Fixed storage block voiding and markDirty on removal of node

This commit is contained in:
raoulvdberge
2017-02-06 22:02:33 +01:00
parent 9c70e7d668
commit da591ee386
12 changed files with 81 additions and 62 deletions

View File

@@ -1,6 +1,7 @@
package com.raoulvdberge.refinedstorage.api.network.node; package com.raoulvdberge.refinedstorage.api.network.node;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
@@ -42,4 +43,11 @@ public interface INetworkNodeManager {
* Clears all the nodes. * Clears all the nodes.
*/ */
void clear(); void clear();
/**
* Marks the nodes dirty.
*
* @param world the world
*/
void markDirty(World world);
} }

View File

@@ -2,7 +2,9 @@ package com.raoulvdberge.refinedstorage.apiimpl.network;
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode; import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager; import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.WorldSavedDataNetworkNode;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
@@ -37,4 +39,9 @@ public class NetworkNodeManager implements INetworkNodeManager {
public void clear() { public void clear() {
nodes.clear(); nodes.clear();
} }
@Override
public void markDirty(World world) {
WorldSavedDataNetworkNode.get(world).markDirty();
}
} }

View File

@@ -5,6 +5,7 @@ import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
import com.raoulvdberge.refinedstorage.api.network.INetworkNeighborhoodAware; import com.raoulvdberge.refinedstorage.api.network.INetworkNeighborhoodAware;
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode; import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
import com.raoulvdberge.refinedstorage.api.util.IWrenchable; import com.raoulvdberge.refinedstorage.api.util.IWrenchable;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.tile.config.RedstoneMode; import com.raoulvdberge.refinedstorage.tile.config.RedstoneMode;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@@ -84,7 +85,7 @@ public abstract class NetworkNode implements INetworkNode, INetworkNeighborhoodA
@Override @Override
public void markDirty() { public void markDirty() {
if (holder.world() != null) { if (holder.world() != null) {
WorldSavedDataNetworkNode.get(holder.world()).markDirty(); API.instance().getNetworkNodeManager(holder.world().provider.getDimension()).markDirty(holder.world());
} }
} }

View File

