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:
@@ -1,6 +1,9 @@
|
|||||||
# Refined Storage Changelog
|
# Refined Storage Changelog
|
||||||
|
|
||||||
### 0.6
|
### 0.6
|
||||||
|
**Bugfixes**
|
||||||
|
- Fixed machines out of the Controller's chunk range only connecting after block break on rejoining of the world
|
||||||
|
|
||||||
**Features**
|
**Features**
|
||||||
- Shift clicking on placing Constructor and Destructor will have opposite direction
|
- Shift clicking on placing Constructor and Destructor will have opposite direction
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,16 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
|
|
||||||
private boolean destroyed = false;
|
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
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
super.update();
|
super.update();
|
||||||
@@ -70,14 +80,22 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (TileMachine machine : machines) {
|
for (TileMachine machine : machines) {
|
||||||
if (!newMachines.contains(machine)) {
|
if (!machinesHavePosition(newMachines, machine.getPos())) {
|
||||||
machine.onDisconnected();
|
machine.onDisconnected();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (TileMachine machine : newMachines) {
|
for (TileMachine machine : newMachines) {
|
||||||
if (!machines.contains(machine)) {
|
if (!machinesHavePosition(machines, machine.getPos())) {
|
||||||
machine.onConnected(this);
|
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;
|
package refinedstorage.tile;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import refinedstorage.block.BlockMachine;
|
import refinedstorage.block.BlockMachine;
|
||||||
@@ -13,10 +12,8 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
|||||||
protected RedstoneMode redstoneMode = RedstoneMode.IGNORE;
|
protected RedstoneMode redstoneMode = RedstoneMode.IGNORE;
|
||||||
protected TileController controller;
|
protected TileController controller;
|
||||||
|
|
||||||
private Block machineBlock;
|
|
||||||
|
|
||||||
public void onConnected(TileController controller) {
|
public void onConnected(TileController controller) {
|
||||||
if (worldObj != null && worldObj.getBlockState(pos).getBlock() == machineBlock) {
|
if (worldObj != null && worldObj.getBlockState(pos).getBlock() == getBlockType()) {
|
||||||
markDirty();
|
markDirty();
|
||||||
|
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
@@ -27,7 +24,7 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onDisconnected() {
|
public void onDisconnected() {
|
||||||
if (worldObj != null && worldObj.getBlockState(pos).getBlock() == machineBlock) {
|
if (worldObj != null && worldObj.getBlockState(pos).getBlock() == getBlockType()) {
|
||||||
markDirty();
|
markDirty();
|
||||||
|
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
@@ -43,18 +40,9 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
if (worldObj == null) {
|
|
||||||
super.update();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ticks == 0) {
|
|
||||||
machineBlock = worldObj.getBlockState(pos).getBlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
super.update();
|
super.update();
|
||||||
|
|
||||||
if (!worldObj.isRemote && isConnected()) {
|
if (worldObj != null && !worldObj.isRemote && isConnected()) {
|
||||||
updateMachine();
|
updateMachine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user