package lv.enes.mc.eris_alchemy.menu; import jakarta.annotation.Nonnull; import net.minecraft.world.Container; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.ItemStack; public abstract class ChestLikeBlockMenu extends AbstractContainerMenu { protected final Container container; public ChestLikeBlockMenu( MenuType type, int syncId, Inventory playerInventory, Container container ) { super(type, syncId); checkContainerSize(container, getRequiredSize()); this.container = container; container.startOpen(playerInventory.player); addSlots(playerInventory); } protected abstract void addSlots(Inventory playerInventory); protected abstract int getRequiredSize(); public Container getContainer() { return container; } @Nonnull @Override public ItemStack quickMoveStack(Player player, int fromIndex) { var newStack = ItemStack.EMPTY; var slot = slots.get(fromIndex); if (!slot.hasItem()) { return newStack; } var originalStack = slot.getItem(); newStack = originalStack.copy(); if (fromIndex < container.getContainerSize()) { if (!moveItemStackTo(originalStack, container.getContainerSize(), slots.size(), true)) { return ItemStack.EMPTY; } } else if (!moveItemStackTo(originalStack, 0, container.getContainerSize(), false)) { return ItemStack.EMPTY; } if (originalStack.isEmpty()) { slot.setByPlayer(ItemStack.EMPTY); } else { slot.setChanged(); } return newStack; } @Override public boolean stillValid(Player player) { return container.stillValid(player); } }