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 HopperMenu extends AbstractContainerMenu { public static final int CONTAINER_SIZE = 5; private final Container hopper; public HopperMenu(int containerId, Inventory playerInventory) { this(containerId, playerInventory, new SimpleContainer(5)); } public HopperMenu(int containerId, Inventory playerInventory, Container container) { super(MenuType.HOPPER, containerId); this.hopper = container; checkContainerSize(container, 5); container.startOpen(playerInventory.player); int i = 51; for (int j = 0; j < 5; j++) { this.addSlot(new Slot(container, j, 44 + j * 18, 20)); } for (int j = 0; j < 3; j++) { for (int k = 0; k < 9; k++) { this.addSlot(new Slot(playerInventory, k + j * 9 + 9, 8 + k * 18, j * 18 + 51)); } } for (int j = 0; j < 9; j++) { this.addSlot(new Slot(playerInventory, j, 8 + j * 18, 109)); } } @Override public boolean stillValid(Player player) { return this.hopper.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 < this.hopper.getContainerSize()) { if (!this.moveItemStackTo(itemStack2, this.hopper.getContainerSize(), this.slots.size(), true)) { return ItemStack.EMPTY; } } else if (!this.moveItemStackTo(itemStack2, 0, this.hopper.getContainerSize(), false)) { return ItemStack.EMPTY; } if (itemStack2.isEmpty()) { slot.setByPlayer(ItemStack.EMPTY); } else { slot.setChanged(); } } return itemStack; } @Override public void removed(Player player) { super.removed(player); this.hopper.stopOpen(player); } }