Very unstable improved machine searching part5
This commit is contained in:
@@ -54,11 +54,7 @@ public abstract class BlockMachine extends BlockBase {
|
||||
super.onNeighborBlockChange(world, pos, state, neighborBlock);
|
||||
|
||||
if (!world.isRemote) {
|
||||
TileMachine machine = (TileMachine) world.getTileEntity(pos);
|
||||
|
||||
if (!machine.isConnected()) {
|
||||
machine.searchController();
|
||||
}
|
||||
((TileMachine) world.getTileEntity(pos)).searchController();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,11 @@ public class ControllerSearcher {
|
||||
Block block = world.getBlockState(current).getBlock();
|
||||
|
||||
if (tile instanceof TileMachine || block == RefinedStorageBlocks.CABLE) {
|
||||
// We need to have visited more than 1 tile so that the relay can find a controller for itself
|
||||
if (visited.size() > 1 && tile instanceof TileRelay && !((TileRelay) tile).isConnected()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||
TileController controller = search(world, current.offset(dir), visited);
|
||||
|
||||
|
||||
@@ -28,14 +28,14 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
||||
|
||||
TileController newController = ControllerSearcher.search(worldObj, pos, visited);
|
||||
|
||||
if (newController != null) {
|
||||
this.controller = newController;
|
||||
|
||||
onConnected();
|
||||
} else if (this.controller != null) {
|
||||
this.controller = null;
|
||||
|
||||
onDisconnected();
|
||||
if (controller == null) {
|
||||
if (newController != null) {
|
||||
onConnected(newController);
|
||||
}
|
||||
} else {
|
||||
if (newController == null) {
|
||||
onDisconnected();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,24 +50,33 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
||||
super.update();
|
||||
}
|
||||
|
||||
public void onConnected() {
|
||||
connected = true;
|
||||
public void onConnected(TileController controller) {
|
||||
this.controller = controller;
|
||||
this.connected = true;
|
||||
|
||||
if (worldObj.getBlockState(pos).getBlock() == block) {
|
||||
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, true));
|
||||
}
|
||||
|
||||
worldObj.notifyNeighborsOfStateChange(pos, block);
|
||||
|
||||
controller.addMachine(this);
|
||||
}
|
||||
|
||||
public void onDisconnected() {
|
||||
connected = false;
|
||||
this.connected = false;
|
||||
|
||||
if (worldObj.getBlockState(pos).getBlock() == block) {
|
||||
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, false));
|
||||
}
|
||||
|
||||
controller.removeMachine(this);
|
||||
// I have no idea why this is needed
|
||||
if (controller != null) {
|
||||
this.controller.removeMachine(this);
|
||||
this.controller = null;
|
||||
}
|
||||
|
||||
worldObj.notifyNeighborsOfStateChange(pos, block);
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
|
||||
Reference in New Issue
Block a user