From b153a00bbf3b0d0ebd2fe3c20fb04612db9c5b3d Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Sat, 22 Apr 2017 14:29:17 +0200 Subject: [PATCH] Fix tile inventory --- .../mantle/tileentity/TileInventory.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/main/java/slimeknights/mantle/tileentity/TileInventory.java b/src/main/java/slimeknights/mantle/tileentity/TileInventory.java index f3b8ea0..6167e27 100644 --- a/src/main/java/slimeknights/mantle/tileentity/TileInventory.java +++ b/src/main/java/slimeknights/mantle/tileentity/TileInventory.java @@ -21,6 +21,8 @@ import java.util.Arrays; import javax.annotation.Nonnull; +import slimeknights.mantle.util.ItemStackList; + // Updated version of InventoryLogic in Mantle. Also contains a few bugfixes public class TileInventory extends MantleTileEntity implements IInventory { @@ -81,17 +83,12 @@ public class TileInventory extends MantleTileEntity implements IInventory { } public void resize(int size) { - //TODO: Make sure this didn't break inventory contents. - NonNullList oldInventory = inventory; - - inventory = NonNullList. withSize(size, ItemStack.EMPTY); - - for (int i = 0; i < size; i++) { - ItemStack itemStack = oldInventory.get(i); - if (!itemStack.isEmpty()) { - inventory.set(i, itemStack); - } + ItemStackList newInventory = ItemStackList.withSize(size); + + for (int i = 0; i < size && i < inventory.size(); i++) { + newInventory.set(i, inventory.get(i)); } + inventory = newInventory; } @Override