Commit uncommitted power net code

This commit is contained in:
modmuss50 2017-05-25 20:35:36 +01:00
parent d474870977
commit b8a2d2d266
No known key found for this signature in database
GPG key ID: 203A5ED4D3E48BEA

View file

@ -19,7 +19,7 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
@Override
public void update() {
if(world.isRemote){
if (world.isRemote) {
return;
}
for (EnumFacing face : EnumFacing.VALUES) {
@ -28,6 +28,16 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
if (tile == null) {
continue;
}
if (!(tile instanceof TileCable) && tile.hasCapability(CapabilityEnergy.ENERGY, face.getOpposite())) {
IEnergyStorage energy = tile.getCapability(CapabilityEnergy.ENERGY, face.getOpposite());
if (energy.canReceive()) {
int move = energy.receiveEnergy(Math.min(getCableType().transferRate, power), false);
if (move != 0) {
power -= move;
}
}
}
if (tile instanceof TileCable) {
TileCable cable = (TileCable) tile;
int averPower = (power + cable.power) / 2;
@ -36,28 +46,19 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
averPower++;
}
power = averPower;
} else if (tile.hasCapability(CapabilityEnergy.ENERGY, face.getOpposite())) {
IEnergyStorage energy = tile.getCapability(CapabilityEnergy.ENERGY, face.getOpposite());
if (energy.canReceive()) {
int move = energy.receiveEnergy(Math.min(getCableType().transferRate, power), false);
if (move != 0) {
power -= move;
}
}
}
}
}
private EnumCableType getCableType(){
private EnumCableType getCableType() {
//Todo cache this
return world.getBlockState(pos).getValue(BlockCable.TYPE);
}
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
if (!canReceive()){
if (!canReceive()) {
return 0;
}
@ -69,7 +70,7 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
@Override
public int extractEnergy(int maxExtract, boolean simulate) {
if (!canExtract()){
if (!canExtract()) {
return 0;
}
@ -101,7 +102,7 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
if(capability == CapabilityEnergy.ENERGY){
if (capability == CapabilityEnergy.ENERGY) {
return true;
}
return super.hasCapability(capability, facing);
@ -109,7 +110,7 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
if(capability == CapabilityEnergy.ENERGY){
if (capability == CapabilityEnergy.ENERGY) {
return (T) this;
}
return super.getCapability(capability, facing);