diff --git a/src/minecraft/hydraulic/api/ColorCode.java b/src/minecraft/hydraulic/api/ColorCode.java index 5ce77adfa..3f70f66cb 100644 --- a/src/minecraft/hydraulic/api/ColorCode.java +++ b/src/minecraft/hydraulic/api/ColorCode.java @@ -91,6 +91,16 @@ public enum ColorCode } return validLiquids; } + + public List getAllLiquidStacks() + { + List validStacks = new ArrayList(); + for (LiquidData data : getAllLiquidData()) + { + validStacks.add(data.getStack()); + } + return validStacks; + } /** * checks to see if the liquidStack is valid for the given color diff --git a/src/minecraft/hydraulic/api/ILiquidNetworkPart.java b/src/minecraft/hydraulic/api/ILiquidNetworkPart.java index 18cfe4cbf..baa41c587 100644 --- a/src/minecraft/hydraulic/api/ILiquidNetworkPart.java +++ b/src/minecraft/hydraulic/api/ILiquidNetworkPart.java @@ -10,7 +10,7 @@ import net.minecraftforge.liquids.LiquidStack; * that doesn't change the over all network pressure. So pipes, gauges, tubes, buffers, decor * blocks. */ -public interface ILiquidNetworkPart +public interface ILiquidNetworkPart extends IPipeConnector { /** * gets the devices pressure from a given side for input diff --git a/src/minecraft/hydraulic/api/IPipeConnector.java b/src/minecraft/hydraulic/api/IPipeConnector.java new file mode 100644 index 000000000..d93edfaa8 --- /dev/null +++ b/src/minecraft/hydraulic/api/IPipeConnector.java @@ -0,0 +1,17 @@ +package hydraulic.api; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.liquids.LiquidStack; + +public interface IPipeConnector +{ + /** + * + * @param ent - tileEntity trying to connect to this machine + * @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(ForgeDirection dir, LiquidStack... stacks); +} diff --git a/src/minecraft/hydraulic/api/IPsiCreator.java b/src/minecraft/hydraulic/api/IPsiCreator.java index 79d329eea..c2edc7b0f 100644 --- a/src/minecraft/hydraulic/api/IPsiCreator.java +++ b/src/minecraft/hydraulic/api/IPsiCreator.java @@ -3,7 +3,7 @@ package hydraulic.api; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.liquids.LiquidStack; -public interface IPsiCreator +public interface IPsiCreator extends IPipeConnector { /** * gets the PressureOutput of a device diff --git a/src/minecraft/hydraulic/api/IPsiReciever.java b/src/minecraft/hydraulic/api/IPsiReciever.java index 77e24dc33..cd67ad30e 100644 --- a/src/minecraft/hydraulic/api/IPsiReciever.java +++ b/src/minecraft/hydraulic/api/IPsiReciever.java @@ -11,27 +11,11 @@ import net.minecraftforge.liquids.LiquidStack; * net.minecraftforge.liquids too make your machine work with other fluid mods that don't use * pressure */ -public interface IPsiReciever +public interface IPsiReciever extends IPipeConnector { /** - * 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) - * @param stack - fluid received in this event. Try to pass this too another network to simulate - * flow rate - * @return - how much of the stack was used or passed on. + * the load that this machine is handling, working, or moving */ - public int onReceiveFluid(double pressure, LiquidStack stack); - - /** - * - * @param ent - tileEntity trying to connect to this machine - * @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(ForgeDirection dir, TileEntity ent, LiquidStack... stacks); + public double getPressureLoad(); } diff --git a/src/minecraft/hydraulic/core/liquidNetwork/HydraulicNetwork.java b/src/minecraft/hydraulic/core/liquidNetwork/HydraulicNetwork.java index b7771222e..4821f82a7 100644 --- a/src/minecraft/hydraulic/core/liquidNetwork/HydraulicNetwork.java +++ b/src/minecraft/hydraulic/core/liquidNetwork/HydraulicNetwork.java @@ -1,6 +1,7 @@ package hydraulic.core.liquidNetwork; import hydraulic.api.ColorCode; +import hydraulic.api.IPipeConnector; import hydraulic.api.IPsiCreator; import hydraulic.api.ILiquidNetworkPart; import hydraulic.api.IPsiReciever; @@ -18,8 +19,8 @@ import net.minecraftforge.liquids.ITankContainer; import net.minecraftforge.liquids.LiquidStack; /** - * Side note: the network should act like this when done - * {@link http://www.e4training.com/hydraulic_calculators/B1.htm} as well as stay compatible with the forge + * Side note: the network should act like this when done {@link http + * ://www.e4training.com/hydraulic_calculators/B1.htm} as well as stay compatible with the forge * Liquids * * @author Rseifert @@ -45,9 +46,36 @@ public class HydraulicNetwork this.color = color; } + /** + * updates the pressure in the network + * + * @param ent + */ + public void updatePressure() + { + this.pressureLoad = 0; + this.pressureProduced = 0; + for (TileEntity ent : receivers) + { + if (ent instanceof IPipeConnector && ((IPipeConnector) ent).canConnect(ForgeDirection.UNKNOWN, (LiquidStack[]) this.color.getAllLiquidStacks().toArray())) + { + if (ent instanceof IPsiReciever) + { + pressureLoad += ((IPsiReciever) ent).getPressureLoad(); + } + else if (ent instanceof IPsiCreator) + { + pressureProduced += ((IPsiCreator) ent).getPressureOut(color.getLiquidData().getStack(), ForgeDirection.UNKNOWN); + } + } + } + } + /** * Tries to add the liquid stack to the network's valid machines. Same as the fill method for - * ITankContainer in that it will fill machines, however it also includes pressure + * ITankContainer in that it will fill machines, however it also includes pressure if the + * machine also adds pressure to the network. Called mostly by pipes as they are filled from + * other mod sources * * @return The amount of Liquid used. */ @@ -76,32 +104,6 @@ public class HydraulicNetwork { 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; @@ -173,7 +175,8 @@ public class HydraulicNetwork int flow = 1000; for (ILiquidNetworkPart conductor : this.conductors) { - // TODO change the direction to actual look for connected only directions and pipes along + // 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)