@@ -28,8 +28,8 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage,
public static final String ID = "fluid_storage"; public static final String ID = "fluid_storage";
class StorageFluid extends StorageDiskFluid { class StorageFluid extends StorageDiskFluid {
public StorageFluid() { public StorageFluid(NBTTagCompound tag) {
super(NetworkNodeFluidStorage.this.getStorageTag(), NetworkNodeFluidStorage.this.getCapacity()); super(tag, NetworkNodeFluidStorage.this.getCapacity());
} }
@Override @Override
@@ -74,9 +74,8 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage,
private ItemHandlerFluid filters = new ItemHandlerFluid(9, new ItemHandlerListenerNetworkNode(this)); private ItemHandlerFluid filters = new ItemHandlerFluid(9, new ItemHandlerListenerNetworkNode(this));
private NBTTagCompound storageTag = StorageDiskFluid.getTag(); private StorageFluid storage = new StorageFluid(StorageDiskFluid.getTag());
private NBTTagCompound storageTagToRead;
private StorageFluid storage;
private EnumFluidStorageType type; private EnumFluidStorageType type;
@@ -99,15 +98,23 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage,
public void update() { public void update() {
super.update(); super.update();
if (storage == null && storageTag != null) { if (storageTagToRead != null) {
storage = new StorageFluid(); storage = new StorageFluid(storageTagToRead);
storage.readFromNBT();
if (network != null) { if (network != null) {
network.getFluidStorageCache().invalidate(); network.getFluidStorageCache().invalidate();
} }
storageTagToRead = null;
} }
} }
public void onPlacedWithStorage(NBTTagCompound tag) {
storageTagToRead = tag;
}
public void onBreak() { public void onBreak() {
if (storage != null) { if (storage != null) {
storage.writeToNBT(); storage.writeToNBT();
@@ -138,7 +145,7 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage,
super.read(tag); super.read(tag);
if (tag.hasKey(NBT_STORAGE)) { if (tag.hasKey(NBT_STORAGE)) {
storageTag = tag.getCompoundTag(NBT_STORAGE); storageTagToRead = tag.getCompoundTag(NBT_STORAGE);
} }
} }
@@ -151,11 +158,9 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage,
public NBTTagCompound write(NBTTagCompound tag) { public NBTTagCompound write(NBTTagCompound tag) {
super.write(tag); super.write(tag);
if (storage != null) { storage.writeToNBT();
storage.writeToNBT();
}
tag.setTag(NBT_STORAGE, storageTag); tag.setTag(NBT_STORAGE, storage.getStorageTag());
return tag; return tag;
} }
@@ -202,7 +207,7 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage,
} }
public EnumFluidStorageType getType() { public EnumFluidStorageType getType() {
if (type == null && holder.world().getBlockState(holder.pos()).getBlock() == RSBlocks.FLUID_STORAGE) { if (type == null && holder.world() != null && holder.world().getBlockState(holder.pos()).getBlock() == RSBlocks.FLUID_STORAGE) {
type = (EnumFluidStorageType) holder.world().getBlockState(holder.pos()).getValue(BlockFluidStorage.TYPE); type = (EnumFluidStorageType) holder.world().getBlockState(holder.pos()).getValue(BlockFluidStorage.TYPE);
} }
@@ -233,14 +238,6 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage,
markDirty(); markDirty();
} }
public NBTTagCompound getStorageTag() {
return storageTag;
}
public void setStorageTag(NBTTagCompound storageTag) {
this.storageTag = storageTag;
}
public StorageDiskFluid getStorage() { public StorageDiskFluid getStorage() {
return storage; return storage;
} }

View File

@@ -28,8 +28,8 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
public static final String ID = "storage"; public static final String ID = "storage";
class StorageItem extends StorageDiskItem { class StorageItem extends StorageDiskItem {
public StorageItem() { public StorageItem(NBTTagCompound tag) {
super(NetworkNodeStorage.this.getStorageTag(), NetworkNodeStorage.this.getCapacity()); super(tag, NetworkNodeStorage.this.getCapacity());
} }
@Override @Override
@@ -73,9 +73,8 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
private ItemHandlerBasic filters = new ItemHandlerBasic(9, new ItemHandlerListenerNetworkNode(this)); private ItemHandlerBasic filters = new ItemHandlerBasic(9, new ItemHandlerListenerNetworkNode(this));
private NBTTagCompound storageTag = StorageDiskItem.getTag(); private StorageItem storage = new StorageItem(StorageDiskItem.getTag());
private NBTTagCompound storageTagToRead = null;
private StorageItem storage;
private EnumItemStorageType type; private EnumItemStorageType type;
@@ -89,28 +88,34 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
super(holder); super(holder);
} }
@Override
public int getEnergyUsage() {
return RS.INSTANCE.config.storageUsage;
}
@Override @Override
public void update() { public void update() {
super.update(); super.update();
if (storage == null && storageTag != null) { if (storageTagToRead != null) {
storage = new StorageItem(); storage = new StorageItem(storageTagToRead);
storage.readFromNBT();
if (network != null) { if (network != null) {
network.getItemStorageCache().invalidate(); network.getItemStorageCache().invalidate();
} }
storageTagToRead = null;
} }
} }
public void onPlacedWithStorage(NBTTagCompound tag) {
storageTagToRead = tag;
}
@Override
public int getEnergyUsage() {
return RS.INSTANCE.config.storageUsage;
}
public void onBreak() { public void onBreak() {
if (storage != null) { storage.writeToNBT();
storage.writeToNBT();
}
} }
@Override @Override
@@ -122,9 +127,7 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
@Override @Override
public void addItemStorages(List<IStorage<ItemStack>> storages) { public void addItemStorages(List<IStorage<ItemStack>> storages) {
if (storage != null) { storages.add(storage);
storages.add(storage);
}
} }
@Override @Override
@@ -137,7 +140,7 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
super.read(tag); super.read(tag);
if (tag.hasKey(NBT_STORAGE)) { if (tag.hasKey(NBT_STORAGE)) {
storageTag = tag.getCompoundTag(NBT_STORAGE); storageTagToRead = tag.getCompoundTag(NBT_STORAGE);
} }
} }
@@ -150,11 +153,9 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
public NBTTagCompound write(NBTTagCompound tag) { public NBTTagCompound write(NBTTagCompound tag) {
super.write(tag); super.write(tag);
if (storage != null) { storage.writeToNBT();
storage.writeToNBT();
}
tag.setTag(NBT_STORAGE, storageTag); tag.setTag(NBT_STORAGE, storage.getStorageTag());
return tag; return tag;
} }
@@ -201,7 +202,7 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
} }
public EnumItemStorageType getType() { public EnumItemStorageType getType() {
if (type == null && holder.world().getBlockState(holder.pos()).getBlock() == RSBlocks.STORAGE) { if (type == null && holder.world() != null && holder.world().getBlockState(holder.pos()).getBlock() == RSBlocks.STORAGE) {
type = (EnumItemStorageType) holder.world().getBlockState(holder.pos()).getValue(BlockStorage.TYPE); type = (EnumItemStorageType) holder.world().getBlockState(holder.pos()).getValue(BlockStorage.TYPE);
} }
@@ -244,14 +245,6 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
markDirty(); markDirty();
} }
public NBTTagCompound getStorageTag() {
return storageTag;
}
public void setStorageTag(NBTTagCompound storageTag) {
this.storageTag = storageTag;
}
public StorageDiskItem getStorage() { public StorageDiskItem getStorage() {
return storage; return storage;
} }

