Fixes to world saved data impl, mark *actually* drives dirty
This commit is contained in:
@@ -28,9 +28,11 @@ public interface IStorageDisk<T> extends IStorage<T> {
|
||||
boolean isValid(ItemStack stack);
|
||||
|
||||
/**
|
||||
* Called when the storage changes.
|
||||
* Sets a listener that is called when the storage changes.
|
||||
*
|
||||
* @param listener the listener
|
||||
*/
|
||||
void onChanged();
|
||||
void setListener(Runnable listener);
|
||||
|
||||
/**
|
||||
* Reads the storage from NBT.
|
||||
|
||||
@@ -54,18 +54,11 @@ public class NetworkNodeListener {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWorldSave(WorldEvent.Save e) {
|
||||
WorldSavedDataNetworkNode.get(e.getWorld());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWorldLoad(WorldEvent.Load e) {
|
||||
WorldSavedDataNetworkNode.get(e.getWorld());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWorldUnload(WorldEvent.Unload e) {
|
||||
// Clear all data from a possible previous load, so we start with a clean slate
|
||||
API.instance().getNetworkNodeManager(e.getWorld().provider.getDimension()).clear();
|
||||
|
||||
WorldSavedDataNetworkNode.getOrLoadData(e.getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,6 @@ public class NetworkNodeManager implements INetworkNodeManager {
|
||||
|
||||
@Override
|
||||
public void markDirty(World world) {
|
||||
WorldSavedDataNetworkNode.get(world).markDirty();
|
||||
WorldSavedDataNetworkNode.getOrLoadData(world).markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage,
|
||||
class StorageFluid extends StorageDiskFluid {
|
||||
public StorageFluid(NBTTagCompound tag) {
|
||||
super(tag, NetworkNodeFluidStorage.this.getCapacity());
|
||||
|
||||
this.setListener(NetworkNodeFluidStorage.this::markDirty);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,13 +58,6 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage,
|
||||
public boolean isVoiding() {
|
||||
return voidExcess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
super.onChanged();
|
||||
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public static final String NBT_STORAGE = "Storage";
|
||||
|
||||
@@ -30,6 +30,8 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
|
||||
class StorageItem extends StorageDiskItem {
|
||||
public StorageItem(NBTTagCompound tag) {
|
||||
super(tag, NetworkNodeStorage.this.getCapacity());
|
||||
|
||||
this.setListener(NetworkNodeStorage.this::markDirty);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,13 +57,6 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
|
||||
public boolean isVoiding() {
|
||||
return voidExcess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
super.onChanged();
|
||||
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public static final String NBT_STORAGE = "Storage";
|
||||
|
||||
@@ -77,7 +77,7 @@ public class WorldSavedDataNetworkNode extends WorldSavedData {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static WorldSavedDataNetworkNode get(World world) {
|
||||
public static WorldSavedDataNetworkNode getOrLoadData(World world) {
|
||||
MapStorage storage = world.getPerWorldStorage();
|
||||
WorldSavedDataNetworkNode instance = (WorldSavedDataNetworkNode) storage.getOrLoadData(WorldSavedDataNetworkNode.class, NAME);
|
||||
|
||||
|
||||
@@ -21,6 +21,17 @@ public class StorageFluidDiskDrive implements IStorageDisk<FluidStack> {
|
||||
public StorageFluidDiskDrive(NetworkNodeDiskDrive diskDrive, IStorageDisk<FluidStack> parent) {
|
||||
this.diskDrive = diskDrive;
|
||||
this.parent = parent;
|
||||
this.parent.setListener(() -> {
|
||||
diskDrive.markDirty();
|
||||
|
||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
|
||||
if (lastState != currentState) {
|
||||
lastState = currentState;
|
||||
|
||||
RSUtils.updateBlock(diskDrive.getHolder().world(), diskDrive.getHolder().pos());
|
||||
}
|
||||
});
|
||||
this.lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
}
|
||||
|
||||
@@ -81,18 +92,8 @@ public class StorageFluidDiskDrive implements IStorageDisk<FluidStack> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
parent.onChanged();
|
||||
|
||||
diskDrive.markDirty();
|
||||
|
||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
|
||||
if (lastState != currentState) {
|
||||
lastState = currentState;
|
||||
|
||||
RSUtils.updateBlock(diskDrive.getHolder().world(), diskDrive.getHolder().pos());
|
||||
}
|
||||
public void setListener(Runnable listener) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,6 +21,17 @@ public class StorageItemDiskDrive implements IStorageDisk<ItemStack> {
|
||||
public StorageItemDiskDrive(NetworkNodeDiskDrive diskDrive, IStorageDisk<ItemStack> parent) {
|
||||
this.diskDrive = diskDrive;
|
||||
this.parent = parent;
|
||||
this.parent.setListener(() -> {
|
||||
diskDrive.markDirty();
|
||||
|
||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
|
||||
if (lastState != currentState) {
|
||||
lastState = currentState;
|
||||
|
||||
RSUtils.updateBlock(diskDrive.getHolder().world(), diskDrive.getHolder().pos());
|
||||
}
|
||||
});
|
||||
this.lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
}
|
||||
|
||||
@@ -81,18 +92,8 @@ public class StorageItemDiskDrive implements IStorageDisk<ItemStack> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
parent.onChanged();
|
||||
|
||||
diskDrive.markDirty();
|
||||
|
||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
|
||||
if (lastState != currentState) {
|
||||
lastState = currentState;
|
||||
|
||||
RSUtils.updateBlock(diskDrive.getHolder().world(), diskDrive.getHolder().pos());
|
||||
}
|
||||
public void setListener(Runnable listener) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,6 +20,17 @@ public class StorageFluidDiskManipulator implements IStorageDisk<FluidStack> {
|
||||
public StorageFluidDiskManipulator(NetworkNodeDiskManipulator diskManipulator, IStorageDisk<FluidStack> parent) {
|
||||
this.diskManipulator = diskManipulator;
|
||||
this.parent = parent;
|
||||
this.parent.setListener(() -> {
|
||||
diskManipulator.markDirty();
|
||||
|
||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
|
||||
if (lastState != currentState) {
|
||||
lastState = currentState;
|
||||
|
||||
RSUtils.updateBlock(diskManipulator.getHolder().world(), diskManipulator.getHolder().pos());
|
||||
}
|
||||
});
|
||||
this.lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
}
|
||||
|
||||
@@ -39,18 +50,8 @@ public class StorageFluidDiskManipulator implements IStorageDisk<FluidStack> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
parent.onChanged();
|
||||
|
||||
diskManipulator.markDirty();
|
||||
|
||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
|
||||
if (lastState != currentState) {
|
||||
lastState = currentState;
|
||||
|
||||
RSUtils.updateBlock(diskManipulator.getHolder().world(), diskManipulator.getHolder().pos());
|
||||
}
|
||||
public void setListener(Runnable listener) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,6 +20,17 @@ public class StorageItemDiskManipulator implements IStorageDisk<ItemStack> {
|
||||
public StorageItemDiskManipulator(NetworkNodeDiskManipulator diskManipulator, IStorageDisk<ItemStack> parent) {
|
||||
this.diskManipulator = diskManipulator;
|
||||
this.parent = parent;
|
||||
this.parent.setListener(() -> {
|
||||
diskManipulator.markDirty();
|
||||
|
||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
|
||||
if (lastState != currentState) {
|
||||
lastState = currentState;
|
||||
|
||||
RSUtils.updateBlock(diskManipulator.getHolder().world(), diskManipulator.getHolder().pos());
|
||||
}
|
||||
});
|
||||
this.lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
}
|
||||
|
||||
@@ -39,18 +50,8 @@ public class StorageItemDiskManipulator implements IStorageDisk<ItemStack> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
parent.onChanged();
|
||||
|
||||
diskManipulator.markDirty();
|
||||
|
||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
|
||||
if (lastState != currentState) {
|
||||
lastState = currentState;
|
||||
|
||||
RSUtils.updateBlock(diskManipulator.getHolder().world(), diskManipulator.getHolder().pos());
|
||||
}
|
||||
public void setListener(Runnable listener) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,6 +27,9 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||
|
||||
private NonNullList<FluidStack> stacks = NonNullList.create();
|
||||
|
||||
private Runnable listener = () -> {
|
||||
};
|
||||
|
||||
public StorageDiskFluid(NBTTagCompound tag, int capacity) {
|
||||
this.tag = tag;
|
||||
this.capacity = capacity;
|
||||
@@ -92,7 +95,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||
|
||||
otherStack.amount += remainingSpace;
|
||||
|
||||
onChanged();
|
||||
listener.run();
|
||||
}
|
||||
|
||||
return isVoiding() ? null : RSUtils.copyStackWithSize(otherStack, size - remainingSpace);
|
||||
@@ -102,7 +105,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||
|
||||
otherStack.amount += size;
|
||||
|
||||
onChanged();
|
||||
listener.run();
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -126,7 +129,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||
|
||||
stacks.add(RSUtils.copyStackWithSize(stack, remainingSpace));
|
||||
|
||||
onChanged();
|
||||
listener.run();
|
||||
}
|
||||
|
||||
return isVoiding() ? null : RSUtils.copyStackWithSize(stack, size - remainingSpace);
|
||||
@@ -136,7 +139,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||
|
||||
stacks.add(RSUtils.copyStackWithSize(stack, size));
|
||||
|
||||
onChanged();
|
||||
listener.run();
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -161,7 +164,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||
|
||||
tag.setInteger(NBT_STORED, getStored() - size);
|
||||
|
||||
onChanged();
|
||||
listener.run();
|
||||
}
|
||||
|
||||
return RSUtils.copyStackWithSize(otherStack, size);
|
||||
@@ -171,11 +174,6 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored() {
|
||||
return getStored(tag);
|
||||
@@ -216,6 +214,11 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_FLUIDS) && stack.getTagCompound().hasKey(NBT_STORED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setListener(Runnable listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public static NBTTagCompound getShareTag(NBTTagCompound tag) {
|
||||
NBTTagCompound otherTag = new NBTTagCompound();
|
||||
|
||||
|
||||
@@ -35,6 +35,9 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
private NBTTagCompound tag;
|
||||
private int capacity;
|
||||
|
||||
private Runnable listener = () -> {
|
||||
};
|
||||
|
||||
private NonNullList<ItemStack> stacks = NonNullList.create();
|
||||
|
||||
/**
|
||||
@@ -136,7 +139,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
|
||||
otherStack.grow(remainingSpace);
|
||||
|
||||
onChanged();
|
||||
listener.run();
|
||||
}
|
||||
|
||||
return isVoiding() ? null : ItemHandlerHelper.copyStackWithSize(otherStack, size - remainingSpace);
|
||||
@@ -146,7 +149,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
|
||||
otherStack.grow(size);
|
||||
|
||||
onChanged();
|
||||
listener.run();
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -170,7 +173,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
|
||||
stacks.add(ItemHandlerHelper.copyStackWithSize(stack, remainingSpace));
|
||||
|
||||
onChanged();
|
||||
listener.run();
|
||||
}
|
||||
|
||||
return isVoiding() ? null : ItemHandlerHelper.copyStackWithSize(stack, size - remainingSpace);
|
||||
@@ -180,7 +183,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
|
||||
stacks.add(ItemHandlerHelper.copyStackWithSize(stack, size));
|
||||
|
||||
onChanged();
|
||||
listener.run();
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -205,7 +208,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
|
||||
tag.setInteger(NBT_STORED, getStored() - size);
|
||||
|
||||
onChanged();
|
||||
listener.run();
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(otherStack, size);
|
||||
@@ -236,13 +239,13 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
// NO OP
|
||||
public boolean isValid(ItemStack stack) {
|
||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_ITEMS) && stack.getTagCompound().hasKey(NBT_STORED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(ItemStack stack) {
|
||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_ITEMS) && stack.getTagCompound().hasKey(NBT_STORED);
|
||||
public void setListener(Runnable listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user