Commit uncommitted power net code
This commit is contained in:
parent
d474870977
commit
b8a2d2d266
1 changed files with 16 additions and 15 deletions
|
@ -19,7 +19,7 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
if(world.isRemote){
|
if (world.isRemote) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (EnumFacing face : EnumFacing.VALUES) {
|
for (EnumFacing face : EnumFacing.VALUES) {
|
||||||
|
@ -28,6 +28,16 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
|
||||||
if (tile == null) {
|
if (tile == null) {
|
||||||
continue;
|
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) {
|
if (tile instanceof TileCable) {
|
||||||
TileCable cable = (TileCable) tile;
|
TileCable cable = (TileCable) tile;
|
||||||
int averPower = (power + cable.power) / 2;
|
int averPower = (power + cable.power) / 2;
|
||||||
|
@ -36,28 +46,19 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
|
||||||
averPower++;
|
averPower++;
|
||||||
}
|
}
|
||||||
power = 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
|
//Todo cache this
|
||||||
return world.getBlockState(pos).getValue(BlockCable.TYPE);
|
return world.getBlockState(pos).getValue(BlockCable.TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int receiveEnergy(int maxReceive, boolean simulate) {
|
public int receiveEnergy(int maxReceive, boolean simulate) {
|
||||||
if (!canReceive()){
|
if (!canReceive()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +70,7 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int extractEnergy(int maxExtract, boolean simulate) {
|
public int extractEnergy(int maxExtract, boolean simulate) {
|
||||||
if (!canExtract()){
|
if (!canExtract()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +102,7 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||||
if(capability == CapabilityEnergy.ENERGY){
|
if (capability == CapabilityEnergy.ENERGY) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.hasCapability(capability, facing);
|
return super.hasCapability(capability, facing);
|
||||||
|
@ -109,7 +110,7 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||||
if(capability == CapabilityEnergy.ENERGY){
|
if (capability == CapabilityEnergy.ENERGY) {
|
||||||
return (T) this;
|
return (T) this;
|
||||||
}
|
}
|
||||||
return super.getCapability(capability, facing);
|
return super.getCapability(capability, facing);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue