From 29b59d88e00497267993426751de17013a2615b4 Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Wed, 15 Jan 2014 08:08:24 -0500 Subject: [PATCH] Fixed tank network and improved fluid network --- .../fluid/network/FluidNetwork.java | 17 ++++++----- .../mechanical/fluid/pipe/PipeNetwork.java | 12 ++++++-- .../mechanical/fluid/pipe/TilePipe.java | 4 +-- .../fluid/prefab/TileFluidNetwork.java | 6 ++-- .../mechanical/fluid/tank/TankNetwork.java | 30 +++++++++---------- 5 files changed, 38 insertions(+), 31 deletions(-) diff --git a/src/main/java/resonantinduction/mechanical/fluid/network/FluidNetwork.java b/src/main/java/resonantinduction/mechanical/fluid/network/FluidNetwork.java index c4ff6ca56..bf693fe5d 100644 --- a/src/main/java/resonantinduction/mechanical/fluid/network/FluidNetwork.java +++ b/src/main/java/resonantinduction/mechanical/fluid/network/FluidNetwork.java @@ -1,5 +1,7 @@ package resonantinduction.mechanical.fluid.network; +import java.util.Set; + import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; @@ -147,20 +149,19 @@ public class FluidNetwork extends Network tankList) + { + int parts = tankList.size(); + for (IFluidPart part : tankList) { - stack = stack.copy(); - } - int parts = this.getConnectors().size(); - for (IFluidPart part : this.getConnectors()) - { - part.getInternalTank().setFluid(null); if (stack != null) { int fillPer = stack.amount / parts; - part.getInternalTank().fill(FluidUtility.getStack(stack, fillPer), true); + stack.amount -= part.getInternalTank().fill(FluidUtility.getStack(stack, fillPer), true); part.onFluidChanged(); if (parts > 1) parts--; diff --git a/src/main/java/resonantinduction/mechanical/fluid/pipe/PipeNetwork.java b/src/main/java/resonantinduction/mechanical/fluid/pipe/PipeNetwork.java index 495f54327..95aa504e1 100644 --- a/src/main/java/resonantinduction/mechanical/fluid/pipe/PipeNetwork.java +++ b/src/main/java/resonantinduction/mechanical/fluid/pipe/PipeNetwork.java @@ -12,6 +12,7 @@ import resonantinduction.api.fluid.IFluidPart; import resonantinduction.api.fluid.IFluidPipe; import resonantinduction.mechanical.fluid.network.FluidNetwork; import universalelectricity.api.vector.Vector3; +import universalelectricity.core.net.NetworkTickHandler; import calclavia.lib.utility.FluidUtility; /** @author DarkGuardsman */ @@ -19,6 +20,11 @@ public class PipeNetwork extends FluidNetwork { public HashMap> connectionMap = new HashMap>(); + public PipeNetwork() + { + NetworkTickHandler.addNetwork(this); + } + @Override public void update() { @@ -64,13 +70,13 @@ public class PipeNetwork extends FluidNetwork @Override public boolean canUpdate() { - return super.canUpdate() || this.getTank().getFluid() != null; + return true; } @Override public boolean continueUpdate() { - return super.canUpdate() || this.getTank().getFluid() != null; + return true; } @Override @@ -86,7 +92,7 @@ public class PipeNetwork extends FluidNetwork super.buildPart(part); for (int i = 0; i < 6; i++) { - if (part.getConnections()[i] instanceof IFluidHandler) + if (part.getConnections()[i] instanceof IFluidHandler && !(part.getConnections()[i] instanceof IFluidPipe)) { EnumSet set = this.connectionMap.get(part.getConnections()[i]); if (set == null) diff --git a/src/main/java/resonantinduction/mechanical/fluid/pipe/TilePipe.java b/src/main/java/resonantinduction/mechanical/fluid/pipe/TilePipe.java index e15cb8f3c..c2f2388f2 100644 --- a/src/main/java/resonantinduction/mechanical/fluid/pipe/TilePipe.java +++ b/src/main/java/resonantinduction/mechanical/fluid/pipe/TilePipe.java @@ -111,11 +111,11 @@ public class TilePipe extends TileFluidNetwork implements IColorCoded, IFluidPip } @Override - public void sendTankUpdate(int index) + public void sendTankUpdate() { if (this.getBlockMetadata() == FluidContainerMaterial.WOOD.ordinal() || this.getBlockMetadata() == FluidContainerMaterial.STONE.ordinal()) { - super.sendTankUpdate(index); + super.sendTankUpdate(); } } diff --git a/src/main/java/resonantinduction/mechanical/fluid/prefab/TileFluidNetwork.java b/src/main/java/resonantinduction/mechanical/fluid/prefab/TileFluidNetwork.java index 009a52408..ffac2e0c7 100644 --- a/src/main/java/resonantinduction/mechanical/fluid/prefab/TileFluidNetwork.java +++ b/src/main/java/resonantinduction/mechanical/fluid/prefab/TileFluidNetwork.java @@ -69,7 +69,7 @@ public class TileFluidNetwork extends TileEntityFluidDevice implements IFluidPar { if (!FluidUtility.matchExact(prevStack, this.getInternalTank().getFluid())) { - this.sendTankUpdate(0); + this.sendTankUpdate(); } this.prevStack = this.tank.getFluid(); @@ -298,9 +298,9 @@ public class TileFluidNetwork extends TileEntityFluidDevice implements IFluidPar PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_RENDER, this, this.colorID, this.renderSides)); } - public void sendTankUpdate(int index) + public void sendTankUpdate() { - if (this.getInternalTank() != null && index == 0) + if (this.getInternalTank() != null) { PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_TANK, this, this.getInternalTank().getCapacity(), this.getInternalTank().writeToNBT(new NBTTagCompound())), this.worldObj, new Vector3(this), 60); } diff --git a/src/main/java/resonantinduction/mechanical/fluid/tank/TankNetwork.java b/src/main/java/resonantinduction/mechanical/fluid/tank/TankNetwork.java index fd1edd823..29530cd33 100644 --- a/src/main/java/resonantinduction/mechanical/fluid/tank/TankNetwork.java +++ b/src/main/java/resonantinduction/mechanical/fluid/tank/TankNetwork.java @@ -1,12 +1,13 @@ package resonantinduction.mechanical.fluid.tank; -import java.util.ArrayList; -import java.util.List; +import java.util.LinkedHashSet; +import java.util.Set; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.fluids.FluidStack; import resonantinduction.api.fluid.IFluidPart; import resonantinduction.mechanical.fluid.network.FluidNetwork; +import universalelectricity.core.net.NetworkTickHandler; import calclavia.lib.utility.FluidUtility; /** Network that handles connected tanks @@ -14,18 +15,24 @@ import calclavia.lib.utility.FluidUtility; * @author DarkGuardsman */ public class TankNetwork extends FluidNetwork { + public TankNetwork() + { + NetworkTickHandler.addNetwork(this); + } @Override public void reloadTanks() { + System.out.println("TankNetwork: Balancing fluid"); FluidStack fillStack = this.getTank().getFluid(); int lowestY = 255, highestY = 0; if (fillStack == null || fillStack.getFluid().isGaseous()) { + System.out.println("TankNetwork: Stack is null or a gas"); super.reloadTanks(); } - else if (this.getNodes().size() > 0) + else if (this.getConnectors().size() > 0) { fillStack = fillStack.copy(); for (IFluidPart part : this.getConnectors()) @@ -43,9 +50,9 @@ public class TankNetwork extends FluidNetwork //TODO Add path finder to prevent filling when tanks are only connected at the top for (int y = lowestY; y <= highestY; y++) - { - List parts = new ArrayList(); - + { + Set parts = new LinkedHashSet(); + for (IFluidPart part : this.getConnectors()) { if (part instanceof IFluidPart && ((TileEntity) part).yCoord == y) @@ -55,15 +62,8 @@ public class TankNetwork extends FluidNetwork } if (!parts.isEmpty()) { - //TODO change this to use a percent system for even filling - int partCount = parts.size(); - for (IFluidPart part : parts) - { - fillStack.amount -= part.getInternalTank().fill(FluidUtility.getStack(fillStack, fillStack.amount / partCount), true); - part.onFluidChanged(); - if (partCount > 1) - partCount--; - } + System.out.println("TankNetwork: balancing level: " + y); + this.fillTankSet(fillStack, parts); } if (fillStack == null || fillStack.amount <= 0)