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