From 09484b5ee27e309411c9f1c71f5310a330b7eef2 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 6 Dec 2013 15:22:44 -0500 Subject: [PATCH] Partly fixed pipes --- .../tilenetwork/fluid/NetworkFluidTiles.java | 36 ++++++---- .../tilenetwork/fluid/NetworkPipes.java | 72 +++++-------------- .../fluid/common/pipes/TileEntityPipe.java | 1 + .../prefab/TileEntityFluidNetworkTile.java | 5 +- .../pump/TileEntityConstructionPump.java | 13 ++-- .../common/pump/TileEntityStarterPump.java | 7 +- 6 files changed, 51 insertions(+), 83 deletions(-) diff --git a/src/dark/core/prefab/tilenetwork/fluid/NetworkFluidTiles.java b/src/dark/core/prefab/tilenetwork/fluid/NetworkFluidTiles.java index aeb986cbb..a106b8843 100644 --- a/src/dark/core/prefab/tilenetwork/fluid/NetworkFluidTiles.java +++ b/src/dark/core/prefab/tilenetwork/fluid/NetworkFluidTiles.java @@ -1,11 +1,14 @@ package dark.core.prefab.tilenetwork.fluid; +import java.util.EnumSet; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; @@ -21,7 +24,7 @@ import dark.core.prefab.tilenetwork.NetworkUpdateHandler; public class NetworkFluidTiles extends NetworkTileEntities { /** Fluid Tanks that are connected to the network but not part of the network's main body */ - public final Set connectedTanks = new HashSet(); + public HashMap> connctedFluidHandlers = new HashMap>(); /** Collective storage tank of all fluid tile that make up this networks main body */ protected FluidTank sharedTank; protected FluidTankInfo sharedTankInfo; @@ -186,24 +189,29 @@ public class NetworkFluidTiles extends NetworkTileEntities @Override public boolean removeTile(TileEntity ent) { - return super.removeTile(ent) || this.connectedTanks.remove(ent); - } - - @Override - public boolean addTile(TileEntity ent, boolean member) - { - if (!(super.addTile(ent, member)) && ent instanceof IFluidHandler && !connectedTanks.contains(ent)) - { - connectedTanks.add((IFluidHandler) ent); - return true; - } - return false; + return super.removeTile(ent) || this.connctedFluidHandlers.remove(ent) != null; } /** Checks too see if the tileEntity is part of or connected too the network */ public boolean isConnected(TileEntity tileEntity) { - return this.connectedTanks.contains(tileEntity); + return this.connctedFluidHandlers.containsKey(tileEntity); + } + + public void addTank(ForgeDirection side, IFluidHandler tank) + { + if (this.connctedFluidHandlers.containsKey(tank)) + { + EnumSet d = this.connctedFluidHandlers.get(tank); + d.add(side); + this.connctedFluidHandlers.put(tank, d); + } + else + { + EnumSet d = EnumSet.noneOf(ForgeDirection.class); + d.add(side); + this.connctedFluidHandlers.put(tank, d); + } } @Override diff --git a/src/dark/core/prefab/tilenetwork/fluid/NetworkPipes.java b/src/dark/core/prefab/tilenetwork/fluid/NetworkPipes.java index 2f5b5fd32..0a74814f1 100644 --- a/src/dark/core/prefab/tilenetwork/fluid/NetworkPipes.java +++ b/src/dark/core/prefab/tilenetwork/fluid/NetworkPipes.java @@ -1,5 +1,8 @@ package dark.core.prefab.tilenetwork.fluid; +import java.util.EnumSet; +import java.util.Map.Entry; + import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.fluids.FluidStack; @@ -57,76 +60,38 @@ public class NetworkPipes extends NetworkFluidTiles public int addFluidToNetwork(TileEntity source, FluidStack sta, boolean doFill, boolean allowStore) { int used = 0; - FluidStack prevCombined = this.getNetworkTank().getFluid(); FluidStack stack = sta.copy(); if (!this.processingRequest && stack != null) { this.processingRequest = true; - - if (this.getNetworkTank().getFluid() != null && !stack.isFluidEqual(this.getNetworkTank().getFluid())) - { - //this.causingMixing(null, this.combinedStorage().getFluid(), stack); - } if (stack.amount > this.getMaxFlow(stack)) { stack = FluidHelper.getStack(stack, this.getMaxFlow(stack)); } - /* Main fill target to try to fill with the stack */ - IFluidHandler primaryFill = null; - int volume = Integer.MAX_VALUE; - ForgeDirection fillDir = ForgeDirection.UNKNOWN; - /* Secondary fill target if the main target is not found */ - IFluidHandler secondayFill = null; + IFluidHandler tankToFill = null; int mostFill = 0; - ForgeDirection otherFillDir = ForgeDirection.UNKNOWN; + ForgeDirection fillDir = ForgeDirection.UNKNOWN; boolean found = false; /* FIND THE FILL TARGET FROM THE LIST OF FLUID RECIEVERS */ - for (IFluidHandler tankContainer : connectedTanks) + for (Entry> entry : this.connctedFluidHandlers.entrySet()) { + IFluidHandler tankContainer = entry.getKey(); if (tankContainer instanceof TileEntity && tankContainer != source && !(tankContainer instanceof INetworkPipe)) { - TileEntity[] connectedTiles = ConnectionHelper.getSurroundingTileEntities((TileEntity) tankContainer); - - for (int i = 0; i < 6; i++) + for (ForgeDirection dir : entry.getValue()) { - if (connectedTiles[i] instanceof INetworkPipe && ((INetworkPipe) connectedTiles[i]).getTileNetwork() == this) - { - ForgeDirection dir = ForgeDirection.getOrientation(i).getOpposite(); - FluidTankInfo[] targetTank = tankContainer.getTankInfo(dir); - int fill = tankContainer.fill(dir, stack, false); + int fill = tankContainer.fill(dir, stack, false); - /* USE GET TANK FROM SIDE METHOD FIRST */ - if (targetTank != null) - { - for (int t = 0; t < targetTank.length; t++) - { - FluidStack stackStored = targetTank[t].fluid; - int tankCap = targetTank[t].capacity; - if (stackStored == null) - { - primaryFill = tankContainer; - found = true; - fillDir = dir; - break; - } - else if (stackStored.isFluidEqual(sta) && stackStored.amount < tankCap && stackStored.amount < volume) - { - primaryFill = tankContainer; - volume = stackStored.amount; - } - } - }/* USE FILL METHOD IF GET TANK == NULL */ - else if (fill > 0 && fill > mostFill) - { - secondayFill = tankContainer; - mostFill = fill; - otherFillDir = dir; - } + if (fill > 0 && fill > mostFill) + { + tankToFill = tankContainer; + mostFill = fill; + fillDir = dir; } } } @@ -137,14 +102,9 @@ public class NetworkPipes extends NetworkFluidTiles }// End of tank finder boolean filledMain = false; - if (primaryFill != null) + if (tankToFill != null) { - used = primaryFill.fill(fillDir, stack, doFill); - // System.out.println("Primary Target " + used + doFill); - } - else if (secondayFill != null) - { - used = secondayFill.fill(fillDir, stack, doFill); + used = tankToFill.fill(fillDir, stack, doFill); // System.out.println("Seconday Target " + used + doFill); } else if (allowStore) diff --git a/src/dark/fluid/common/pipes/TileEntityPipe.java b/src/dark/fluid/common/pipes/TileEntityPipe.java index d9d803704..fbed4924e 100644 --- a/src/dark/fluid/common/pipes/TileEntityPipe.java +++ b/src/dark/fluid/common/pipes/TileEntityPipe.java @@ -75,6 +75,7 @@ public class TileEntityPipe extends TileEntityFluidNetworkTile implements IColor { connectedBlocks.add(tileEntity); this.renderConnection[side.ordinal()] = true; + this.getTileNetwork().addTank(side.getOpposite(), (IFluidHandler) tileEntity); } else if (tileEntity instanceof ITileConnector && ((ITileConnector) tileEntity).canTileConnect(Connection.FLUIDS, side.getOpposite())) { diff --git a/src/dark/fluid/common/prefab/TileEntityFluidNetworkTile.java b/src/dark/fluid/common/prefab/TileEntityFluidNetworkTile.java index 1a27820d9..b19f3bea8 100644 --- a/src/dark/fluid/common/prefab/TileEntityFluidNetworkTile.java +++ b/src/dark/fluid/common/prefab/TileEntityFluidNetworkTile.java @@ -299,12 +299,13 @@ public abstract class TileEntityFluidNetworkTile extends TileEntityFluidDevice i { if (fluid.getFluid().isGaseous(fluid) && !mat.canSupportGas) { - //TODO lose 25% of the gas, and render the lost + //TODO lose 25% of the gas, and render the escaping gas as a particle effect + this.getTileNetwork().drainNetworkTank(this.worldObj, (int) (fluid.amount * .25), true); } else if (FluidMasterList.isMolten(fluid.getFluid()) && !mat.canSupportMoltenFluids) { //TODO start to heat up the pipe to melting point. When it hits melting point turn the pipe to its molten metal equal - //TODO also once it reaches a set heat level start burning up blocks around the pipe. Eg wood + //TODO also once it reaches a set heat level start burning up blocks around the pipe such as wood this.heat += FluidMasterList.getHeatPerPass(fluid.getFluid()); if (heat >= this.maxHeat) { diff --git a/src/dark/fluid/common/pump/TileEntityConstructionPump.java b/src/dark/fluid/common/pump/TileEntityConstructionPump.java index 00733f132..5b3c2bebf 100644 --- a/src/dark/fluid/common/pump/TileEntityConstructionPump.java +++ b/src/dark/fluid/common/pump/TileEntityConstructionPump.java @@ -1,7 +1,9 @@ package dark.fluid.common.pump; import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; +import java.util.Map.Entry; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; @@ -85,11 +87,12 @@ public class TileEntityConstructionPump extends TileEntityStarterPump implements { if (outputTile instanceof IFluidHandler) { - for (IFluidHandler tank : ((NetworkFluidTiles) ((INetworkPipe) inputTile).getTileNetwork()).connectedTanks) + for (Entry> entry : ((NetworkFluidTiles) ((INetworkPipe) inputTile).getTileNetwork()).connctedFluidHandlers.entrySet()) { - if (tank instanceof IDrain && !ignoreList.contains(tank)) + + if (entry.getKey() instanceof IDrain && !ignoreList.contains(entry.getKey())) { - drain = (IDrain) tank; + drain = (IDrain) entry.getKey(); break; } } @@ -172,9 +175,9 @@ public class TileEntityConstructionPump extends TileEntityStarterPump implements if (inputTile instanceof INetworkPipe && ((INetworkPipe) inputTile).getTileNetwork() instanceof NetworkFluidTiles) { int count = 0; - for (IFluidHandler tank : ((NetworkFluidTiles) ((INetworkPipe) inputTile).getTileNetwork()).connectedTanks) + for (Entry> entry : ((NetworkFluidTiles) ((INetworkPipe) inputTile).getTileNetwork()).connctedFluidHandlers.entrySet()) { - if (tank instanceof IDrain) + if (entry.getKey() instanceof IDrain) { count++; } diff --git a/src/dark/fluid/common/pump/TileEntityStarterPump.java b/src/dark/fluid/common/pump/TileEntityStarterPump.java index d9ac741c1..0ed6dc146 100644 --- a/src/dark/fluid/common/pump/TileEntityStarterPump.java +++ b/src/dark/fluid/common/pump/TileEntityStarterPump.java @@ -141,11 +141,6 @@ public class TileEntityStarterPump extends TileEntityEnergyMachine implements IT } } - if (ExternalModHandler.isBCFluidPipe(drain)) - { - //TODO add resource pathfinder - } - if (drainList == null) { if (this.getLiquidFinder().results.size() < MAX_WORLD_EDITS_PER_PROCESS + 10) @@ -170,7 +165,7 @@ public class TileEntityStarterPump extends TileEntityEnergyMachine implements IT Vector3 drainLocation = fluidList.next(); FluidStack drainStack = FluidHelper.drainBlock(world, drainLocation, false, 3); - // System.out.println("StartPump>>DrainArea>>Draining>>NextFluidBlock>" + (drainStack == null ? "Null" : drainStack.amount + "mb of " + drainStack.getFluid().getName())); + //System.out.println("StartPump>>DrainArea>>Draining>>NextFluidBlock>" + (drainStack == null ? "Null" : drainStack.amount + "mb of " + drainStack.getFluid().getName())); //int fillV = FluidHelper.fillTanksAllSides(worldObj, new Vector3(this), drainStack, false, ForgeDirection.DOWN); //System.out.println("StartPump>>DrainArea>>Draining>>NextFluidBlock>Filled>" + fillV + "mb");