More fixes
This commit is contained in:
@@ -5,6 +5,9 @@ import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* Represents a slave or machine in the storage network.
|
||||
*
|
||||
* Make sure you implement {@link Object#hashCode()} or the slave will not get properly removed or added by the storage master.
|
||||
* Typically the hash code from {@link INetworkSlave#getPosition()} is used.
|
||||
*/
|
||||
public interface INetworkSlave {
|
||||
/**
|
||||
@@ -18,9 +21,9 @@ public interface INetworkSlave {
|
||||
int getEnergyUsage();
|
||||
|
||||
/**
|
||||
* @return If this slave can send connectivity updates and can trigger block updates
|
||||
* Responsible for sending connectivity block updates
|
||||
*/
|
||||
boolean canSendConnectivityUpdate();
|
||||
void updateConnectivity();
|
||||
|
||||
/**
|
||||
* @return The position of this slave in the world
|
||||
@@ -28,14 +31,14 @@ public interface INetworkSlave {
|
||||
BlockPos getPosition();
|
||||
|
||||
/**
|
||||
* Called when the neighbor of this slave is changed. Typically used to recalculate the network (if there is still a connection)
|
||||
* Called when the neighbor of this slave is changed. Typically used to check if there is still a connection to the network.
|
||||
*
|
||||
* @param world The world
|
||||
*/
|
||||
void onNeighborChanged(World world);
|
||||
|
||||
/**
|
||||
* Called when a connection is found to the storage network
|
||||
* Called when a connection is found to the network
|
||||
*
|
||||
* @param world The world
|
||||
* @param network The network we're trying to connect to
|
||||
@@ -50,7 +53,7 @@ public interface INetworkSlave {
|
||||
void forceConnect(NetworkMaster network);
|
||||
|
||||
/**
|
||||
* Called when a connection is lost to the stoarge network
|
||||
* Called when a connection is lost to the network
|
||||
*
|
||||
* @param world The world
|
||||
*/
|
||||
@@ -62,7 +65,7 @@ public interface INetworkSlave {
|
||||
boolean isConnected();
|
||||
|
||||
/**
|
||||
* @return If this slave can be updated. Typically returns false when redstone mode doesn't allow it.
|
||||
* @return If {@link INetworkSlave#canUpdate()} can get called. Typically checks for connection and redstone mode.
|
||||
*/
|
||||
boolean canUpdate();
|
||||
|
||||
|
||||
@@ -120,21 +120,13 @@ public class NetworkMaster {
|
||||
|
||||
public void update() {
|
||||
for (INetworkSlave slave : slavesToAdd) {
|
||||
slaves.add(slave);
|
||||
if (!slaves.contains(slave)) {
|
||||
slaves.add(slave);
|
||||
}
|
||||
}
|
||||
slavesToAdd.clear();
|
||||
|
||||
for (INetworkSlave slave : slavesToRemove) {
|
||||
Iterator<INetworkSlave> otherSlave = slaves.iterator();
|
||||
|
||||
while (otherSlave.hasNext()) {
|
||||
if (otherSlave.next().getPosition().equals(slave.getPosition())) {
|
||||
otherSlave.remove();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
slaves.removeAll(slavesToRemove);
|
||||
slavesToRemove.clear();
|
||||
|
||||
int lastEnergy = energy.getEnergyStored();
|
||||
@@ -148,6 +140,8 @@ public class NetworkMaster {
|
||||
if (slave.canUpdate()) {
|
||||
slave.updateSlave();
|
||||
}
|
||||
|
||||
slave.updateConnectivity();
|
||||
}
|
||||
|
||||
for (ICraftingTask taskToCancel : craftingTasksToCancel) {
|
||||
|
||||
@@ -50,10 +50,10 @@ public abstract class BlockSlave extends BlockBase {
|
||||
@Override
|
||||
public void breakBlock(World world, BlockPos pos, IBlockState state) {
|
||||
if (!world.isRemote) {
|
||||
TileSlave machine = (TileSlave) world.getTileEntity(pos);
|
||||
TileSlave slave = (TileSlave) world.getTileEntity(pos);
|
||||
|
||||
if (machine.isConnected()) {
|
||||
machine.disconnect(world);
|
||||
if (slave.isConnected()) {
|
||||
slave.disconnect(world);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,11 +10,12 @@ public class TileCable extends TileSlave {
|
||||
|
||||
@Override
|
||||
public void updateSlave() {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSendConnectivityUpdate() {
|
||||
return false;
|
||||
public void updateConnectivity() {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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 net.minecraft.world.World;
|
||||
@@ -21,36 +20,12 @@ public abstract class TileSlave extends TileBase implements ISynchronizedContain
|
||||
public static final String NBT_CONNECTED = "Connected";
|
||||
|
||||
protected boolean connected;
|
||||
protected boolean wasConnected;
|
||||
protected RedstoneMode redstoneMode = RedstoneMode.IGNORE;
|
||||
protected NetworkMaster network;
|
||||
|
||||
private Block block;
|
||||
|
||||
private boolean wasActive;
|
||||
private Set<String> visited = new HashSet<String>();
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (!worldObj.isRemote) {
|
||||
if (ticks == 0) {
|
||||
block = worldObj.getBlockState(pos).getBlock();
|
||||
}
|
||||
|
||||
if (wasConnected != isActive() && canSendConnectivityUpdate()) {
|
||||
wasConnected = isActive();
|
||||
|
||||
RefinedStorageUtils.updateBlock(worldObj, pos);
|
||||
}
|
||||
}
|
||||
|
||||
super.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSendConnectivityUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate() {
|
||||
return redstoneMode.isEnabled(worldObj, pos);
|
||||
@@ -60,15 +35,24 @@ public abstract class TileSlave extends TileBase implements ISynchronizedContain
|
||||
return isConnected() && canUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateConnectivity() {
|
||||
if (wasActive != isActive()) {
|
||||
wasActive = isActive();
|
||||
|
||||
RefinedStorageUtils.updateBlock(worldObj, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(World world, NetworkMaster network) {
|
||||
if (block != null && this.network.canRun()) {
|
||||
if (network.canRun()) {
|
||||
this.network = network;
|
||||
this.connected = true;
|
||||
|
||||
this.network.addSlave(this);
|
||||
|
||||
world.notifyNeighborsOfStateChange(pos, block);
|
||||
world.notifyNeighborsOfStateChange(pos, getBlockType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +71,7 @@ public abstract class TileSlave extends TileBase implements ISynchronizedContain
|
||||
this.network = null;
|
||||
}
|
||||
|
||||
world.notifyNeighborsOfStateChange(pos, block);
|
||||
world.notifyNeighborsOfStateChange(pos, getBlockType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user