View File

@@ -32,6 +32,10 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
this.capacity = capacity; this.capacity = capacity;
} }
public NBTTagCompound getStorageTag() {
return tag;
}
@Override @Override
public void readFromNBT() { public void readFromNBT() {
NBTTagList list = (NBTTagList) tag.getTag(NBT_FLUIDS); NBTTagList list = (NBTTagList) tag.getTag(NBT_FLUIDS);

View File

@@ -46,6 +46,10 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
this.capacity = capacity; this.capacity = capacity;
} }
public NBTTagCompound getStorageTag() {
return tag;
}
@Override @Override
public void readFromNBT() { public void readFromNBT() {
NBTTagList list = (NBTTagList) tag.getTag(NBT_ITEMS); NBTTagList list = (NBTTagList) tag.getTag(NBT_ITEMS);

View File

@@ -77,7 +77,7 @@ public class BlockFluidStorage extends BlockNode {
super.onBlockPlacedBy(world, pos, state, player, stack); super.onBlockPlacedBy(world, pos, state, player, stack);
if (!world.isRemote && stack.hasTagCompound() && stack.getTagCompound().hasKey(NetworkNodeFluidStorage.NBT_STORAGE)) { if (!world.isRemote && stack.hasTagCompound() && stack.getTagCompound().hasKey(NetworkNodeFluidStorage.NBT_STORAGE)) {
((TileFluidStorage) world.getTileEntity(pos)).getNode().setStorageTag(stack.getTagCompound().getCompoundTag(NetworkNodeFluidStorage.NBT_STORAGE)); ((TileFluidStorage) world.getTileEntity(pos)).getNode().onPlacedWithStorage(stack.getTagCompound().getCompoundTag(NetworkNodeFluidStorage.NBT_STORAGE));
} }
} }
@@ -96,7 +96,10 @@ public class BlockFluidStorage extends BlockNode {
ItemStack stack = new ItemStack(RSBlocks.FLUID_STORAGE, 1, getMetaFromState(state)); ItemStack stack = new ItemStack(RSBlocks.FLUID_STORAGE, 1, getMetaFromState(state));
stack.setTagCompound(new NBTTagCompound()); stack.setTagCompound(new NBTTagCompound());
stack.getTagCompound().setTag(NetworkNodeFluidStorage.NBT_STORAGE, ((TileFluidStorage) world.getTileEntity(pos)).getNode().getStorageTag());
storage.getNode().getStorage().writeToNBT();
stack.getTagCompound().setTag(NetworkNodeFluidStorage.NBT_STORAGE, storage.getNode().getStorage().getStorageTag());
drops.add(stack); drops.add(stack);

View File

@@ -57,6 +57,7 @@ public abstract class BlockNode extends BlockBase {
INetworkNode node = manager.getNode(pos); INetworkNode node = manager.getNode(pos);
manager.removeNode(pos); manager.removeNode(pos);
manager.markDirty(world);
if (node.getNetwork() != null) { if (node.getNetwork() != null) {
node.getNetwork().getNodeGraph().rebuild(); node.getNetwork().getNodeGraph().rebuild();

View File

@@ -77,7 +77,7 @@ public class BlockStorage extends BlockNode {
super.onBlockPlacedBy(world, pos, state, player, stack); super.onBlockPlacedBy(world, pos, state, player, stack);
if (!world.isRemote && stack.hasTagCompound() && stack.getTagCompound().hasKey(NetworkNodeStorage.NBT_STORAGE)) { if (!world.isRemote && stack.hasTagCompound() && stack.getTagCompound().hasKey(NetworkNodeStorage.NBT_STORAGE)) {
((TileStorage) world.getTileEntity(pos)).getNode().setStorageTag(stack.getTagCompound().getCompoundTag(NetworkNodeStorage.NBT_STORAGE)); ((TileStorage) world.getTileEntity(pos)).getNode().onPlacedWithStorage(stack.getTagCompound().getCompoundTag(NetworkNodeStorage.NBT_STORAGE));
} }
} }
@@ -96,7 +96,10 @@ public class BlockStorage extends BlockNode {
ItemStack stack = new ItemStack(RSBlocks.STORAGE, 1, getMetaFromState(state)); ItemStack stack = new ItemStack(RSBlocks.STORAGE, 1, getMetaFromState(state));
stack.setTagCompound(new NBTTagCompound()); stack.setTagCompound(new NBTTagCompound());
stack.getTagCompound().setTag(NetworkNodeStorage.NBT_STORAGE, ((TileStorage) world.getTileEntity(pos)).getNode().getStorageTag());
storage.getNode().getStorage().writeToNBT();
stack.getTagCompound().setTag(NetworkNodeStorage.NBT_STORAGE, storage.getNode().getStorage().getStorageTag());
drops.add(stack); drops.add(stack);

View File

@@ -2,7 +2,6 @@ package com.raoulvdberge.refinedstorage.tile;
import com.raoulvdberge.refinedstorage.api.storage.AccessType; import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeFluidStorage; import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeFluidStorage;
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskFluid;
import com.raoulvdberge.refinedstorage.tile.config.*; import com.raoulvdberge.refinedstorage.tile.config.*;
import com.raoulvdberge.refinedstorage.tile.data.ITileDataProducer; import com.raoulvdberge.refinedstorage.tile.data.ITileDataProducer;
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter; import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
@@ -19,7 +18,7 @@ public class TileFluidStorage extends TileNode<NetworkNodeFluidStorage> {
public static final TileDataParameter<Integer> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, new ITileDataProducer<Integer, TileFluidStorage>() { public static final TileDataParameter<Integer> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, new ITileDataProducer<Integer, TileFluidStorage>() {
@Override @Override
public Integer getValue(TileFluidStorage tile) { public Integer getValue(TileFluidStorage tile) {
return StorageDiskFluid.getStored(tile.getNode().getStorageTag()); return tile.getNode().getStorage().getStored();
} }
}); });

View File

@@ -2,7 +2,6 @@ package com.raoulvdberge.refinedstorage.tile;
import com.raoulvdberge.refinedstorage.api.storage.AccessType; import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeStorage; import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeStorage;
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskItem;
import com.raoulvdberge.refinedstorage.tile.config.*; import com.raoulvdberge.refinedstorage.tile.config.*;
import com.raoulvdberge.refinedstorage.tile.data.ITileDataProducer; import com.raoulvdberge.refinedstorage.tile.data.ITileDataProducer;
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter; import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
@@ -18,7 +17,7 @@ public class TileStorage extends TileNode<NetworkNodeStorage> {
public static final TileDataParameter<Integer> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, new ITileDataProducer<Integer, TileStorage>() { public static final TileDataParameter<Integer> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, new ITileDataProducer<Integer, TileStorage>() {
@Override @Override
public Integer getValue(TileStorage tile) { public Integer getValue(TileStorage tile) {
return StorageDiskItem.getStored(tile.getNode().getStorageTag()); return tile.getNode().getStorage().getStored();
} }
}); });
public static final TileDataParameter<Boolean> VOID_EXCESS = IExcessVoidable.createParameter(); public static final TileDataParameter<Boolean> VOID_EXCESS = IExcessVoidable.createParameter();