Skip to content

Commit

Permalink
fix: ACTUALLY fix the empty itemstack issue this time
Browse files Browse the repository at this point in the history
Third time's the charm
FTBTeam/FTB-Mods-Issues#1182
  • Loading branch information
desht committed May 28, 2024
1 parent 43bdba1 commit 43d12f2
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ public static ItemStack readItem(CompoundTag tag) {
return stack;
}

// Kludge: see kludge comment below!
return ItemStack.of(tag).copyWithCount(tag.getInt("Count"));
// Kludge: vanilla serializes the stack size as a byte, which breaks for a stack >127 items,
// leading to the stack turning into an empty (air) stack
// (note: using ItemStack#copyWithCount will *not* work here)
ItemStack stack = ItemStack.of(tag);
stack.setCount(tag.getInt("Count"));
return stack;
}

public static CompoundTag writeItem(ItemStack stack) {
Expand All @@ -54,9 +58,7 @@ public static CompoundTag writeItem(ItemStack stack) {
SNBTCompoundTag tag = new SNBTCompoundTag();
stack.save(tag);

// kludge: vanilla saves the stack size as a byte, which means negative sizes for big stacks,
// leading to the stack turning into an empty (air) stack
// https://github.com/FTBTeam/FTB-Mods-Issues/issues/1182
// kludge: see above!
tag.putInt("Count", stack.getCount());

if (tag.size() == 2) {
Expand Down

0 comments on commit 43d12f2

Please sign in to comment.