| 1 | package net.minecraft.world.inventory;
|
| 2 |
|
| 3 | import net.minecraft.world.Container;
|
| 4 | import net.minecraft.world.entity.LivingEntity;
|
| 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 abstract class AbstractMountInventoryMenu extends AbstractContainerMenu {
|
| 10 | protected final Container mountContainer;
|
| 11 | protected final LivingEntity mount;
|
| 12 | protected final int SLOT_SADDLE = 0;
|
| 13 | protected final int SLOT_BODY_ARMOR = 1;
|
| 14 | protected final int SLOT_INVENTORY_START = 2;
|
| 15 | protected static final int INVENTORY_ROWS = 3;
|
| 16 |
|
| 17 | protected AbstractMountInventoryMenu(final int containerId, final Inventory playerInventory, final Container mountInventory, final LivingEntity mount) {
|
| 18 | super(null, containerId);
|
| 19 | this.mountContainer = mountInventory;
|
| 20 | this.mount = mount;
|
| 21 | mountInventory.startOpen(playerInventory.player);
|
| 22 | }
|
| 23 |
|
| 24 | protected abstract boolean hasInventoryChanged(final Container container);
|
| 25 |
|
| 26 | @Override
|
| 27 | public boolean stillValid(final Player player) {
|
| 28 | return !this.hasInventoryChanged(this.mountContainer)
|
| 29 | && this.mountContainer.stillValid(player)
|
| 30 | && this.mount.isAlive()
|
| 31 | && player.isWithinEntityInteractionRange(this.mount, 4.0);
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | public void removed(final Player player) {
|
| 36 | super.removed(player);
|
| 37 | this.mountContainer.stopOpen(player);
|
| 38 | }
|
| 39 |
|
| 40 | @Override
|
| 41 | public ItemStack quickMoveStack(final Player player, final int slotIndex) {
|
| 42 | ItemStack clicked = ItemStack.EMPTY;
|
| 43 | Slot slot = this.slots.get(slotIndex);
|
| 44 | if (slot != null && slot.hasItem()) {
|
| 45 | ItemStack stack = slot.getItem();
|
| 46 | clicked = stack.copy();
|
| 47 | int playerContainerStart = 2 + this.mountContainer.getContainerSize();
|
| 48 | if (slotIndex < playerContainerStart) {
|
| 49 | if (!this.moveItemStackTo(stack, playerContainerStart, this.slots.size(), true)) {
|
| 50 | return ItemStack.EMPTY;
|
| 51 | }
|
| 52 | } else if (this.getSlot(1).mayPlace(stack) && !this.getSlot(1).hasItem()) {
|
| 53 | if (!this.moveItemStackTo(stack, 1, 2, false)) {
|
| 54 | return ItemStack.EMPTY;
|
| 55 | }
|
| 56 | } else if (this.getSlot(0).mayPlace(stack) && !this.getSlot(0).hasItem()) {
|
| 57 | if (!this.moveItemStackTo(stack, 0, 1, false)) {
|
| 58 | return ItemStack.EMPTY;
|
| 59 | }
|
| 60 | } else if (this.mountContainer.getContainerSize() == 0 || !this.moveItemStackTo(stack, 2, playerContainerStart, false)) {
|
| 61 | int playerContainerEnd = playerContainerStart + 27;
|
| 62 | int playerHotBarStart = playerContainerEnd;
|
| 63 | int playerHotBarEnd = playerHotBarStart + 9;
|
| 64 | if (slotIndex >= playerHotBarStart && slotIndex < playerHotBarEnd) {
|
| 65 | if (!this.moveItemStackTo(stack, playerContainerStart, playerContainerEnd, false)) {
|
| 66 | return ItemStack.EMPTY;
|
| 67 | }
|
| 68 | } else if (slotIndex >= playerContainerStart && slotIndex < playerContainerEnd) {
|
| 69 | if (!this.moveItemStackTo(stack, playerHotBarStart, playerHotBarEnd, false)) {
|
| 70 | return ItemStack.EMPTY;
|
| 71 | }
|
| 72 | } else if (!this.moveItemStackTo(stack, playerHotBarStart, playerContainerEnd, false)) {
|
| 73 | return ItemStack.EMPTY;
|
| 74 | }
|
| 75 |
|
| 76 | return ItemStack.EMPTY;
|
| 77 | }
|
| 78 |
|
| 79 | if (stack.isEmpty()) {
|
| 80 | slot.setByPlayer(ItemStack.EMPTY);
|
| 81 | } else {
|
| 82 | slot.setChanged();
|
| 83 | }
|
| 84 | }
|
| 85 |
|
| 86 | return clicked;
|
| 87 | }
|
| 88 |
|
| 89 | public static int getInventorySize(final int inventoryColumns) {
|
| 90 | return inventoryColumns * 3;
|
| 91 | }
|
| 92 | }
|
| 93 |
|