From ad1768302f9ea282226e5b29fb06ec39c19fc3bc Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 22 Dec 2016 21:08:02 +0100 Subject: [PATCH] Make Laser Relays ignore full containers --- .../mod/tile/TileEntityLaserRelayEnergy.java | 28 +++++++++++++++---- .../mod/tile/TileEntityLaserRelayFluids.java | 28 +++++++++++++++---- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java index 35c1b99e9..b427658cb 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java @@ -123,16 +123,32 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements TileEntity relayTile = this.worldObj.getTileEntity(relay); if(relayTile instanceof TileEntityLaserRelayEnergy){ TileEntityLaserRelayEnergy theRelay = (TileEntityLaserRelayEnergy)relayTile; + boolean workedOnce = false; - int amount = theRelay.receiversAround.size(); - if(theRelay == this && theRelay.receiversAround.containsKey(from)){ - //So that the tile energy was gotten from isn't factored into the amount - amount--; + for(EnumFacing facing : theRelay.receiversAround.keySet()){ + if(theRelay != this || facing != from){ + TileEntity tile = theRelay.receiversAround.get(facing); + + EnumFacing opp = facing.getOpposite(); + if(tile instanceof IEnergyReceiver){ + IEnergyReceiver iReceiver = (IEnergyReceiver)tile; + if(iReceiver.canConnectEnergy(opp) && iReceiver.receiveEnergy(opp, Integer.MAX_VALUE, true) > 0){ + totalReceiverAmount++; + workedOnce = true; + } + } + else if(ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, opp)){ + ITeslaConsumer cap = tile.getCapability(TeslaUtil.teslaConsumer, opp); + if(cap != null && cap.givePower(maxTransfer, true) > 0){ + totalReceiverAmount++; + workedOnce = true; + } + } + } } - if(amount > 0){ + if(workedOnce){ relaysThatWork.add(theRelay); - totalReceiverAmount += amount; } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java index 3c8079189..f32c3c64c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java @@ -117,16 +117,32 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay implements TileEntity relayTile = this.worldObj.getTileEntity(relay); if(relayTile instanceof TileEntityLaserRelayFluids){ TileEntityLaserRelayFluids theRelay = (TileEntityLaserRelayFluids)relayTile; + boolean workedOnce = false; - int amount = theRelay.receiversAround.size(); - if(theRelay == this && theRelay.receiversAround.containsKey(from)){ - //So that the tile energy was gotten from isn't factored into the amount - amount--; + for(EnumFacing facing : theRelay.receiversAround.keySet()){ + if(theRelay != this || facing != from){ + TileEntity tile = theRelay.receiversAround.get(facing); + + EnumFacing opp = facing.getOpposite(); + if(tile instanceof net.minecraftforge.fluids.IFluidHandler){ + net.minecraftforge.fluids.IFluidHandler iHandler = (net.minecraftforge.fluids.IFluidHandler)tile; + if(iHandler.canFill(opp, stack.getFluid()) && iHandler.fill(opp, stack, false) > 0){ + totalReceiverAmount++; + workedOnce = true; + } + } + else if(tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, opp)){ + IFluidHandler cap = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, opp); + if(cap != null && cap.fill(stack, false) > 0){ + totalReceiverAmount++; + workedOnce = true; + } + } + } } - if(amount > 0){ + if(workedOnce){ relaysThatWork.add(theRelay); - totalReceiverAmount += amount; } } }