package net.minecraft.world.inventory; import net.minecraft.world.Container; import net.minecraft.world.SimpleContainer; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; public class DispenserMenu extends AbstractContainerMenu { private static final int SLOT_COUNT = 9; private static final int INV_SLOT_START = 9; private static final int INV_SLOT_END = 36; private static final int USE_ROW_SLOT_START = 36; private static final int USE_ROW_SLOT_END = 45; private final Container dispenser; public DispenserMenu(int containerId, Inventory playerInventory) { this(containerId, playerInventory, new SimpleContainer(9)); } public DispenserMenu(int containerId, Inventory playerInventory, Container container) { super(MenuType.GENERIC_3x3, containerId); checkContainerSize(container, 9); this.dispenser = container; container.startOpen(playerInventory.player); this.add3x3GridSlots(container, 62, 17); this.addStandardInventorySlots(playerInventory, 8, 84); } protected void add3x3GridSlots(Container container, int x, int y) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { int k = j + i * 3; this.addSlot(new Slot(container, k, x + j * 18, y + i * 18)); } } } @Override public boolean stillValid(Player player) { return this.dispenser.stillValid(player); } @Override public ItemStack quickMoveStack(Player player, int index) { ItemStack itemStack = ItemStack.EMPTY; Slot slot = this.slots.get(index); if (slot != null && slot.hasItem()) { ItemStack itemStack2 = slot.getItem(); itemStack = itemStack2.copy(); if (index < 9) { if (!this.moveItemStackTo(itemStack2, 9, 45, true)) { return ItemStack.EMPTY; } } else if (!this.moveItemStackTo(itemStack2, 0, 9, false)) { return ItemStack.EMPTY; } if (itemStack2.isEmpty()) { slot.setByPlayer(ItemStack.EMPTY); } else { slot.setChanged(); } if (itemStack2.getCount() == itemStack.getCount()) { return ItemStack.EMPTY; } slot.onTake(player, itemStack2); } return itemStack; } @Override public void removed(Player player) { super.removed(player); this.dispenser.stopOpen(player); } }