From dff62a74bf7b81ba884400b10f6262c3f3a13801 Mon Sep 17 00:00:00 2001 From: Rseifert Date: Mon, 25 Mar 2013 13:01:00 -0400 Subject: [PATCH] added code to apply pressure to IPsiRecievers even if the tileEntity is a ITankContainer it will call IPsiReceiver.onRecieve first then if there is anything left of the stack it will call ITankContainer.fill. I still need rework this too work better, and use the path finder but for now it will do. --- src/minecraft/hydraulic/api/IPsiReciever.java | 10 ++-- .../core/liquidNetwork/HydraulicNetwork.java | 53 ++++++++++++++----- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/minecraft/hydraulic/api/IPsiReciever.java b/src/minecraft/hydraulic/api/IPsiReciever.java index d82c07ff4..77e24dc33 100644 --- a/src/minecraft/hydraulic/api/IPsiReciever.java +++ b/src/minecraft/hydraulic/api/IPsiReciever.java @@ -1,6 +1,9 @@ package hydraulic.api; +import java.util.List; + import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.liquids.LiquidStack; /** @@ -11,7 +14,8 @@ import net.minecraftforge.liquids.LiquidStack; public interface IPsiReciever { /** - * Called when this machine receives a fluid at a given pressure + * Called when this machine receives a fluid at a given pressure. Will be called by the network + * before ITankContainer.fill * * @param pressure - input pressure, fill free to pass a reduced # to another network if you can * (100->[*]->40) @@ -24,10 +28,10 @@ public interface IPsiReciever /** * * @param ent - tileEntity trying to connect to this machine - * @param stack - liquid it is most likely going to take or pass. It will pass null if it + * @param stack - liquid(s) it is most likely going to take or pass. It will pass null if it * doesn't care * @return true if it can connect */ - public boolean canConnect(TileEntity ent, LiquidStack stack); + public boolean canConnect(ForgeDirection dir, TileEntity ent, LiquidStack... stacks); } diff --git a/src/minecraft/hydraulic/core/liquidNetwork/HydraulicNetwork.java b/src/minecraft/hydraulic/core/liquidNetwork/HydraulicNetwork.java index 0d01cd626..5fdbbf657 100644 --- a/src/minecraft/hydraulic/core/liquidNetwork/HydraulicNetwork.java +++ b/src/minecraft/hydraulic/core/liquidNetwork/HydraulicNetwork.java @@ -41,7 +41,7 @@ public class HydraulicNetwork * * @return The amount of Liquid used. */ - public int addFluidToNetwork(LiquidStack stack) + public int addFluidToNetwork(LiquidStack stack, double pressure) { int used = 0; if (stack != null && canAcceptLiquid(stack)) @@ -64,10 +64,38 @@ public class HydraulicNetwork for (TileEntity ent : receivers) { + TileEntity[] surroundings = connectionHelper.getSurroundingTileEntities(ent); + + if (ent instanceof IPsiReciever) + { + IPsiReciever machine = (IPsiReciever) ent; + + for (int i = 0; i < 6; i++) + { + if (surroundings[i] instanceof ILiquidNetworkPart && ((ILiquidNetworkPart) surroundings[i]).getNetwork() == this) + { + ForgeDirection dir = ForgeDirection.getOrientation(i).getOpposite(); + if (machine.canConnect(dir, ent, stack)) + { + int lose = machine.onReceiveFluid(pressure, stack); + used += lose; + stack = new LiquidStack(stack.itemID, Math.max(0, stack.amount - lose), stack.itemMeta); + } + } + if (stack == null || stack.amount <= 0) + { + return used; + } + } + if (stack == null || stack.amount <= 0) + { + return used; + } + } if (ent instanceof ITankContainer) { ITankContainer tank = (ITankContainer) ent; - TileEntity[] surroundings = connectionHelper.getSurroundingTileEntities((TileEntity) tank); + for (int i = 0; i < 6; i++) { if (surroundings[i] instanceof ILiquidNetworkPart && ((ILiquidNetworkPart) surroundings[i]).getNetwork() == this) @@ -107,6 +135,10 @@ public class HydraulicNetwork { break; } + if (stack == null || stack.amount <= 0) + { + return used; + } }// End of tank finder if (fillTarget != null) { @@ -131,12 +163,9 @@ public class HydraulicNetwork int flow = 1000; for (ILiquidNetworkPart conductor : this.conductors) { - int cFlow = conductor.getMaxFlowRate(stack, ForgeDirection.UNKNOWN); // TODO change the - // direction to - // actual look - // for connected - // only - // directions + // TODO change the direction to actual look for connected only directions and pipes along + // the path to the target + int cFlow = conductor.getMaxFlowRate(stack, ForgeDirection.UNKNOWN); if (cFlow < flow) { flow = cFlow; @@ -219,20 +248,20 @@ public class HydraulicNetwork } } - public void onPresureCharge() + public void onPresureChange() { this.cleanConductors(); for (int i = 0; i < conductors.size(); i++) { - //TODO change to actual check connected sides only && get true value from settings file + // TODO change to actual check connected sides only && get true value from settings file ILiquidNetworkPart part = conductors.get(i); - if(part.getMaxPressure(ForgeDirection.UNKNOWN) < this.pressure && part.onOverPressure(true)) + if (part.getMaxPressure(ForgeDirection.UNKNOWN) < this.pressure && part.onOverPressure(true)) { this.conductors.remove(part); this.cleanConductors(); } - + } }