Make Laser Relays ignore full containers

This commit is contained in:
Ellpeck 2016-12-22 21:08:02 +01:00
parent 1846d52e50
commit ad1768302f
2 changed files with 44 additions and 12 deletions

View file

@ -123,16 +123,32 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
TileEntity relayTile = this.worldObj.getTileEntity(relay); TileEntity relayTile = this.worldObj.getTileEntity(relay);
if(relayTile instanceof TileEntityLaserRelayEnergy){ if(relayTile instanceof TileEntityLaserRelayEnergy){
TileEntityLaserRelayEnergy theRelay = (TileEntityLaserRelayEnergy)relayTile; TileEntityLaserRelayEnergy theRelay = (TileEntityLaserRelayEnergy)relayTile;
boolean workedOnce = false;
int amount = theRelay.receiversAround.size(); for(EnumFacing facing : theRelay.receiversAround.keySet()){
if(theRelay == this && theRelay.receiversAround.containsKey(from)){ if(theRelay != this || facing != from){
//So that the tile energy was gotten from isn't factored into the amount TileEntity tile = theRelay.receiversAround.get(facing);
amount--;
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); relaysThatWork.add(theRelay);
totalReceiverAmount += amount;
} }
} }
} }

View file

@ -117,16 +117,32 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay implements
TileEntity relayTile = this.worldObj.getTileEntity(relay); TileEntity relayTile = this.worldObj.getTileEntity(relay);
if(relayTile instanceof TileEntityLaserRelayFluids){ if(relayTile instanceof TileEntityLaserRelayFluids){
TileEntityLaserRelayFluids theRelay = (TileEntityLaserRelayFluids)relayTile; TileEntityLaserRelayFluids theRelay = (TileEntityLaserRelayFluids)relayTile;
boolean workedOnce = false;
int amount = theRelay.receiversAround.size(); for(EnumFacing facing : theRelay.receiversAround.keySet()){
if(theRelay == this && theRelay.receiversAround.containsKey(from)){ if(theRelay != this || facing != from){
//So that the tile energy was gotten from isn't factored into the amount TileEntity tile = theRelay.receiversAround.get(facing);
amount--;
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); relaysThatWork.add(theRelay);
totalReceiverAmount += amount;
} }
} }
} }