diff --git a/CHANGELOG.md b/CHANGELOG.md index dbf104432..920a30d77 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Refined Storage Changelog ### 0.6 +**Bugfixes** +- Fixed machines out of the Controller's chunk range only connecting after block break on rejoining of the world + **Features** - Shift clicking on placing Constructor and Destructor will have opposite direction diff --git a/src/main/java/refinedstorage/tile/TileController.java b/src/main/java/refinedstorage/tile/TileController.java index 80e81998c..5e0988725 100755 --- a/src/main/java/refinedstorage/tile/TileController.java +++ b/src/main/java/refinedstorage/tile/TileController.java @@ -50,6 +50,16 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor private boolean destroyed = false; + private boolean machinesHavePosition(List tiles, BlockPos pos) { + for (TileEntity tile : tiles) { + if (tile.getPos().getX() == pos.getX() && tile.getPos().getY() == pos.getY() && tile.getPos().getZ() == pos.getZ()) { + return true; + } + } + + return false; + } + @Override public void update() { super.update(); @@ -70,14 +80,22 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor } for (TileMachine machine : machines) { - if (!newMachines.contains(machine)) { + if (!machinesHavePosition(newMachines, machine.getPos())) { machine.onDisconnected(); } } for (TileMachine machine : newMachines) { - if (!machines.contains(machine)) { + if (!machinesHavePosition(machines, machine.getPos())) { machine.onConnected(this); + } else { + /* This machine is in our machine list, but due to a chunk reload the tile entity + would get reset which causes its connected property to reset too (to false). + So, if the machine is in our list but not connected (which is the case due to a TE reload) + we connect it either way. */ + if (!machine.isConnected()) { + machine.onConnected(this); + } } } diff --git a/src/main/java/refinedstorage/tile/TileMachine.java b/src/main/java/refinedstorage/tile/TileMachine.java index 54f29104e..129c9a1f8 100755 --- a/src/main/java/refinedstorage/tile/TileMachine.java +++ b/src/main/java/refinedstorage/tile/TileMachine.java @@ -1,7 +1,6 @@ package refinedstorage.tile; import io.netty.buffer.ByteBuf; -import net.minecraft.block.Block; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; import refinedstorage.block.BlockMachine; @@ -13,10 +12,8 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed protected RedstoneMode redstoneMode = RedstoneMode.IGNORE; protected TileController controller; - private Block machineBlock; - public void onConnected(TileController controller) { - if (worldObj != null && worldObj.getBlockState(pos).getBlock() == machineBlock) { + if (worldObj != null && worldObj.getBlockState(pos).getBlock() == getBlockType()) { markDirty(); this.connected = true; @@ -27,7 +24,7 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed } public void onDisconnected() { - if (worldObj != null && worldObj.getBlockState(pos).getBlock() == machineBlock) { + if (worldObj != null && worldObj.getBlockState(pos).getBlock() == getBlockType()) { markDirty(); this.connected = false; @@ -43,18 +40,9 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed @Override public void update() { - if (worldObj == null) { - super.update(); - return; - } - - if (ticks == 0) { - machineBlock = worldObj.getBlockState(pos).getBlock(); - } - super.update(); - if (!worldObj.isRemote && isConnected()) { + if (worldObj != null && !worldObj.isRemote && isConnected()) { updateMachine(); } }