From 56e166c0aaa3f63083329530c0b1898cfea3dfa6 Mon Sep 17 00:00:00 2001 From: CrazyPants Date: Sat, 23 Nov 2013 08:26:36 +0800 Subject: [PATCH] #311 Cannot connect an empty fluid conduit to a full one. --- .../enderio/conduit/BlockConduitBundle.java | 77 +++++++++++-------- .../enderio/conduit/liquid/LiquidConduit.java | 11 +++ 2 files changed, 58 insertions(+), 30 deletions(-) diff --git a/common/crazypants/enderio/conduit/BlockConduitBundle.java b/common/crazypants/enderio/conduit/BlockConduitBundle.java index 677eea88..79961bd7 100644 --- a/common/crazypants/enderio/conduit/BlockConduitBundle.java +++ b/common/crazypants/enderio/conduit/BlockConduitBundle.java @@ -397,36 +397,11 @@ public class BlockConduitBundle extends Block implements ITileEntityProvider, IC } if(breakBlock) { - RaytraceResult rt = doRayTrace(world, x, y, z, player); - if(rt != null && rt.component != null) { - Class type = rt.component.conduitType; - if(type == null) { - // broke a conector so drop any conduits with no connections as there - // is no other way to remove these - List cons = new ArrayList(te.getConduits()); - boolean droppedUnconected = false; - for (IConduit con : cons) { - if(con.getConduitConnections().isEmpty() && - con.getExternalConnections().isEmpty()) { - te.removeConduit(con); - drop.add(con.createItem()); - droppedUnconected = true; - } - } - // If there isn't, then drop em all - if(!droppedUnconected) { - for (IConduit con : cons) { - te.removeConduit(con); - drop.add(con.createItem()); - } - } - } else { - IConduit con = te.getConduit(type); - if(con != null) { - te.removeConduit(con); - drop.add(con.createItem()); - } - + List results = doRayTraceAll(world, x, y, z, player); + RaytraceResult.sort(getEyePosition(world, player), results); + for (RaytraceResult rt : results) { + if(breakConduit(te, drop, rt, player)) { + break; } } } @@ -447,6 +422,48 @@ public class BlockConduitBundle extends Block implements ITileEntityProvider, IC return true; } + private boolean breakConduit(IConduitBundle te, List drop, RaytraceResult rt, EntityPlayer player) { + if(rt == null || rt.component == null) { + return false; + } + Class type = rt.component.conduitType; + if(!ConduitUtil.renderConduit(player, type)) { + return false; + } + + if(type == null) { + // broke a conector so drop any conduits with no connections as there + // is no other way to remove these + List cons = new ArrayList(te.getConduits()); + boolean droppedUnconected = false; + for (IConduit con : cons) { + if(con.getConduitConnections().isEmpty() && + con.getExternalConnections().isEmpty() && ConduitUtil.renderConduit(player, con)) { + te.removeConduit(con); + drop.add(con.createItem()); + droppedUnconected = true; + } + } + // If there isn't, then drop em all + if(!droppedUnconected) { + for (IConduit con : cons) { + if(ConduitUtil.renderConduit(player, con)) { + te.removeConduit(con); + drop.add(con.createItem()); + } + } + } + } else { + IConduit con = te.getConduit(type); + if(con != null) { + te.removeConduit(con); + drop.add(con.createItem()); + } + } + + return true; + } + @Override public void breakBlock(World world, int x, int y, int z, int par5, int par6) { diff --git a/common/crazypants/enderio/conduit/liquid/LiquidConduit.java b/common/crazypants/enderio/conduit/liquid/LiquidConduit.java index e9ef5831..8f5b6a6b 100644 --- a/common/crazypants/enderio/conduit/liquid/LiquidConduit.java +++ b/common/crazypants/enderio/conduit/liquid/LiquidConduit.java @@ -103,6 +103,17 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit { ForgeDirection faceHit = ForgeDirection.getOrientation(res.movingObjectPosition.sideHit); if(connDir == ForgeDirection.UNKNOWN || connDir == faceHit) { + BlockCoord loc = getLocation().getLocation(faceHit); + ILiquidConduit neighbour = ConduitUtil.getConduit(getBundle().getEntity().worldObj, loc.x, loc.y, loc.z, ILiquidConduit.class); + if(neighbour == null) { + return false; + } + if(neighbour.getFluidType() == null || getFluidType() == null) { + FluidStack type = getFluidType(); + type = type != null ? type : neighbour.getFluidType(); + neighbour.setFluidType(type); + setFluidType(type); + } return ConduitUtil.joinConduits(this, faceHit); } else if(containsExternalConnection(connDir)) { // Toggle extraction mode