worked on pressure updating in the network

this will not be easy as i've forgot some of my hydraulic's class. As
well if the pressure or load changes i have to update the entire network
to the change and recalculate the network's pressure.
This commit is contained in:
Rseifert 2013-03-25 13:49:50 -04:00
parent 15759fb7f1
commit ca9c037fa6
6 changed files with 65 additions and 51 deletions

View file

@ -92,6 +92,16 @@ public enum ColorCode
return validLiquids;
}
public List<LiquidStack> getAllLiquidStacks()
{
List<LiquidStack> validStacks = new ArrayList<LiquidStack>();
for (LiquidData data : getAllLiquidData())
{
validStacks.add(data.getStack());
}
return validStacks;
}
/**
* checks to see if the liquidStack is valid for the given color
*/

View file

@ -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

View file

@ -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);
}

View file

@ -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

View file

@ -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();
}

View file

@ -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)