diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java index 6a4317309..0e654d4ef 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java @@ -122,7 +122,6 @@ public class BlockLaserRelay extends BlockContainerBase{ TileEntity tile = world.getTileEntity(pos); if(tile instanceof TileEntityLaserRelay){ ((TileEntityLaserRelay)tile).saveAllHandlersAround(); - System.out.println("Checked handlers around!"); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java index 6c90ef3ed..66f757f87 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java @@ -84,7 +84,7 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements } if(this.storage.getEnergyStored() > 0){ - WorldUtil.pushEnergyToAllSides(this.worldObj, this.pos, this.storage); + WorldUtil.pushEnergyToAllSides(this); } if(flag != this.currentBurnTime > 0){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java index 57d40e4ad..6c41caf0b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java @@ -61,7 +61,7 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements IEne } if(this.storage.getEnergyStored() > 0){ - WorldUtil.pushEnergyToAllSides(this.worldObj, this.pos, this.storage); + WorldUtil.pushEnergyToAllSides(this); } if(this.lastEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceSolar.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceSolar.java index d594bcd7c..955e0af18 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceSolar.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceSolar.java @@ -74,7 +74,7 @@ public class TileEntityFurnaceSolar extends TileEntityBase implements IEnergyPro } if(this.storage.getEnergyStored() > 0){ - WorldUtil.pushEnergyToAllSides(this.worldObj, this.pos, this.storage); + WorldUtil.pushEnergyToAllSides(this); } if(this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java index d707a0488..10ce2edb9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java @@ -74,7 +74,7 @@ public class TileEntityHeatCollector extends TileEntityBase implements IEnergyPr } if(this.storage.getEnergyStored() > 0){ - WorldUtil.pushEnergy(this.worldObj, this.pos, EnumFacing.UP, this.storage); + WorldUtil.pushEnergyToAllSides(this); } if(this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java index d59a498a5..2bf4cb5ce 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java @@ -86,7 +86,6 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{ else if(!this.hasCheckedHandlersAround){ this.saveAllHandlersAround(); this.hasCheckedHandlersAround = true; - System.out.println("Checked handlers around!"); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java index 2ba10173c..fec15a520 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java @@ -101,7 +101,7 @@ public class TileEntityLeafGenerator extends TileEntityBase implements IEnergyPr } if(this.storage.getEnergyStored() > 0){ - WorldUtil.pushEnergyToAllSides(this.worldObj, this.pos, this.storage); + WorldUtil.pushEnergyToAllSides(this); } if(this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java index 2ae0c4cb6..3a0e4e6fd 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java @@ -100,7 +100,7 @@ public class TileEntityOilGenerator extends TileEntityBase implements IEnergyPro } if(this.storage.getEnergyStored() > 0){ - WorldUtil.pushEnergyToAllSides(this.worldObj, this.pos, this.storage); + WorldUtil.pushEnergyToAllSides(this); } if(flag != this.currentBurnTime > 0){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomEnergyface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomEnergyface.java index 497c466c6..46adf947f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomEnergyface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomEnergyface.java @@ -86,12 +86,7 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement if(!this.worldObj.isRemote){ if(this.isBoundThingInRange() && this.getProvider() != null){ - this.pushEnergy(EnumFacing.UP); - this.pushEnergy(EnumFacing.DOWN); - this.pushEnergy(EnumFacing.NORTH); - this.pushEnergy(EnumFacing.EAST); - this.pushEnergy(EnumFacing.SOUTH); - this.pushEnergy(EnumFacing.WEST); + WorldUtil.pushEnergyToAllSides(this); } } } @@ -101,17 +96,6 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement return super.isBoundThingInRange() && (this.worldObj.getTileEntity(this.boundPosition) instanceof IEnergyReceiver || this.worldObj.getTileEntity(this.boundPosition) instanceof IEnergyProvider); } - private void pushEnergy(EnumFacing side){ - TileEntity tile = WorldUtil.getTileEntityFromSide(side, this.worldObj, this.getPos()); - if(tile != null && tile instanceof IEnergyReceiver && this.getProvider().getEnergyStored(side.getOpposite()) > 0){ - if(((IEnergyReceiver)tile).canConnectEnergy(side.getOpposite()) && this.canConnectEnergy(side)){ - int receive = this.extractEnergy(side, Integer.MAX_VALUE, true); - int actualReceive = ((IEnergyReceiver)tile).receiveEnergy(side.getOpposite(), receive, false); - this.extractEnergy(side, actualReceive, false); - } - } - } - @Override public boolean canConnectEnergy(EnumFacing from){ if(this.isBoundThingInRange()){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java index 9fe929c89..e602a1df8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java @@ -11,6 +11,7 @@ package de.ellpeck.actuallyadditions.mod.util; import cofh.api.energy.EnergyStorage; +import cofh.api.energy.IEnergyProvider; import cofh.api.energy.IEnergyReceiver; import net.minecraft.block.Block; import net.minecraft.block.BlockLiquid; @@ -63,21 +64,28 @@ public class WorldUtil{ return new BlockPos(pos.getX()+side.getFrontOffsetX()*(offset+1), pos.getY()+side.getFrontOffsetY()*(offset+1), pos.getZ()+side.getFrontOffsetZ()*(offset+1)); } - public static void pushEnergyToAllSides(World world, BlockPos pos, EnergyStorage storage){ - pushEnergy(world, pos, EnumFacing.UP, storage); - pushEnergy(world, pos, EnumFacing.DOWN, storage); - pushEnergy(world, pos, EnumFacing.NORTH, storage); - pushEnergy(world, pos, EnumFacing.EAST, storage); - pushEnergy(world, pos, EnumFacing.SOUTH, storage); - pushEnergy(world, pos, EnumFacing.WEST, storage); + public static void pushEnergyToAllSides(TileEntity tileFrom){ + pushEnergy(tileFrom, EnumFacing.UP); + pushEnergy(tileFrom, EnumFacing.DOWN); + pushEnergy(tileFrom, EnumFacing.NORTH); + pushEnergy(tileFrom, EnumFacing.EAST); + pushEnergy(tileFrom, EnumFacing.SOUTH); + pushEnergy(tileFrom, EnumFacing.WEST); } - public static void pushEnergy(World world, BlockPos pos, EnumFacing side, EnergyStorage storage){ - TileEntity tile = getTileEntityFromSide(side, world, pos); - if(tile != null && tile instanceof IEnergyReceiver && storage.getEnergyStored() > 0){ - if(((IEnergyReceiver)tile).canConnectEnergy(side.getOpposite())){ - int receive = ((IEnergyReceiver)tile).receiveEnergy(side.getOpposite(), Math.min(storage.getMaxExtract(), storage.getEnergyStored()), false); - storage.extractEnergy(receive, false); + public static void pushEnergy(TileEntity tileFrom, EnumFacing side){ + TileEntity tileTo = getTileEntityFromSide(side, tileFrom.getWorld(), tileFrom.getPos()); + if(tileTo != null){ + if(tileFrom instanceof IEnergyProvider && tileTo instanceof IEnergyReceiver){ + IEnergyReceiver handlerTo = (IEnergyReceiver)tileTo; + IEnergyProvider handlerFrom = (IEnergyProvider)tileFrom; + int drain = handlerFrom.extractEnergy(side, Integer.MAX_VALUE, true); + if(drain > 0){ + if(handlerTo.canConnectEnergy(side.getOpposite())){ + int filled = handlerTo.receiveEnergy(side.getOpposite(), drain, false); + handlerFrom.extractEnergy(side, filled, false); + } + } } } }