diff --git a/src/main/java/team/lodestar/lodestone/systems/blockentity/LodestoneBlockEntityInventory.java b/src/main/java/team/lodestar/lodestone/systems/blockentity/LodestoneBlockEntityInventory.java index f916bfd6..0cdd5dce 100644 --- a/src/main/java/team/lodestar/lodestone/systems/blockentity/LodestoneBlockEntityInventory.java +++ b/src/main/java/team/lodestar/lodestone/systems/blockentity/LodestoneBlockEntityInventory.java @@ -17,6 +17,7 @@ import team.lodestar.lodestone.helpers.BlockHelper; import java.util.ArrayList; +import java.util.List; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -30,7 +31,7 @@ public class LodestoneBlockEntityInventory extends ItemStackHandlerContainer { public Predicate outputPredicate; public final LazyOptional inventoryOptional = LazyOptional.of(() -> this); - public ArrayList> nonEmptyItemStacks = new ArrayList<>(); + public ArrayList nonEmptyItemStacks = new ArrayList<>(); public int emptyItemAmount; public int nonEmptyItemAmount; @@ -38,21 +39,22 @@ public class LodestoneBlockEntityInventory extends ItemStackHandlerContainer { private LodestoneBlockEntity blockEntity; - public LodestoneBlockEntityInventory(int slotCount, int allowedItemSize, Predicate inputPredicate, Predicate outputPredicate) { - this(slotCount, allowedItemSize, inputPredicate); + public LodestoneBlockEntityInventory(LodestoneBlockEntity blockEntity, int slotCount, int allowedItemSize, Predicate inputPredicate, Predicate outputPredicate) { + this(blockEntity, slotCount, allowedItemSize, inputPredicate); this.outputPredicate = outputPredicate; } - public LodestoneBlockEntityInventory(int slotCount, int allowedItemSize, Predicate inputPredicate) { - this(slotCount, allowedItemSize); + public LodestoneBlockEntityInventory(LodestoneBlockEntity blockEntity, int slotCount, int allowedItemSize, Predicate inputPredicate) { + this(blockEntity, slotCount, allowedItemSize); this.inputPredicate = inputPredicate; } - public LodestoneBlockEntityInventory(int slotCount, int allowedItemSize) { + public LodestoneBlockEntityInventory(LodestoneBlockEntity blockEntity, int slotCount, int allowedItemSize) { super(slotCount); this.slotCount = slotCount; this.allowedItemSize = allowedItemSize; updateData(); + this.blockEntity = blockEntity; } @Override @@ -88,13 +90,13 @@ public void clear() { } public void updateData() { - var stacks = getSlots(); - nonEmptyItemStacks = stacks.stream().filter(s -> !s.getSlots().isEmpty()).collect(Collectors.toCollection(ArrayList::new)); + NonNullList stacks = convertToNonNullItemStacks(getSlots()); + nonEmptyItemStacks = stacks.stream().filter(s -> !s.isEmpty()).collect(Collectors.toCollection(ArrayList::new)); nonEmptyItemAmount = nonEmptyItemStacks.size(); - emptyItemAmount = (int) stacks.stream().filter(storageViews -> storageViews.getSlots().isEmpty()).count(); + emptyItemAmount = (int) stacks.stream().filter(ItemStack::isEmpty).count(); for (int i = 0; i < stacks.size(); i++) { - var stack = stacks.get(i); - if (stack.isResourceBlank()) { + ItemStack stack = stacks.get(i); + if (stack.isEmpty()) { firstEmptyItemIndex = i; return; } @@ -102,6 +104,40 @@ public void updateData() { firstEmptyItemIndex = -1; } + public static ArrayList convertToItemStacks(ArrayList> nonEmptyItemStacks) { + ArrayList itemStacks = new ArrayList<>(); + + for (SingleSlotStorage slot : nonEmptyItemStacks) { + // Get the ItemVariant from the slot + ItemVariant itemVariant = slot.getResource(); + + // Convert ItemVariant to ItemStack + ItemStack itemStack = itemVariant.toStack((int) slot.getAmount()); + + // Add the ItemStack to the new list + itemStacks.add(itemStack); + } + + return itemStacks; + } + + public static NonNullList convertToNonNullItemStacks(List> nonEmptyItemStacks) { + NonNullList itemStacks = NonNullList.create(); + + for (SingleSlotStorage slot : nonEmptyItemStacks) { + // Get the ItemVariant from the slot + ItemVariant itemVariant = slot.getResource(); + + // Convert ItemVariant to ItemStack + ItemStack itemStack = itemVariant.toStack((int) slot.getAmount()); + + // Add the ItemStack to the new list + itemStacks.add(itemStack); + } + + return itemStacks; + } + public void dumpItems(Level level, BlockPos pos) { dumpItems(level, BlockHelper.fromBlockPos(pos).add(0.5, 0.5, 0.5)); } @@ -121,7 +157,7 @@ public void interact(Level level, Player player, InteractionHand handIn) { player.swing(handIn, true); int size = nonEmptyItemStacks.size() - 1; if ((held.isEmpty() || firstEmptyItemIndex == -1) && size != -1) { - ItemStack takeOutStack = nonEmptyItemStacks.get(size).getResource().toStack(); + ItemStack takeOutStack = nonEmptyItemStacks.get(size); if (takeOutStack.getItem().equals(held.getItem())) { TransferUtil.insertItem(this, held); return;