package net.minecraft.world.inventory; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.EntityTypeTags; import net.minecraft.world.Container; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.animal.horse.AbstractHorse; import net.minecraft.world.entity.animal.horse.Llama; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; public class HorseInventoryMenu extends AbstractContainerMenu { private static final ResourceLocation SADDLE_SLOT_SPRITE = ResourceLocation.withDefaultNamespace("container/slot/saddle"); private static final ResourceLocation LLAMA_ARMOR_SLOT_SPRITE = ResourceLocation.withDefaultNamespace("container/slot/llama_armor"); private static final ResourceLocation ARMOR_SLOT_SPRITE = ResourceLocation.withDefaultNamespace("container/slot/horse_armor"); private final Container horseContainer; private final AbstractHorse horse; private static final int SLOT_SADDLE = 0; private static final int SLOT_BODY_ARMOR = 1; private static final int SLOT_HORSE_INVENTORY_START = 2; public HorseInventoryMenu(int containerId, Inventory inventory, Container horseContainer, AbstractHorse horse, int columns) { super(null, containerId); this.horseContainer = horseContainer; this.horse = horse; horseContainer.startOpen(inventory.player); Container container = horse.createEquipmentSlotContainer(EquipmentSlot.SADDLE); this.addSlot(new ArmorSlot(container, horse, EquipmentSlot.SADDLE, 0, 8, 18, SADDLE_SLOT_SPRITE) { @Override public boolean isActive() { return horse.canUseSlot(EquipmentSlot.SADDLE) && horse.getType().is(EntityTypeTags.CAN_EQUIP_SADDLE); } }); final boolean bl = horse instanceof Llama; ResourceLocation resourceLocation = bl ? LLAMA_ARMOR_SLOT_SPRITE : ARMOR_SLOT_SPRITE; Container container2 = horse.createEquipmentSlotContainer(EquipmentSlot.BODY); this.addSlot(new ArmorSlot(container2, horse, EquipmentSlot.BODY, 0, 8, 36, resourceLocation) { @Override public boolean isActive() { return horse.canUseSlot(EquipmentSlot.BODY) && (horse.getType().is(EntityTypeTags.CAN_WEAR_HORSE_ARMOR) || bl); } }); if (columns > 0) { for (int i = 0; i < 3; i++) { for (int j = 0; j < columns; j++) { this.addSlot(new Slot(horseContainer, j + i * columns, 80 + j * 18, 18 + i * 18)); } } } this.addStandardInventorySlots(inventory, 8, 84); } @Override public boolean stillValid(Player player) { return !this.horse.hasInventoryChanged(this.horseContainer) && this.horseContainer.stillValid(player) && this.horse.isAlive() && player.canInteractWithEntity(this.horse, 4.0); } @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(); int i = 2 + this.horseContainer.getContainerSize(); if (index < i) { if (!this.moveItemStackTo(itemStack2, i, this.slots.size(), true)) { return ItemStack.EMPTY; } } else if (this.getSlot(1).mayPlace(itemStack2) && !this.getSlot(1).hasItem()) { if (!this.moveItemStackTo(itemStack2, 1, 2, false)) { return ItemStack.EMPTY; } } else if (this.getSlot(0).mayPlace(itemStack2) && !this.getSlot(0).hasItem()) { if (!this.moveItemStackTo(itemStack2, 0, 1, false)) { return ItemStack.EMPTY; } } else if (this.horseContainer.getContainerSize() == 0 || !this.moveItemStackTo(itemStack2, 2, i, false)) { int j = i + 27; int l = j + 9; if (index >= j && index < l) { if (!this.moveItemStackTo(itemStack2, i, j, false)) { return ItemStack.EMPTY; } } else if (index >= i && index < j) { if (!this.moveItemStackTo(itemStack2, j, l, false)) { return ItemStack.EMPTY; } } else if (!this.moveItemStackTo(itemStack2, j, j, false)) { return ItemStack.EMPTY; } 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.horseContainer.stopOpen(player); } }