From 0819c0ad5f75e9bf8af1c9cec8a5605b56fd9d1d Mon Sep 17 00:00:00 2001 From: "Aidan C. Brady" Date: Thu, 19 Feb 2015 09:13:03 -0500 Subject: [PATCH] Hopefully fixed the transmitter network halt issue. Provide feedback! --- .../common/multipart/PartSidedPipe.java | 19 ++++++++------- .../mekanism/common/util/MekanismUtils.java | 24 +++++++++++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/main/java/mekanism/common/multipart/PartSidedPipe.java b/src/main/java/mekanism/common/multipart/PartSidedPipe.java index 700037c4c..23b0d53b9 100644 --- a/src/main/java/mekanism/common/multipart/PartSidedPipe.java +++ b/src/main/java/mekanism/common/multipart/PartSidedPipe.java @@ -173,7 +173,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart, { byte connections = 0x00; - if(redstoneReactive && world().isBlockIndirectlyGettingPowered(x(), y(), z())) + if(redstoneReactive && MekanismUtils.isGettingPowered(world(), Coord4D.get(tile()))) { return connections; } @@ -198,7 +198,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart, { byte connections = 0x00; - if(redstoneReactive && world().isBlockIndirectlyGettingPowered(x(), y(), z())) + if(redstoneReactive && MekanismUtils.isGettingPowered(world(), Coord4D.get(tile()))) { return connections; } @@ -347,7 +347,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart, @Override public boolean canConnect(ForgeDirection side) { - if(redstoneReactive && world().isBlockIndirectlyGettingPowered(x(), y(), z())) + if(redstoneReactive && MekanismUtils.isGettingPowered(world(), Coord4D.get(tile()))) { return false; } @@ -463,7 +463,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart, public void redstoneRefresh() { - boolean nowPowered = redstoneReactive && world().isBlockIndirectlyGettingPowered(x(), y(), z()); + boolean nowPowered = redstoneReactive && MekanismUtils.isGettingPowered(world(), Coord4D.get(tile())); if(nowPowered != redstonePowered) { @@ -479,7 +479,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart, if(possibleTransmitters != currentTransmitterConnections) { - boolean nowPowered = redstoneReactive && world().isBlockIndirectlyGettingPowered(x(), y(), z()); + boolean nowPowered = redstoneReactive && MekanismUtils.isGettingPowered(world(), Coord4D.get(tile())); if(nowPowered != redstonePowered) { @@ -489,8 +489,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart, { onRedstoneSplit(); } - else - { + else { onRedstoneJoin(); } @@ -520,7 +519,8 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart, public void onAdded() { super.onAdded(); - redstonePowered = redstoneReactive && world().isBlockIndirectlyGettingPowered(x(), y(), z()); + + redstonePowered = redstoneReactive && MekanismUtils.isGettingPowered(world(), Coord4D.get(tile())); refreshConnections(); } @@ -528,7 +528,8 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart, public void onChunkLoad() { super.onChunkLoad(); - redstonePowered = redstoneReactive && world().isBlockIndirectlyGettingPowered(x(), y(), z()); + + redstonePowered = redstoneReactive && MekanismUtils.isGettingPowered(world(), Coord4D.get(tile())); refreshConnections(); } diff --git a/src/main/java/mekanism/common/util/MekanismUtils.java b/src/main/java/mekanism/common/util/MekanismUtils.java index 707e43c7c..cba2a42ef 100644 --- a/src/main/java/mekanism/common/util/MekanismUtils.java +++ b/src/main/java/mekanism/common/util/MekanismUtils.java @@ -669,6 +669,30 @@ public final class MekanismUtils { return def * Math.pow(Mekanism.maxUpgradeMultiplier, mgmt.getEnergyMultiplier(itemStack)/8.0); } + + /** + * A better "isBlockIndirectlyGettingPowered()" that doesn't load chunks + * @param world - the world to perform the check in + * @param coord - the coordinate of the block performing the check + * @return if the block is indirectly getting powered by LOADED chunks + */ + public static boolean isGettingPowered(World world, Coord4D coord) + { + for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + { + Coord4D sideCoord = coord.getFromSide(side); + + if(sideCoord.exists(world)) + { + if(world.getIndirectPowerLevelTo(sideCoord.xCoord, sideCoord.yCoord, sideCoord.zCoord, side.ordinal()) > 0) + { + return true; + } + } + } + + return false; + } /** * Places a fake bounding block at the defined location.