Fixes #908
This commit is contained in:
@@ -15,11 +15,17 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||
private static final int PROTOCOL = 1;
|
||||
/**
|
||||
* Protocol history:
|
||||
* - 1: Initial
|
||||
* - 2: Removed "stored" tag
|
||||
*/
|
||||
private static final int PROTOCOL = 2;
|
||||
|
||||
private static final String NBT_PROTOCOL = "Protocol";
|
||||
|
||||
private static final String NBT_FLUIDS = "Fluids";
|
||||
// Used client side
|
||||
private static final String NBT_STORED = "Stored";
|
||||
|
||||
private NBTTagCompound tag;
|
||||
@@ -84,8 +90,6 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||
}
|
||||
|
||||
if (!simulate) {
|
||||
tag.setInteger(NBT_STORED, getStored() + remainingSpace);
|
||||
|
||||
otherStack.amount += remainingSpace;
|
||||
|
||||
onChanged();
|
||||
@@ -94,8 +98,6 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||
return isVoiding() ? null : RSUtils.copyStackWithSize(otherStack, size - remainingSpace);
|
||||
} else {
|
||||
if (!simulate) {
|
||||
tag.setInteger(NBT_STORED, getStored() + size);
|
||||
|
||||
otherStack.amount += size;
|
||||
|
||||
onChanged();
|
||||
@@ -118,8 +120,6 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||
}
|
||||
|
||||
if (!simulate) {
|
||||
tag.setInteger(NBT_STORED, getStored() + remainingSpace);
|
||||
|
||||
stacks.add(RSUtils.copyStackWithSize(stack, remainingSpace));
|
||||
|
||||
onChanged();
|
||||
@@ -128,8 +128,6 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||
return isVoiding() ? null : RSUtils.copyStackWithSize(stack, size - remainingSpace);
|
||||
} else {
|
||||
if (!simulate) {
|
||||
tag.setInteger(NBT_STORED, getStored() + size);
|
||||
|
||||
stacks.add(RSUtils.copyStackWithSize(stack, size));
|
||||
|
||||
onChanged();
|
||||
@@ -155,8 +153,6 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||
otherStack.amount -= size;
|
||||
}
|
||||
|
||||
tag.setInteger(NBT_STORED, getStored() - size);
|
||||
|
||||
onChanged();
|
||||
}
|
||||
|
||||
@@ -174,7 +170,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||
|
||||
@Override
|
||||
public int getStored() {
|
||||
return getStored(tag);
|
||||
return stacks.stream().mapToInt(s -> s.amount).sum();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -209,28 +205,27 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||
|
||||
@Override
|
||||
public boolean isValid(ItemStack stack) {
|
||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_FLUIDS) && stack.getTagCompound().hasKey(NBT_STORED);
|
||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_FLUIDS);
|
||||
}
|
||||
|
||||
public static NBTTagCompound getShareTag(NBTTagCompound tag) {
|
||||
StorageDiskFluid storage = new StorageDiskFluid(tag, 0);
|
||||
|
||||
storage.readFromNBT();
|
||||
|
||||
NBTTagCompound otherTag = new NBTTagCompound();
|
||||
|
||||
otherTag.setInteger(NBT_STORED, getStored(tag));
|
||||
otherTag.setTag(NBT_FLUIDS, new NBTTagList()); // To circumvent not being able to insert disks in Disk Drives (see FluidStorageNBT#isValid(ItemStack)).
|
||||
otherTag.setInteger(NBT_STORED, storage.getStored());
|
||||
otherTag.setTag(NBT_FLUIDS, new NBTTagList());
|
||||
otherTag.setInteger(NBT_PROTOCOL, PROTOCOL);
|
||||
|
||||
return otherTag;
|
||||
}
|
||||
|
||||
public static int getStored(NBTTagCompound tag) {
|
||||
return tag.getInteger(NBT_STORED);
|
||||
}
|
||||
|
||||
public static NBTTagCompound getTag() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
|
||||
tag.setTag(NBT_FLUIDS, new NBTTagList());
|
||||
tag.setInteger(NBT_STORED, 0);
|
||||
tag.setInteger(NBT_PROTOCOL, PROTOCOL);
|
||||
|
||||
return tag;
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.storage;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorage;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
@@ -15,15 +14,18 @@ import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A implementation of {@link IStorage<ItemStack>} that stores storage items in NBT.
|
||||
*/
|
||||
public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
private static final int PROTOCOL = 1;
|
||||
/**
|
||||
* Protocol history:
|
||||
* - 1: Initial
|
||||
* - 2: Removed "stored" tag
|
||||
*/
|
||||
private static final int PROTOCOL = 2;
|
||||
|
||||
private static final String NBT_PROTOCOL = "Protocol";
|
||||
|
||||
private static final String NBT_ITEMS = "Items";
|
||||
// Only client side
|
||||
private static final String NBT_STORED = "Stored";
|
||||
|
||||
private static final String NBT_ITEM_TYPE = "Type";
|
||||
@@ -37,10 +39,6 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
|
||||
private NonNullList<ItemStack> stacks = NonNullList.create();
|
||||
|
||||
/**
|
||||
* @param tag The NBT tag we are reading from and writing the amount stored to, has to be initialized with {@link StorageDiskItem#getTag()} if it doesn't exist yet
|
||||
* @param capacity The capacity of this storage, -1 for infinite capacity
|
||||
*/
|
||||
public StorageDiskItem(NBTTagCompound tag, int capacity) {
|
||||
this.tag = tag;
|
||||
this.capacity = capacity;
|
||||
@@ -128,8 +126,6 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
}
|
||||
|
||||
if (!simulate) {
|
||||
tag.setInteger(NBT_STORED, getStored() + remainingSpace);
|
||||
|
||||
otherStack.grow(remainingSpace);
|
||||
|
||||
onChanged();
|
||||
@@ -138,8 +134,6 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
return isVoiding() ? null : ItemHandlerHelper.copyStackWithSize(otherStack, size - remainingSpace);
|
||||
} else {
|
||||
if (!simulate) {
|
||||
tag.setInteger(NBT_STORED, getStored() + size);
|
||||
|
||||
otherStack.grow(size);
|
||||
|
||||
onChanged();
|
||||
@@ -162,8 +156,6 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
}
|
||||
|
||||
if (!simulate) {
|
||||
tag.setInteger(NBT_STORED, getStored() + remainingSpace);
|
||||
|
||||
stacks.add(ItemHandlerHelper.copyStackWithSize(stack, remainingSpace));
|
||||
|
||||
onChanged();
|
||||
@@ -172,8 +164,6 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
return isVoiding() ? null : ItemHandlerHelper.copyStackWithSize(stack, size - remainingSpace);
|
||||
} else {
|
||||
if (!simulate) {
|
||||
tag.setInteger(NBT_STORED, getStored() + size);
|
||||
|
||||
stacks.add(ItemHandlerHelper.copyStackWithSize(stack, size));
|
||||
|
||||
onChanged();
|
||||
@@ -199,8 +189,6 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
otherStack.shrink(size);
|
||||
}
|
||||
|
||||
tag.setInteger(NBT_STORED, getStored() - size);
|
||||
|
||||
onChanged();
|
||||
}
|
||||
|
||||
@@ -213,7 +201,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
|
||||
@Override
|
||||
public int getStored() {
|
||||
return getStored(tag);
|
||||
return stacks.stream().mapToInt(s -> s.getCount()).sum();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -238,7 +226,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
|
||||
@Override
|
||||
public boolean isValid(ItemStack stack) {
|
||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_ITEMS) && stack.getTagCompound().hasKey(NBT_STORED);
|
||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_ITEMS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -257,24 +245,23 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
}
|
||||
|
||||
public static NBTTagCompound getShareTag(NBTTagCompound tag) {
|
||||
StorageDiskItem storage = new StorageDiskItem(tag, 0);
|
||||
|
||||
storage.readFromNBT();
|
||||
|
||||
NBTTagCompound otherTag = new NBTTagCompound();
|
||||
|
||||
otherTag.setInteger(NBT_STORED, getStored(tag));
|
||||
otherTag.setTag(NBT_ITEMS, new NBTTagList()); // To circumvent not being able to insert disks in Disk Drives (see ItemStorageNBT#isValid(ItemStack)).
|
||||
otherTag.setInteger(NBT_STORED, storage.getStored());
|
||||
otherTag.setTag(NBT_ITEMS, new NBTTagList());
|
||||
otherTag.setInteger(NBT_PROTOCOL, PROTOCOL);
|
||||
|
||||
return otherTag;
|
||||
}
|
||||
|
||||
public static int getStored(NBTTagCompound tag) {
|
||||
return tag.getInteger(NBT_STORED);
|
||||
}
|
||||
|
||||
public static NBTTagCompound getTag() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
|
||||
tag.setTag(NBT_ITEMS, new NBTTagList());
|
||||
tag.setInteger(NBT_STORED, 0);
|
||||
tag.setInteger(NBT_PROTOCOL, PROTOCOL);
|
||||
|
||||
return tag;
|
||||
|
Reference in New Issue
Block a user