diff --git a/common/crazypants/enderio/conduit/AbstractConduit.java b/common/crazypants/enderio/conduit/AbstractConduit.java index 30d659ca..421fcea2 100644 --- a/common/crazypants/enderio/conduit/AbstractConduit.java +++ b/common/crazypants/enderio/conduit/AbstractConduit.java @@ -157,7 +157,10 @@ public abstract class AbstractConduit implements IConduit { @Override public boolean canConnectToConduit(ForgeDirection direction, IConduit conduit) { - return true; + if(conduit == null) { + return false; + } + return getConectionMode(direction) != ConnectionMode.DISABLED && conduit.getConectionMode(direction.getOpposite()) != ConnectionMode.DISABLED; } @Override diff --git a/common/crazypants/enderio/conduit/AbstractConduitNetwork.java b/common/crazypants/enderio/conduit/AbstractConduitNetwork.java index 63a675b7..304cdd3c 100644 --- a/common/crazypants/enderio/conduit/AbstractConduitNetwork.java +++ b/common/crazypants/enderio/conduit/AbstractConduitNetwork.java @@ -49,7 +49,9 @@ public abstract class AbstractConduitNetwork { } public void addConduit(T con) { - conduits.add(con); + if(!conduits.contains(con)) { + conduits.add(con); + } } public void destroyNetwork() { diff --git a/common/crazypants/enderio/conduit/ConduitUtil.java b/common/crazypants/enderio/conduit/ConduitUtil.java index 713623f9..b49f37c2 100644 --- a/common/crazypants/enderio/conduit/ConduitUtil.java +++ b/common/crazypants/enderio/conduit/ConduitUtil.java @@ -29,6 +29,7 @@ import crazypants.enderio.conduit.power.PowerConduitNetwork; import crazypants.enderio.conduit.redstone.IInsulatedRedstoneConduit; import crazypants.enderio.conduit.redstone.IRedstoneConduit; import crazypants.enderio.conduit.redstone.RedstoneConduitNetwork; +import crazypants.util.BlockCoord; public class ConduitUtil { @@ -84,6 +85,54 @@ public class ConduitUtil { return false; } + public static void disconectConduits(T con, ForgeDirection connDir) { + con.conduitConnectionRemoved(connDir); + BlockCoord loc = con.getLocation().getLocation(connDir); + IConduit neighbour = ConduitUtil.getConduit(con.getBundle().getEntity().worldObj, loc.x, loc.y, loc.z, con.getBaseConduitType()); + if(neighbour != null) { + neighbour.conduitConnectionRemoved(connDir.getOpposite()); + if(neighbour.getNetwork() != null) { + neighbour.getNetwork().destroyNetwork(); + } + } + if(con.getNetwork() != null) { //this should have been destroyed when destroying the neighbours network but lets just make sure + con.getNetwork().destroyNetwork(); + } + } + + public static boolean joinConduits(T con, ForgeDirection faceHit) { + BlockCoord loc = con.getLocation().getLocation(faceHit); + IConduit neighbour = ConduitUtil.getConduit(con.getBundle().getEntity().worldObj, loc.x, loc.y, loc.z, con.getBaseConduitType()); + if(neighbour != null && con.canConnectToConduit(faceHit, neighbour) && neighbour.canConnectToConduit(faceHit.getOpposite(), con)) { + con.conduitConnectionAdded(faceHit); + neighbour.conduitConnectionAdded(faceHit.getOpposite()); + if(con.getNetwork() != null) { + con.getNetwork().destroyNetwork(); + } + if(neighbour.getNetwork() != null) { + neighbour.getNetwork().destroyNetwork(); + } + return true; + } + return false; + } + + public static void forceSkylightRecalculation(World worldObj, int xCoord, int yCoord, int zCoord) { + int height = worldObj.getHeightValue(xCoord, zCoord); + if(height <= yCoord) { + for (int i = 1; i < 12; i++) { + if(worldObj.isAirBlock(xCoord, yCoord + i, zCoord)) { + //We need to force the re-lighting of the column due to a change + //in the light reaching bellow the block from the sky. To avoid + //modifying core classes to expose this functionality I am just placing then breaking + //a block above this one to force the check + worldObj.setBlock(xCoord, yCoord + i, zCoord, 1, 0, 3); + worldObj.setBlockToAir(xCoord, yCoord + i, zCoord); + } + } + } + } + @SideOnly(Side.CLIENT) public static FacadeRenderState getRequiredFacadeRenderState(IConduitBundle bundle, EntityPlayer player) { if(!bundle.hasFacade()) { @@ -202,10 +251,14 @@ public class ConduitUtil { } List result = new ArrayList(); IConduitBundle root = (IConduitBundle) te; - for (ForgeDirection dir : root.getAllConnections()) { - T con = getConduit(world, root.getEntity(), dir, type); - if(con != null) { - result.add(con); + T con = root.getConduit(type); + if(con != null) { + for (ForgeDirection dir : con.getConduitConnections()) { + T connected = getConduit(world, root.getEntity(), dir, type); + if(connected != null) { + result.add(connected); + } + } } return result; diff --git a/common/crazypants/enderio/conduit/TileConduitBundle.java b/common/crazypants/enderio/conduit/TileConduitBundle.java index cf83b70a..0518c3de 100644 --- a/common/crazypants/enderio/conduit/TileConduitBundle.java +++ b/common/crazypants/enderio/conduit/TileConduitBundle.java @@ -184,15 +184,7 @@ public class TileConduitBundle extends TileEntity implements IConduitBundle { } if(worldObj != null && facadeChanged) { - int height = worldObj.getHeightValue(xCoord, zCoord); - if(height <= yCoord) { - //We need to force the re-lighting of the column due to a change - //in the light reaching bellow the block from the sky. To avoid - //modifying core classes to expose this functionality I am just placing then breaking - //a block above this one to force the check - worldObj.setBlock(xCoord, yCoord + 1, zCoord, 1, 0, 3); - worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord); - } + ConduitUtil.forceSkylightRecalculation(worldObj, xCoord, yCoord, zCoord); worldObj.updateAllLightTypes(xCoord, yCoord, zCoord); worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord); diff --git a/common/crazypants/enderio/conduit/item/ItemConduit.java b/common/crazypants/enderio/conduit/item/ItemConduit.java index 57f09d19..2cf4a715 100644 --- a/common/crazypants/enderio/conduit/item/ItemConduit.java +++ b/common/crazypants/enderio/conduit/item/ItemConduit.java @@ -13,8 +13,6 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; -import crazypants.enderio.ClientProxy; -import crazypants.enderio.EnderIO; import crazypants.enderio.ModObject; import crazypants.enderio.conduit.AbstractConduit; import crazypants.enderio.conduit.AbstractConduitNetwork; @@ -24,12 +22,8 @@ import crazypants.enderio.conduit.IConduit; import crazypants.enderio.conduit.IConduitBundle; import crazypants.enderio.conduit.RaytraceResult; import crazypants.enderio.conduit.geom.CollidableComponent; -import crazypants.render.BoundingBox; import crazypants.render.IconUtil; import crazypants.util.BlockCoord; -import crazypants.util.ForgeDirectionOffsets; -import crazypants.vecmath.Vector3d; -import crazypants.vecmath.Vector3f; public class ItemConduit extends AbstractConduit implements IItemConduit { @@ -74,9 +68,9 @@ public class ItemConduit extends AbstractConduit implements IItemConduit { int maxExtractedOnTick = 2; float extractRatePerTick = maxExtractedOnTick / 20f; - long extractedAtLastTick = -1; + long extractedAtLastTick = -1; - public ItemConduit() { + public ItemConduit() { } @Override @@ -86,31 +80,14 @@ public class ItemConduit extends AbstractConduit implements IItemConduit { if(res != null && res.component != null) { ForgeDirection connDir = res.component.dir; ForgeDirection faceHit = ForgeDirection.getOrientation(res.movingObjectPosition.sideHit); - if(connDir == ForgeDirection.UNKNOWN || connDir == faceHit) { // Attempt to join networks - BlockCoord loc = getLocation().getLocation(faceHit); - IItemConduit neighbour = ConduitUtil.getConduit(getBundle().getEntity().worldObj, loc.x, loc.y, loc.z, IItemConduit.class); - if(neighbour != null) { - if(network != null) { - network.destroyNetwork(); - } - onAddedToBundle(); - return true; - } + return ConduitUtil.joinConduits(this, faceHit); } else if(externalConnections.contains(connDir)) { setConnectionMode(connDir, getNextConnectionMode(connDir)); return true; } else if(containsConduitConnection(connDir)) { - conduitConnectionRemoved(connDir); - BlockCoord loc = getLocation().getLocation(connDir); - IItemConduit neighbour = ConduitUtil.getConduit(getBundle().getEntity().worldObj, loc.x, loc.y, loc.z, IItemConduit.class); - if(neighbour != null) { - neighbour.conduitConnectionRemoved(connDir.getOpposite()); - } - if(network != null) { - network.destroyNetwork(); - } + ConduitUtil.disconectConduits(this, connDir); return true; } } @@ -255,59 +232,59 @@ public class ItemConduit extends AbstractConduit implements IItemConduit { return null; } -// @Override -// public List getCollidableComponents() { -// if(collidables != null && !collidablesDirty) { -// return collidables; -// } -// List result = super.getCollidableComponents(); -// -// for (ForgeDirection dir : getExternalConnections()) { -// if(getConectionMode(dir) != ConnectionMode.DISABLED && getConectionMode(dir) != ConnectionMode.NOT_SET) { -// float scale = 0.1f; -// BoundingBox bb = BoundingBox.UNIT_CUBE.scale(scale, scale, scale); -// -// Vector3d offset = ForgeDirectionOffsets.forDirCopy(dir); -// offset.scale(scale/2); -// -// BoundingBox conectorBounds = ((ClientProxy) EnderIO.proxy).getConduitBundleRenderer().getExternalConnectorBoundsForDirection(dir); -// List corners = conectorBounds.getCornersForFace(dir); -// -// Vector3d center = new Vector3d(); -// for (Vector3f vec : corners) { -// center.add(vec); -// } -// center.scale(0.25); -// Vector3d toCenter = new Vector3d(); -// -// for (Vector3f vec : corners) { -// -// -// -// -// -// toCenter.set(center); -// toCenter.sub(vec); -// toCenter.normalize(); -// toCenter.scale(scale/2); -// -// vec.sub(new Vector3f(0.5f, 0.5f, 0.5f)); //center -// vec.sub(new Vector3f(offset)); //move them flush with block space -// vec.add(toCenter); // -// -// BoundingBox bbb = bb.translate(vec); -// result.add(new CollidableComponent(IItemConduit.class, bbb, dir, EXTERNAL_INTERFACE_GEOM)); -// } -// -// } -// } -// -// return result; -// } + // @Override + // public List getCollidableComponents() { + // if(collidables != null && !collidablesDirty) { + // return collidables; + // } + // List result = super.getCollidableComponents(); + // + // for (ForgeDirection dir : getExternalConnections()) { + // if(getConectionMode(dir) != ConnectionMode.DISABLED && getConectionMode(dir) != ConnectionMode.NOT_SET) { + // float scale = 0.1f; + // BoundingBox bb = BoundingBox.UNIT_CUBE.scale(scale, scale, scale); + // + // Vector3d offset = ForgeDirectionOffsets.forDirCopy(dir); + // offset.scale(scale/2); + // + // BoundingBox conectorBounds = ((ClientProxy) EnderIO.proxy).getConduitBundleRenderer().getExternalConnectorBoundsForDirection(dir); + // List corners = conectorBounds.getCornersForFace(dir); + // + // Vector3d center = new Vector3d(); + // for (Vector3f vec : corners) { + // center.add(vec); + // } + // center.scale(0.25); + // Vector3d toCenter = new Vector3d(); + // + // for (Vector3f vec : corners) { + // + // + // + // + // + // toCenter.set(center); + // toCenter.sub(vec); + // toCenter.normalize(); + // toCenter.scale(scale/2); + // + // vec.sub(new Vector3f(0.5f, 0.5f, 0.5f)); //center + // vec.sub(new Vector3f(offset)); //move them flush with block space + // vec.add(toCenter); // + // + // BoundingBox bbb = bb.translate(vec); + // result.add(new CollidableComponent(IItemConduit.class, bbb, dir, EXTERNAL_INTERFACE_GEOM)); + // } + // + // } + // } + // + // return result; + // } @Override public void writeToNBT(NBTTagCompound nbtRoot) { - super.writeToNBT(nbtRoot); + super.writeToNBT(nbtRoot); } @Override diff --git a/common/crazypants/enderio/conduit/item/ItemConduitNetwork.java b/common/crazypants/enderio/conduit/item/ItemConduitNetwork.java index c76c255f..b8a6ef1b 100644 --- a/common/crazypants/enderio/conduit/item/ItemConduitNetwork.java +++ b/common/crazypants/enderio/conduit/item/ItemConduitNetwork.java @@ -36,10 +36,10 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { super.addConduit(con); TileEntity te = con.getBundle().getEntity(); - if (te != null) { + if(te != null) { for (ForgeDirection direction : con.getExternalConnections()) { IInventory extCon = con.getExternalInventory(direction); - if (extCon != null) { + if(extCon != null) { inventoryAdded(con, direction, te.xCoord + direction.offsetX, te.yCoord + direction.offsetY, te.zCoord + direction.offsetZ, extCon); } } @@ -57,7 +57,7 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { public void inventoryRemoved(ItemConduit itemConduit, int x, int y, int z) { BlockCoord bc = new BlockCoord(x, y, z); NetworkedInventory inv = invMap.remove(bc); - if (inv != null) { + if(inv != null) { inventories.remove(inv); } requiresSort = true; @@ -69,7 +69,7 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { private boolean isRemote(ItemConduit itemConduit) { World world = itemConduit.getBundle().getEntity().worldObj; - if (world != null && world.isRemote) { + if(world != null && world.isRemote) { return true; } return false; @@ -78,14 +78,14 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { @Override public void onUpdateEntity(IConduit conduit) { World world = conduit.getBundle().getEntity().worldObj; - if (world == null) { + if(world == null) { return; } - if (world.isRemote) { + if(world.isRemote) { return; } long curTime = world.getTotalWorldTime(); - if (curTime != timeAtLastApply) { + if(curTime != timeAtLastApply) { timeAtLastApply = curTime; doTick(); } @@ -93,7 +93,7 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { private void doTick() { for (NetworkedInventory ni : inventories) { - if (requiresSort) { + if(requiresSort) { ni.updateInsertOrder(); } ni.onTick(); @@ -113,14 +113,14 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { ForgeDirection conDir; BlockCoord location; int inventorySide; - + boolean allowSelfFeed = false; List sendPriority = new ArrayList(); NetworkedInventory(IInventory inv, IItemConduit con, ForgeDirection conDir, BlockCoord location) { this.inv = inv; - if (inv instanceof ISidedInventory) { + if(inv instanceof ISidedInventory) { sidedInv = (ISidedInventory) inv; } this.con = con; @@ -140,10 +140,10 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { } void onTick() { - if (!canExtract()) { + if(!canExtract()) { return; } - if (sidedInv != null) { + if(sidedInv != null) { transferItemsSided(); } else { tranfserItems(); @@ -159,12 +159,12 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { int slot = -1; for (int i = 0; i < numSlots; i++) { ItemStack item = inv.getStackInSlot(i); - if (item != null) { + if(item != null) { extractItem = item.copy(); slot = i; int maxExtracted = con.getMaximumExtracted(slot); - if (maxExtracted > 0) { - if (doTranfser(extractItem, slot, maxExtracted)) { + if(maxExtracted > 0) { + if(doTranfser(extractItem, slot, maxExtracted)) { return; } @@ -183,13 +183,13 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { int slot = -1; for (int i = 0; i < slotIndices.length; i++) { ItemStack item = sidedInv.getStackInSlot(i); - if (item != null) { + if(item != null) { extractItem = item.copy(); slot = i; - if (sidedInv.canExtractItem(i, extractItem, inventorySide)) { + if(sidedInv.canExtractItem(i, extractItem, inventorySide)) { int maxExtracted = con.getMaximumExtracted(slot); - if (maxExtracted > 0) { - if (doTranfser(extractItem, slot, maxExtracted)) { + if(maxExtracted > 0) { + if(doTranfser(extractItem, slot, maxExtracted)) { return; } } @@ -199,13 +199,13 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { } private boolean doTranfser(ItemStack extractedItem, int slot, int maxExtract) { - if (extractedItem == null) { + if(extractedItem == null) { return false; } ItemStack toExtract = extractedItem.copy(); toExtract.stackSize = Math.min(maxExtract, toExtract.stackSize); int numInserted = insertIntoTargets(toExtract, slot); - if (numInserted <= 0) { + if(numInserted <= 0) { return false; } @@ -225,7 +225,7 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { } private int insertIntoTargets(ItemStack toExtract, int slot) { - if (toExtract == null) { + if(toExtract == null) { return 0; } @@ -233,11 +233,11 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { int leftToInsert = totalToInsert; for (Target target : sendPriority) { int inserted = target.inv.insertItem(toExtract); - if (inserted > 0) { + if(inserted > 0) { toExtract.stackSize -= inserted; leftToInsert -= inserted; } - if (leftToInsert <= 0) { + if(leftToInsert <= 0) { return totalToInsert; } } @@ -245,14 +245,14 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { } private int insertItem(ItemStack item) { - if (sidedInv != null) { + if(sidedInv != null) { return doInsertItemSided(item); } return doInsertItem(item); } private int doInsertItem(ItemStack item) { - if (!canInsert() || item == null) { + if(!canInsert() || item == null) { return 0; } @@ -264,10 +264,10 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { toInsert.stackSize = Math.min(toInsert.stackSize, inv.getInventoryStackLimit()); toInsert.stackSize = Math.min(toInsert.stackSize, numToInsert); int inserted = 0; - if (contents == null) { + if(contents == null) { inserted = toInsert.stackSize; } else { - if (contents.isItemEqual(item) && ItemStack.areItemStackTagsEqual(contents, item)) { + if(contents.isItemEqual(item) && ItemStack.areItemStackTagsEqual(contents, item)) { int space = inv.getInventoryStackLimit() - contents.stackSize; space = Math.min(space, contents.getMaxStackSize() - contents.stackSize); inserted += Math.min(space, toInsert.stackSize); @@ -277,7 +277,7 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { } } - if (inserted > 0) { + if(inserted > 0) { numInserted += inserted; numToInsert -= inserted; inv.setInventorySlotContents(slot, toInsert); @@ -292,16 +292,16 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { int numInserted = 0; int numToInsert = item.stackSize; for (int slot = 0; slot < inv.getSizeInventory() && numToInsert > 0; slot++) { - if (sidedInv.canInsertItem(slot, item, inventorySide)) { + if(sidedInv.canInsertItem(slot, item, inventorySide)) { ItemStack contents = inv.getStackInSlot(slot); ItemStack toInsert = item.copy(); toInsert.stackSize = Math.min(toInsert.stackSize, inv.getInventoryStackLimit()); toInsert.stackSize = Math.min(toInsert.stackSize, numToInsert); int inserted = 0; - if (contents == null) { + if(contents == null) { inserted = toInsert.stackSize; } else { - if (contents.isItemEqual(item) && ItemStack.areItemStackTagsEqual(contents, item)) { + if(contents.isItemEqual(item) && ItemStack.areItemStackTagsEqual(contents, item)) { int space = inv.getInventoryStackLimit() - contents.stackSize; space = Math.min(space, contents.getMaxStackSize() - contents.stackSize); inserted += Math.min(space, toInsert.stackSize); @@ -311,7 +311,7 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { } } - if (inserted > 0) { + if(inserted > 0) { numInserted += inserted; numToInsert -= inserted; inv.setInventorySlotContents(slot, toInsert); @@ -323,11 +323,11 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { void updateInsertOrder() { sendPriority.clear(); - if (!canExtract()) { + if(!canExtract()) { return; } for (NetworkedInventory other : inventories) { - if ((allowSelfFeed || (other != this)) && other.canInsert()) { + if((allowSelfFeed || (other != this)) && other.canInsert()) { sendPriority.add(new Target(other, location.distanceSquared(other.location))); } } diff --git a/common/crazypants/enderio/conduit/liquid/LiquidConduit.java b/common/crazypants/enderio/conduit/liquid/LiquidConduit.java index 7e0eeb4d..c90fb388 100644 --- a/common/crazypants/enderio/conduit/liquid/LiquidConduit.java +++ b/common/crazypants/enderio/conduit/liquid/LiquidConduit.java @@ -98,39 +98,21 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit { if(!getBundle().getEntity().worldObj.isRemote) { if(res != null && res.component != null) { + ForgeDirection connDir = res.component.dir; ForgeDirection faceHit = ForgeDirection.getOrientation(res.movingObjectPosition.sideHit); if(connDir == ForgeDirection.UNKNOWN || connDir == faceHit) { - // Attempt to join networks - ILiquidConduit neighbour = getFluidConduit(faceHit); - if(neighbour != null && LiquidConduitNetwork.areFluidsCompatable(getFluidType(), neighbour.getFluidType())) { - // kill the networks so a new one is formed combining then - if(neighbour.getNetwork() != null) { - neighbour.getNetwork().destroyNetwork(); - } - if(getNetwork() != null) { - getNetwork().destroyNetwork(); - } - // and join'm'up - neighbour.conduitConnectionAdded(faceHit.getOpposite()); - conduitConnectionAdded(faceHit); - } + return ConduitUtil.joinConduits(this, faceHit); } else if(containsExternalConnection(connDir)) { // Toggle extraction mode setConnectionMode(connDir, getNextConnectionMode(connDir)); } else if(containsConduitConnection(connDir)) { - conduitConnectionRemoved(connDir); - BlockCoord loc = getLocation().getLocation(connDir); - ILiquidConduit neighbour = ConduitUtil.getConduit(getBundle().getEntity().worldObj, loc.x, loc.y, loc.z, ILiquidConduit.class); - if(neighbour != null) { - neighbour.conduitConnectionRemoved(connDir.getOpposite()); - } FluidStack curFluidType = null; if(network != null) { curFluidType = network.getFluidType(); } - network.destroyNetwork(); + ConduitUtil.disconectConduits(this, connDir); setFluidType(curFluidType); } @@ -546,6 +528,9 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit { @Override public boolean canConnectToConduit(ForgeDirection direction, IConduit con) { + if(!super.canConnectToConduit(direction, con)) { + return false; + } if(!(con instanceof ILiquidConduit)) { return false; } diff --git a/common/crazypants/enderio/conduit/power/PowerConduit.java b/common/crazypants/enderio/conduit/power/PowerConduit.java index 8f26107b..e3634839 100644 --- a/common/crazypants/enderio/conduit/power/PowerConduit.java +++ b/common/crazypants/enderio/conduit/power/PowerConduit.java @@ -32,7 +32,6 @@ import crazypants.enderio.power.PowerHandlerUtil; import crazypants.enderio.power.PowerInterface; import crazypants.render.BoundingBox; import crazypants.render.IconUtil; -import crazypants.util.BlockCoord; import crazypants.vecmath.Vector3d; public class PowerConduit extends AbstractConduit implements IPowerConduit { @@ -105,31 +104,14 @@ public class PowerConduit extends AbstractConduit implements IPowerConduit { if(res != null && res.component != null) { ForgeDirection connDir = res.component.dir; ForgeDirection faceHit = ForgeDirection.getOrientation(res.movingObjectPosition.sideHit); - if(connDir == ForgeDirection.UNKNOWN || connDir == faceHit) { // Attempt to join networks - BlockCoord loc = getLocation().getLocation(faceHit); - IPowerConduit neighbour = ConduitUtil.getConduit(getBundle().getEntity().worldObj, loc.x, loc.y, loc.z, IPowerConduit.class); - if(neighbour != null) { - if(network != null) { - network.destroyNetwork(); - } - onAddedToBundle(); - return true; - } + return ConduitUtil.joinConduits(this, faceHit); } else if(externalConnections.contains(connDir)) { setConnectionMode(connDir, getNextConnectionMode(connDir)); return true; } else if(containsConduitConnection(connDir)) { - conduitConnectionRemoved(connDir); - BlockCoord loc = getLocation().getLocation(connDir); - IPowerConduit neighbour = ConduitUtil.getConduit(getBundle().getEntity().worldObj, loc.x, loc.y, loc.z, IPowerConduit.class); - if(neighbour != null) { - neighbour.conduitConnectionRemoved(connDir.getOpposite()); - } - if(network != null) { - network.destroyNetwork(); - } + ConduitUtil.disconectConduits(this, connDir); return true; } } diff --git a/common/crazypants/enderio/conduit/render/ConduitBundleRenderer.java b/common/crazypants/enderio/conduit/render/ConduitBundleRenderer.java index 46d67340..82990e01 100644 --- a/common/crazypants/enderio/conduit/render/ConduitBundleRenderer.java +++ b/common/crazypants/enderio/conduit/render/ConduitBundleRenderer.java @@ -73,16 +73,7 @@ public class ConduitBundleRenderer extends TileEntitySpecialRenderer implements } if(curRS != rs) { te.worldObj.markBlockForRenderUpdate(te.xCoord, te.yCoord, te.zCoord); - - int height = te.worldObj.getHeightValue(te.xCoord, te.zCoord); - if(height <= te.yCoord) { - //We need to force the re-lighting of the column due to a change - //in the light reaching bellow the block from the sky. To avoid - //modifying core classes to expose this functionality I am just placing then breaking - //a block above this one to force the check - te.worldObj.setBlock(te.xCoord, te.yCoord + 1, te.zCoord, 1, 0, 3); - te.worldObj.setBlockToAir(te.xCoord, te.yCoord + 1, te.zCoord); - } + ConduitUtil.forceSkylightRecalculation(te.worldObj, te.xCoord, te.yCoord, te.zCoord); } if(curRS == FacadeRenderState.FULL) {