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