diff --git a/src/main/java/com/mrcrayfish/backpacked/inventory/BackpackInventory.java b/src/main/java/com/mrcrayfish/backpacked/inventory/BackpackInventory.java index 662aa241..990c3591 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, PlayerEntity player, ItemStack stac super(rows * cols); this.player = player; this.stack = stack; - this.loadBackpackContents(); + this.loadBackpackContents(player); } - private void loadBackpackContents() + private void loadBackpackContents(PlayerEntity player) { CompoundNBT compound = this.stack.getOrCreateTag(); if(compound.contains("Items", Constants.NBT.TAG_LIST)) { - InventoryHelper.loadAllItems(compound.getList("Items", Constants.NBT.TAG_COMPOUND), this); + InventoryHelper.loadAllItems(compound.getList("Items", Constants.NBT.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 27ef417c..3a375d69 100644 --- a/src/main/java/com/mrcrayfish/backpacked/util/InventoryHelper.java +++ b/src/main/java/com/mrcrayfish/backpacked/util/InventoryHelper.java @@ -1,5 +1,7 @@ package com.mrcrayfish.backpacked.util; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; @@ -26,7 +28,7 @@ public static ListNBT saveAllItems(ListNBT list, Inventory inventory) return list; } - public static void loadAllItems(ListNBT list, Inventory inventory) + public static void loadAllItems(ListNBT list, Inventory inventory, PlayerEntity player) { for(int i = 0; i < list.size(); i++) { @@ -36,6 +38,11 @@ public static void loadAllItems(ListNBT list, Inventory inventory) { inventory.setItem(slot, ItemStack.of(compound)); } + else if(player instanceof ServerPlayerEntity) + { + ItemStack stack = ItemStack.of(compound); + player.spawnAtLocation(inventory.addItem(stack)); + } } } }