Fixes #104 "Solderer dying"
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
# Refined Storage Changelog
|
||||
|
||||
### 0.7.17
|
||||
When updating to this version, you'll have to break and replace your controller.
|
||||
|
||||
**Bugfixes**
|
||||
- Fixed controller not working after leaving chunk
|
||||
- Fixed machines not working when leaving chunk
|
||||
- Rewrote storage networks: they are now saved to disk, so big systems won't lag when rejoining a chunk
|
||||
|
||||
### 0.7.16
|
||||
**Features**
|
||||
- Added support for Storage Drawers void upgrade
|
||||
|
||||
@@ -5,9 +5,6 @@ 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 {
|
||||
/**
|
||||
@@ -15,16 +12,16 @@ public interface INetworkSlave {
|
||||
*/
|
||||
void updateSlave();
|
||||
|
||||
/**
|
||||
* @return If the slave can send a connectivity update (for most slaves this is true, for cables it's false)
|
||||
*/
|
||||
boolean canSendConnectivityUpdate();
|
||||
|
||||
/**
|
||||
* @return The energy usage of this slave
|
||||
*/
|
||||
int getEnergyUsage();
|
||||
|
||||
/**
|
||||
* Responsible for sending connectivity block updates
|
||||
*/
|
||||
void updateConnectivity();
|
||||
|
||||
/**
|
||||
* @return The position of this slave in the world
|
||||
*/
|
||||
|
||||
@@ -6,7 +6,6 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
@@ -54,10 +53,10 @@ public class NetworkMaster {
|
||||
|
||||
private List<IStorage> storages = new ArrayList<IStorage>();
|
||||
|
||||
private List<INetworkSlave> slaves = new ArrayList<INetworkSlave>();
|
||||
private List<INetworkSlave> slavesToAdd = new ArrayList<INetworkSlave>();
|
||||
private List<BlockPos> slaves = new ArrayList<BlockPos>();
|
||||
private List<BlockPos> slavesToAdd = new ArrayList<BlockPos>();
|
||||
private List<BlockPos> slavesToLoad = new ArrayList<BlockPos>();
|
||||
private List<INetworkSlave> slavesToRemove = new ArrayList<INetworkSlave>();
|
||||
private List<BlockPos> slavesToRemove = new ArrayList<BlockPos>();
|
||||
|
||||
private List<CraftingPattern> patterns = new ArrayList<CraftingPattern>();
|
||||
|
||||
@@ -123,7 +122,7 @@ public class NetworkMaster {
|
||||
}
|
||||
|
||||
public void update() {
|
||||
for (INetworkSlave slave : slavesToAdd) {
|
||||
for (BlockPos slave : slavesToAdd) {
|
||||
if (!slaves.contains(slave)) {
|
||||
slaves.add(slave);
|
||||
}
|
||||
@@ -140,12 +139,13 @@ public class NetworkMaster {
|
||||
syncMachines();
|
||||
}
|
||||
|
||||
for (INetworkSlave slave : slaves) {
|
||||
Iterator<INetworkSlave> slaves = getSlaves();
|
||||
while (slaves.hasNext()) {
|
||||
INetworkSlave slave = slaves.next();
|
||||
|
||||
if (slave.canUpdate()) {
|
||||
slave.updateSlave();
|
||||
}
|
||||
|
||||
slave.updateConnectivity();
|
||||
}
|
||||
|
||||
for (ICraftingTask taskToCancel : craftingTasksToCancel) {
|
||||
@@ -210,17 +210,34 @@ public class NetworkMaster {
|
||||
ticks++;
|
||||
}
|
||||
|
||||
public List<INetworkSlave> getSlaves() {
|
||||
return slaves;
|
||||
public Iterator<INetworkSlave> getSlaves() {
|
||||
return new Iterator<INetworkSlave>() {
|
||||
private int index;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return index < slaves.size();
|
||||
}
|
||||
|
||||
public void addSlave(INetworkSlave slave) {
|
||||
@Override
|
||||
public INetworkSlave next() {
|
||||
return world.getTileEntity(slaves.get(index++)).getCapability(RefinedStorageCapabilities.NETWORK_SLAVE_CAPABILITY, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void addSlave(BlockPos slave) {
|
||||
slavesToAdd.add(slave);
|
||||
|
||||
markDirty();
|
||||
}
|
||||
|
||||
public void removeSlave(INetworkSlave slave) {
|
||||
public void removeSlave(BlockPos slave) {
|
||||
slavesToRemove.add(slave);
|
||||
|
||||
markDirty();
|
||||
@@ -239,11 +256,13 @@ public class NetworkMaster {
|
||||
}
|
||||
|
||||
public void disconnectAll() {
|
||||
for (INetworkSlave slave : slaves) {
|
||||
slave.disconnect(world);
|
||||
Iterator<INetworkSlave> slaves = getSlaves();
|
||||
|
||||
while (slaves.hasNext()) {
|
||||
slaves.next().disconnect(world);
|
||||
}
|
||||
|
||||
slaves.clear();
|
||||
this.slaves.clear();
|
||||
}
|
||||
|
||||
public void onRemoved() {
|
||||
@@ -255,16 +274,14 @@ public class NetworkMaster {
|
||||
this.type = (EnumControllerType) world.getBlockState(pos).getValue(BlockController.TYPE);
|
||||
|
||||
for (BlockPos slavePos : slavesToLoad) {
|
||||
TileEntity tile = world.getTileEntity(slavePos);
|
||||
|
||||
if (tile.hasCapability(RefinedStorageCapabilities.NETWORK_SLAVE_CAPABILITY, null)) {
|
||||
INetworkSlave slave = tile.getCapability(RefinedStorageCapabilities.NETWORK_SLAVE_CAPABILITY, null);
|
||||
INetworkSlave slave = world.getTileEntity(slavePos).getCapability(RefinedStorageCapabilities.NETWORK_SLAVE_CAPABILITY, null);
|
||||
|
||||
slave.forceConnect(this);
|
||||
|
||||
slaves.add(slave);
|
||||
}
|
||||
slaves.add(slavePos);
|
||||
}
|
||||
|
||||
this.slavesToLoad.clear();
|
||||
}
|
||||
|
||||
public List<ItemStack> getItems() {
|
||||
@@ -359,7 +376,10 @@ public class NetworkMaster {
|
||||
this.storages.clear();
|
||||
this.patterns.clear();
|
||||
|
||||
for (INetworkSlave slave : slaves) {
|
||||
Iterator<INetworkSlave> slaves = getSlaves();
|
||||
while (slaves.hasNext()) {
|
||||
INetworkSlave slave = slaves.next();
|
||||
|
||||
if (!slave.canUpdate()) {
|
||||
continue;
|
||||
}
|
||||
@@ -621,12 +641,12 @@ public class NetworkMaster {
|
||||
|
||||
NBTTagList slavesTag = new NBTTagList();
|
||||
|
||||
for (INetworkSlave slave : slaves) {
|
||||
for (BlockPos slave : slaves) {
|
||||
NBTTagCompound slaveTag = new NBTTagCompound();
|
||||
|
||||
slaveTag.setInteger(NBT_SLAVE_X, slave.getPosition().getX());
|
||||
slaveTag.setInteger(NBT_SLAVE_Y, slave.getPosition().getY());
|
||||
slaveTag.setInteger(NBT_SLAVE_Z, slave.getPosition().getZ());
|
||||
slaveTag.setInteger(NBT_SLAVE_X, slave.getX());
|
||||
slaveTag.setInteger(NBT_SLAVE_Y, slave.getY());
|
||||
slaveTag.setInteger(NBT_SLAVE_Z, slave.getZ());
|
||||
|
||||
slavesTag.appendTag(slaveTag);
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ public class TileCable extends TileSlave {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateConnectivity() {
|
||||
// NO OP
|
||||
public boolean canSendConnectivityUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,9 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import refinedstorage.RefinedStorageUtils;
|
||||
import refinedstorage.api.RefinedStorageCapabilities;
|
||||
import refinedstorage.api.network.INetworkSlave;
|
||||
import refinedstorage.api.network.NetworkMaster;
|
||||
import refinedstorage.api.network.NetworkMasterRegistry;
|
||||
@@ -37,8 +39,13 @@ public abstract class TileSlave extends TileBase implements ISynchronizedContain
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateConnectivity() {
|
||||
if (wasActive != isActive()) {
|
||||
public boolean canSendConnectivityUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (canSendConnectivityUpdate() && wasActive != isActive()) {
|
||||
wasActive = isActive();
|
||||
|
||||
RefinedStorageUtils.updateBlock(worldObj, pos);
|
||||
@@ -51,7 +58,7 @@ public abstract class TileSlave extends TileBase implements ISynchronizedContain
|
||||
this.network = network;
|
||||
this.connected = true;
|
||||
|
||||
this.network.addSlave(this);
|
||||
this.network.addSlave(pos);
|
||||
|
||||
world.notifyNeighborsOfStateChange(pos, getBlockType());
|
||||
}
|
||||
@@ -68,7 +75,7 @@ public abstract class TileSlave extends TileBase implements ISynchronizedContain
|
||||
this.connected = false;
|
||||
|
||||
if (this.network != null) {
|
||||
this.network.removeSlave(this);
|
||||
this.network.removeSlave(pos);
|
||||
this.network = null;
|
||||
}
|
||||
|
||||
@@ -93,11 +100,13 @@ public abstract class TileSlave extends TileBase implements ISynchronizedContain
|
||||
}
|
||||
|
||||
private TileController searchController(World world, BlockPos current, Set<String> visited) {
|
||||
if (visited.contains(current.getX() + "," + current.getY() + "," + current.getZ())) {
|
||||
String id = current.getX() + "," + current.getY() + "," + current.getZ();
|
||||
|
||||
if (visited.contains(id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
visited.add(current.getX() + "," + current.getY() + "," + current.getZ());
|
||||
visited.add(id);
|
||||
|
||||
TileEntity tile = world.getTileEntity(current);
|
||||
|
||||
@@ -193,20 +202,16 @@ public abstract class TileSlave extends TileBase implements ISynchronizedContain
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == this) {
|
||||
return true;
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (capability == RefinedStorageCapabilities.NETWORK_SLAVE_CAPABILITY) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
if (!(other instanceof TileSlave)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((TileSlave) other).getPos().equals(pos);
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return pos.hashCode();
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
return capability == RefinedStorageCapabilities.NETWORK_SLAVE_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import refinedstorage.tile.config.IRedstoneModeConfig;
|
||||
import refinedstorage.tile.config.RedstoneMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class TileController extends TileBase implements IEnergyReceiver, ISynchronizedContainer, IRedstoneModeConfig {
|
||||
@@ -144,9 +145,12 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
||||
|
||||
buf.writeInt(getNetwork().getRedstoneMode().id);
|
||||
|
||||
List<ClientSlave> slaves = new ArrayList<ClientSlave>();
|
||||
List<ClientSlave> clientSlaves = new ArrayList<ClientSlave>();
|
||||
|
||||
Iterator<INetworkSlave> slaves = getNetwork().getSlaves();
|
||||
while (slaves.hasNext()) {
|
||||
INetworkSlave slave = slaves.next();
|
||||
|
||||
for (INetworkSlave slave : getNetwork().getSlaves()) {
|
||||
if (slave.canUpdate()) {
|
||||
IBlockState state = worldObj.getBlockState(slave.getPosition());
|
||||
|
||||
@@ -156,22 +160,22 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
||||
clientSlave.amount = 1;
|
||||
clientSlave.stack = new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state));
|
||||
|
||||
if (slaves.contains(clientSlave)) {
|
||||
for (ClientSlave other : slaves) {
|
||||
if (clientSlaves.contains(clientSlave)) {
|
||||
for (ClientSlave other : clientSlaves) {
|
||||
if (other.equals(clientSlave)) {
|
||||
other.amount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
slaves.add(clientSlave);
|
||||
clientSlaves.add(clientSlave);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buf.writeInt(slaves.size());
|
||||
buf.writeInt(clientSlaves.size());
|
||||
|
||||
for (ClientSlave slave : slaves) {
|
||||
for (ClientSlave slave : clientSlaves) {
|
||||
buf.writeInt(slave.energyUsage);
|
||||
buf.writeInt(slave.amount);
|
||||
ByteBufUtils.writeItemStack(buf, slave.stack);
|
||||
|
||||
Reference in New Issue
Block a user