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);
|
super.onNeighborBlockChange(world, pos, state, neighborBlock);
|
||||||
|
|
||||||
if (!world.isRemote) {
|
if (!world.isRemote) {
|
||||||
TileMachine machine = (TileMachine) world.getTileEntity(pos);
|
((TileMachine) world.getTileEntity(pos)).searchController();
|
||||||
|
|
||||||
if (!machine.isConnected()) {
|
|
||||||
machine.searchController();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ public class ControllerSearcher {
|
|||||||
Block block = world.getBlockState(current).getBlock();
|
Block block = world.getBlockState(current).getBlock();
|
||||||
|
|
||||||
if (tile instanceof TileMachine || block == RefinedStorageBlocks.CABLE) {
|
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) {
|
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||||
TileController controller = search(world, current.offset(dir), visited);
|
TileController controller = search(world, current.offset(dir), visited);
|
||||||
|
|
||||||
|
|||||||
@@ -28,16 +28,16 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
|||||||
|
|
||||||
TileController newController = ControllerSearcher.search(worldObj, pos, visited);
|
TileController newController = ControllerSearcher.search(worldObj, pos, visited);
|
||||||
|
|
||||||
|
if (controller == null) {
|
||||||
if (newController != null) {
|
if (newController != null) {
|
||||||
this.controller = newController;
|
onConnected(newController);
|
||||||
|
}
|
||||||
onConnected();
|
} else {
|
||||||
} else if (this.controller != null) {
|
if (newController == null) {
|
||||||
this.controller = null;
|
|
||||||
|
|
||||||
onDisconnected();
|
onDisconnected();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
@@ -50,24 +50,33 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
|||||||
super.update();
|
super.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onConnected() {
|
public void onConnected(TileController controller) {
|
||||||
connected = true;
|
this.controller = controller;
|
||||||
|
this.connected = true;
|
||||||
|
|
||||||
if (worldObj.getBlockState(pos).getBlock() == block) {
|
if (worldObj.getBlockState(pos).getBlock() == block) {
|
||||||
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, true));
|
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
worldObj.notifyNeighborsOfStateChange(pos, block);
|
||||||
|
|
||||||
controller.addMachine(this);
|
controller.addMachine(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDisconnected() {
|
public void onDisconnected() {
|
||||||
connected = false;
|
this.connected = false;
|
||||||
|
|
||||||
if (worldObj.getBlockState(pos).getBlock() == block) {
|
if (worldObj.getBlockState(pos).getBlock() == block) {
|
||||||
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, false));
|
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() {
|
public boolean isConnected() {
|
||||||
|
|||||||
Reference in New Issue
Block a user