custom serialization of oversized itemstacks.
simple limiting by checking overflow
This commit is contained in:
@@ -266,13 +266,13 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
|
|||||||
|
|
||||||
for (int x = 0; x < this.craftingSlots.length; x++) {
|
for (int x = 0; x < this.craftingSlots.length; x++) {
|
||||||
input[x] = this.craftingSlots[x].getStack();
|
input[x] = this.craftingSlots[x].getStack();
|
||||||
if (!input[x].isEmpty() && input[x].getCount() * multiple > input[x].getMaxStackSize()) {
|
if (!input[x].isEmpty() && input[x].getCount() * multiple < 0) {
|
||||||
canMultiplyInputs = false;
|
canMultiplyInputs = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final OptionalSlotFake outputSlot : this.outputSlots) {
|
for (final OptionalSlotFake outputSlot : this.outputSlots) {
|
||||||
final ItemStack out = outputSlot.getStack();
|
final ItemStack out = outputSlot.getStack();
|
||||||
if (!out.isEmpty() && out.getCount() * multiple > out.getMaxStackSize()) {
|
if (!out.isEmpty() && out.getCount() * multiple < 0) {
|
||||||
canMultiplyOutputs = false;
|
canMultiplyOutputs = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -488,6 +488,9 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
|
|||||||
|
|
||||||
if (!i.isEmpty()) {
|
if (!i.isEmpty()) {
|
||||||
i.writeToNBT(c);
|
i.writeToNBT(c);
|
||||||
|
if (i.getCount() > i.getMaxStackSize()) {
|
||||||
|
c.setInteger("stackSize", i.getCount());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
|
|||||||
@@ -93,6 +93,10 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
|||||||
NBTTagCompound ingredient = inTag.getCompoundTagAt(x);
|
NBTTagCompound ingredient = inTag.getCompoundTagAt(x);
|
||||||
final ItemStack gs = new ItemStack(ingredient);
|
final ItemStack gs = new ItemStack(ingredient);
|
||||||
|
|
||||||
|
if (ingredient.hasKey("stackSize")) {
|
||||||
|
gs.setCount(ingredient.getInteger("stackSize"));
|
||||||
|
}
|
||||||
|
|
||||||
if (!ingredient.hasNoTags() && gs.isEmpty()) {
|
if (!ingredient.hasNoTags() && gs.isEmpty()) {
|
||||||
throw new IllegalArgumentException("No pattern here!");
|
throw new IllegalArgumentException("No pattern here!");
|
||||||
}
|
}
|
||||||
@@ -124,6 +128,10 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
|||||||
NBTTagCompound resultItemTag = outTag.getCompoundTagAt(x);
|
NBTTagCompound resultItemTag = outTag.getCompoundTagAt(x);
|
||||||
final ItemStack gs = new ItemStack(resultItemTag);
|
final ItemStack gs = new ItemStack(resultItemTag);
|
||||||
|
|
||||||
|
if (resultItemTag.hasKey("stackSize")) {
|
||||||
|
gs.setCount(resultItemTag.getInteger("stackSize"));
|
||||||
|
}
|
||||||
|
|
||||||
if (!resultItemTag.hasNoTags() && gs.isEmpty()) {
|
if (!resultItemTag.hasNoTags() && gs.isEmpty()) {
|
||||||
throw new IllegalArgumentException("No pattern here!");
|
throw new IllegalArgumentException("No pattern here!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import appeng.util.inv.InvOperation;
|
|||||||
import appeng.util.inv.filter.IAEItemFilter;
|
import appeng.util.inv.filter.IAEItemFilter;
|
||||||
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.minecraftforge.common.util.Constants;
|
||||||
import net.minecraftforge.items.ItemStackHandler;
|
import net.minecraftforge.items.ItemStackHandler;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -152,6 +154,27 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
|||||||
data.setTag(name, this.serializeNBT());
|
data.setTag(name, this.serializeNBT());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NBTTagCompound serializeNBT() {
|
||||||
|
NBTTagList nbtTagList = new NBTTagList();
|
||||||
|
for (int i = 0; i < stacks.size(); i++) {
|
||||||
|
ItemStack is = stacks.get(i);
|
||||||
|
if (!is.isEmpty()) {
|
||||||
|
NBTTagCompound itemTag = new NBTTagCompound();
|
||||||
|
itemTag.setInteger("Slot", i);
|
||||||
|
if (is.getCount() > is.getMaxStackSize()) {
|
||||||
|
itemTag.setInteger("stackSize", stacks.get(i).getCount());
|
||||||
|
}
|
||||||
|
stacks.get(i).writeToNBT(itemTag);
|
||||||
|
nbtTagList.appendTag(itemTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NBTTagCompound nbt = new NBTTagCompound();
|
||||||
|
nbt.setTag("Items", nbtTagList);
|
||||||
|
nbt.setInteger("Size", stacks.size());
|
||||||
|
return nbt;
|
||||||
|
}
|
||||||
|
|
||||||
public void readFromNBT(final NBTTagCompound data, final String name) {
|
public void readFromNBT(final NBTTagCompound data, final String name) {
|
||||||
final NBTTagCompound c = data.getCompoundTag(name);
|
final NBTTagCompound c = data.getCompoundTag(name);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
@@ -163,6 +186,24 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
|||||||
this.deserializeNBT(data);
|
this.deserializeNBT(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deserializeNBT(NBTTagCompound nbt) {
|
||||||
|
setSize(nbt.hasKey("Size", Constants.NBT.TAG_INT) ? nbt.getInteger("Size") : stacks.size());
|
||||||
|
NBTTagList tagList = nbt.getTagList("Items", Constants.NBT.TAG_COMPOUND);
|
||||||
|
for (int i = 0; i < tagList.tagCount(); i++) {
|
||||||
|
NBTTagCompound itemTags = tagList.getCompoundTagAt(i);
|
||||||
|
int slot = itemTags.getInteger("Slot");
|
||||||
|
if (slot >= 0 && slot < stacks.size()) {
|
||||||
|
stacks.set(slot, new ItemStack(itemTags));
|
||||||
|
if (itemTags.hasKey("stackSize")) {
|
||||||
|
int stackSize = itemTags.getInteger("stackSize");
|
||||||
|
stacks.get(slot).setCount(stackSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onLoad();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<ItemStack> iterator() {
|
public Iterator<ItemStack> iterator() {
|
||||||
return Collections.unmodifiableList(super.stacks).iterator();
|
return Collections.unmodifiableList(super.stacks).iterator();
|
||||||
|
|||||||
Reference in New Issue
Block a user