From 5823ad2c8565df560b4d41d2607a1bc57f8f032a Mon Sep 17 00:00:00 2001 From: Rseifert Date: Mon, 25 Mar 2013 12:33:32 -0400 Subject: [PATCH] reworked the network code added comments and change comments in several places added can connect method to psi receiver and change the receiver method to get a liquid stack so it can pass that stack to the next network. changed onOverCharge to onPressureChange that will check each time the pressure network increases if one of the parts will bust. --- .../hydraulic/api/ILiquidNetworkPart.java | 15 ++++++---- src/minecraft/hydraulic/api/IPsiReciever.java | 30 +++++++++++++++---- .../core/liquidNetwork/HydraulicNetwork.java | 26 +++++++++++++--- 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/minecraft/hydraulic/api/ILiquidNetworkPart.java b/src/minecraft/hydraulic/api/ILiquidNetworkPart.java index a0bfc37f..18cfe4cb 100644 --- a/src/minecraft/hydraulic/api/ILiquidNetworkPart.java +++ b/src/minecraft/hydraulic/api/ILiquidNetworkPart.java @@ -7,6 +7,8 @@ import net.minecraftforge.liquids.LiquidStack; /** * A machine that acts as one with the liquid network using the networks pressure for some function + * that doesn't change the over all network pressure. So pipes, gauges, tubes, buffers, decor + * blocks. */ public interface ILiquidNetworkPart { @@ -14,11 +16,12 @@ public interface ILiquidNetworkPart * gets the devices pressure from a given side for input */ public double getMaxPressure(ForgeDirection side); - + /** * The Fluid network that this machine is part of */ public HydraulicNetwork getNetwork(); + /** * sets the machines network */ @@ -34,13 +37,15 @@ public interface ILiquidNetworkPart /** * The max amount of liquid that can flow per request */ - public int getMaxFlowRate(LiquidStack stack); - + public int getMaxFlowRate(LiquidStack stack, ForgeDirection side); /** - * Called when the pressure on the pipe passes max + * Called when the pressure on the machine reachs max + * + * @param damageAllowed - can this tileEntity cause grief damage + * @return true if the device over pressured and destroyed itself */ - public void onOverPressure(); + public boolean onOverPressure(Boolean damageAllowed); /** * Resets the pipe and recalculate connection IDs again diff --git a/src/minecraft/hydraulic/api/IPsiReciever.java b/src/minecraft/hydraulic/api/IPsiReciever.java index 909d351b..d82c07ff 100644 --- a/src/minecraft/hydraulic/api/IPsiReciever.java +++ b/src/minecraft/hydraulic/api/IPsiReciever.java @@ -1,13 +1,33 @@ package hydraulic.api; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.liquids.LiquidStack; + +/** + * A tileEntity that receives a pressure driven fluid. Suggested to use some of the class from + * net.minecraftforge.liquids too make your machine work with other fluid mods that don't use + * pressure + */ public interface IPsiReciever { /** - * Called when this machine receives pressure/Fluid Too get force take pressure x Surface area - * of you machine + * Called when this machine receives a fluid at a given pressure * - * @param pressure - input pressure. make sure to output a pressure later on, plus remaining - * liquid + * @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. */ - public void onReceivePressure(double pressure); + public int onReceiveFluid(double pressure, LiquidStack stack); + + /** + * + * @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 + * doesn't care + * @return true if it can connect + */ + public boolean canConnect(TileEntity ent, LiquidStack stack); + } diff --git a/src/minecraft/hydraulic/core/liquidNetwork/HydraulicNetwork.java b/src/minecraft/hydraulic/core/liquidNetwork/HydraulicNetwork.java index 4d16ffae..0d01cd62 100644 --- a/src/minecraft/hydraulic/core/liquidNetwork/HydraulicNetwork.java +++ b/src/minecraft/hydraulic/core/liquidNetwork/HydraulicNetwork.java @@ -3,11 +3,14 @@ package hydraulic.core.liquidNetwork; import hydraulic.api.ColorCode; import hydraulic.api.IPsiCreator; import hydraulic.api.ILiquidNetworkPart; +import hydraulic.api.IPsiReciever; import hydraulic.helpers.connectionHelper; import java.util.ArrayList; import java.util.List; +import universalelectricity.prefab.network.IPacketReceiver; + import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.liquids.ILiquidTank; @@ -23,6 +26,8 @@ public class HydraulicNetwork public final List receivers = new ArrayList(); public ColorCode color = ColorCode.NONE; + /* PRESSURE OF THE NETWORK AS A TOTAL. ZERO AS IN DEFUALT */ + public double pressure = 0; public HydraulicNetwork(ILiquidNetworkPart conductor, ColorCode color) { @@ -126,7 +131,12 @@ public class HydraulicNetwork int flow = 1000; for (ILiquidNetworkPart conductor : this.conductors) { - int cFlow = conductor.getMaxFlowRate(stack); + int cFlow = conductor.getMaxFlowRate(stack, ForgeDirection.UNKNOWN); // TODO change the + // direction to + // actual look + // for connected + // only + // directions if (cFlow < flow) { flow = cFlow; @@ -153,12 +163,13 @@ public class HydraulicNetwork receivers.remove(ent); } } + /** * Adds a tileEntity to the list if its valid */ public void addEntity(TileEntity ent) { - if(!receivers.contains(ent) && (ent instanceof ITankContainer || ent instanceof ILiquidNetworkPart || ent instanceof IPsiCreator)) + if (!receivers.contains(ent) && (ent instanceof ITankContainer || ent instanceof IPsiReciever || ent instanceof IPsiCreator)) { receivers.add(ent); } @@ -208,13 +219,20 @@ public class HydraulicNetwork } } - public void onOverCharge() + public void onPresureCharge() { this.cleanConductors(); for (int i = 0; i < conductors.size(); i++) { - conductors.get(i).onOverPressure(); + //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)) + { + this.conductors.remove(part); + this.cleanConductors(); + } + } }