| 1 | package net.minecraft.world.inventory;
|
| 2 |
|
| 3 | import net.minecraft.world.Container;
|
| 4 | import net.minecraft.world.SimpleContainer;
|
| 5 | import net.minecraft.world.entity.player.Inventory;
|
| 6 | import net.minecraft.world.entity.player.Player;
|
| 7 | import net.minecraft.world.item.ItemStack;
|
| 8 |
|
| 9 | public class ShulkerBoxMenu extends AbstractContainerMenu {
|
| 10 | private static final int CONTAINER_SIZE = 27;
|
| 11 | private final Container container;
|
| 12 |
|
| 13 | public ShulkerBoxMenu(final int containerId, final Inventory inventory) {
|
| 14 | this(containerId, inventory, new SimpleContainer(27));
|
| 15 | }
|
| 16 |
|
| 17 | public ShulkerBoxMenu(final int containerId, final Inventory inventory, final Container container) {
|
| 18 | super(MenuType.SHULKER_BOX, containerId);
|
| 19 | checkContainerSize(container, 27);
|
| 20 | this.container = container;
|
| 21 | container.startOpen(inventory.player);
|
| 22 | int rows = 3;
|
| 23 | int columns = 9;
|
| 24 |
|
| 25 | for (int y = 0; y < 3; y++) {
|
| 26 | for (int x = 0; x < 9; x++) {
|
| 27 | this.addSlot(new ShulkerBoxSlot(container, x + y * 9, 8 + x * 18, 18 + y * 18));
|
| 28 | }
|
| 29 | }
|
| 30 |
|
| 31 | this.addStandardInventorySlots(inventory, 8, 84);
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | public boolean stillValid(final Player player) {
|
| 36 | return this.container.stillValid(player);
|
| 37 | }
|
| 38 |
|
| 39 | @Override
|
| 40 | public ItemStack quickMoveStack(final Player player, final int slotIndex) {
|
| 41 | ItemStack clicked = ItemStack.EMPTY;
|
| 42 | Slot slot = this.slots.get(slotIndex);
|
| 43 | if (slot != null && slot.hasItem()) {
|
| 44 | ItemStack stack = slot.getItem();
|
| 45 | clicked = stack.copy();
|
| 46 | if (slotIndex < this.container.getContainerSize()) {
|
| 47 | if (!this.moveItemStackTo(stack, this.container.getContainerSize(), this.slots.size(), true)) {
|
| 48 | return ItemStack.EMPTY;
|
| 49 | }
|
| 50 | } else if (!this.moveItemStackTo(stack, 0, this.container.getContainerSize(), false)) {
|
| 51 | return ItemStack.EMPTY;
|
| 52 | }
|
| 53 |
|
| 54 | if (stack.isEmpty()) {
|
| 55 | slot.setByPlayer(ItemStack.EMPTY);
|
| 56 | } else {
|
| 57 | slot.setChanged();
|
| 58 | }
|
| 59 | }
|
| 60 |
|
| 61 | return clicked;
|
| 62 | }
|
| 63 |
|
| 64 | @Override
|
| 65 | public void removed(final Player player) {
|
| 66 | super.removed(player);
|
| 67 | this.container.stopOpen(player);
|
| 68 | }
|
| 69 | }
|
| 70 |
|