From 65c8578af89764651a8eac4f4cfbb669463a94de Mon Sep 17 00:00:00 2001 From: MrCrayfish Date: Fri, 7 Jan 2022 18:29:54 +1030 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20Items=20no=20longer=20disappear?= =?UTF-8?q?=20if=20backpack=20size=20was=20changed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backpacked/inventory/BackpackInventory.java | 6 +++--- .../mrcrayfish/backpacked/util/InventoryHelper.java | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/mrcrayfish/backpacked/inventory/BackpackInventory.java b/src/main/java/com/mrcrayfish/backpacked/inventory/BackpackInventory.java index 2a75e9fc..9086bf22 100644 --- a/src/main/java/com/mrcrayfish/backpacked/inventory/BackpackInventory.java +++ b/src/main/java/com/mrcrayfish/backpacked/inventory/BackpackInventory.java @@ -23,15 +23,15 @@ public BackpackInventory(int cols, int rows, Player player, ItemStack stack) super(rows * cols); this.player = player; this.stack = stack; - this.loadBackpackContents(); + this.loadBackpackContents(player); } - private void loadBackpackContents() + private void loadBackpackContents(Player player) { CompoundTag compound = this.stack.getOrCreateTag(); if(compound.contains("Items", Tag.TAG_LIST)) { - InventoryHelper.loadAllItems(compound.getList("Items", Tag.TAG_COMPOUND), this); + InventoryHelper.loadAllItems(compound.getList("Items", Tag.TAG_COMPOUND), this, player); } } diff --git a/src/main/java/com/mrcrayfish/backpacked/util/InventoryHelper.java b/src/main/java/com/mrcrayfish/backpacked/util/InventoryHelper.java index b095ba76..25da1822 100644 --- a/src/main/java/com/mrcrayfish/backpacked/util/InventoryHelper.java +++ b/src/main/java/com/mrcrayfish/backpacked/util/InventoryHelper.java @@ -2,7 +2,10 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.SimpleContainer; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; /** @@ -26,7 +29,7 @@ public static ListTag saveAllItems(ListTag list, SimpleContainer inventory) return list; } - public static void loadAllItems(ListTag list, SimpleContainer inventory) + public static void loadAllItems(ListTag list, SimpleContainer inventory, Player player) { for(int i = 0; i < list.size(); i++) { @@ -36,6 +39,11 @@ public static void loadAllItems(ListTag list, SimpleContainer inventory) { inventory.setItem(slot, ItemStack.of(compound)); } + else if(player instanceof ServerPlayer) + { + ItemStack stack = ItemStack.of(compound); + player.spawnAtLocation(inventory.addItem(stack)); + } } } }