Skip to content

Commit

Permalink
save oversized output stacks properly (#1635)
Browse files Browse the repository at this point in the history
Signed-off-by: Glease <4586901+Glease@users.noreply.github.com>

Signed-off-by: Glease <4586901+Glease@users.noreply.github.com>
  • Loading branch information
Glease committed Jan 6, 2023
1 parent b988452 commit b34471f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,7 @@ public void saveNBTData(NBTTagCompound aNBT) {
if (mFluidOut != null) aNBT.setTag("mFluidOut", mFluidOut.writeToNBT(new NBTTagCompound()));

for (int i = 0; i < mOutputItems.length; i++)
if (mOutputItems[i] != null)
aNBT.setTag("mOutputItem" + i, mOutputItems[i].writeToNBT(new NBTTagCompound()));
if (mOutputItems[i] != null) GT_Utility.saveItem(aNBT, "mOutputItem" + i, mOutputItems[i]);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,7 @@ public void saveNBTData(NBTTagCompound aNBT) {
aNBT.setInteger("mOutputItemsLength", mOutputItems.length);
for (int i = 0; i < mOutputItems.length; i++)
if (mOutputItems[i] != null) {
NBTTagCompound tNBT = new NBTTagCompound();
mOutputItems[i].writeToNBT(tNBT);
aNBT.setTag("mOutputItem" + i, tNBT);
GT_Utility.saveItem(aNBT, "mOutputItem" + i, mOutputItems[i]);
}
}
if (mOutputFluids != null) {
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/gregtech/api/util/GT_Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.BlockSnapshot;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.common.util.ForgeDirection;
Expand Down Expand Up @@ -2904,7 +2905,29 @@ public static FluidStack loadFluid(NBTTagCompound aNBT, String aTagName) {
*/
public static ItemStack loadItem(NBTTagCompound aNBT) {
if (aNBT == null) return null;
return GT_OreDictUnificator.get(true, ItemStack.loadItemStackFromNBT(aNBT));
ItemStack tRawStack = ItemStack.loadItemStackFromNBT(aNBT);
int tRealStackSize = 0;
if (tRawStack != null && aNBT.hasKey("Count", Constants.NBT.TAG_INT)) {
tRealStackSize = aNBT.getInteger("Count");
tRawStack.stackSize = tRealStackSize;
} else if (tRawStack != null) {
tRealStackSize = tRawStack.stackSize;
}
ItemStack tRet = GT_OreDictUnificator.get(true, tRawStack);
if (tRet != null) tRet.stackSize = tRealStackSize;
return tRet;
}

public static void saveItem(NBTTagCompound aParentTag, String aTagName, ItemStack aStack) {
if (aStack != null) aParentTag.setTag(aTagName, saveItem(aStack));
}

public static NBTTagCompound saveItem(ItemStack aStack) {
if (aStack == null) return new NBTTagCompound();
NBTTagCompound t = new NBTTagCompound();
aStack.writeToNBT(t);
if (aStack.stackSize > Byte.MAX_VALUE) t.setInteger("Count", aStack.stackSize);
return t;
}

/**
Expand Down

0 comments on commit b34471f

Please sign in to comment.