Fixed machines out of the Controller's chunk range only connecting after block break on rejoining of the world (this was a pain to debug)
This commit is contained in:
@@ -50,6 +50,16 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
|
||||
private boolean destroyed = false;
|
||||
|
||||
private boolean machinesHavePosition(List<TileMachine> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user