| 1 | package net.minecraft.world.inventory;
|
| 2 |
|
| 3 | import net.minecraft.resources.Identifier;
|
| 4 | import net.minecraft.tags.EntityTypeTags;
|
| 5 | import net.minecraft.world.Container;
|
| 6 | import net.minecraft.world.entity.EquipmentSlot;
|
| 7 | import net.minecraft.world.entity.animal.equine.AbstractHorse;
|
| 8 | import net.minecraft.world.entity.animal.equine.Llama;
|
| 9 | import net.minecraft.world.entity.player.Inventory;
|
| 10 |
|
| 11 | public class HorseInventoryMenu extends AbstractMountInventoryMenu {
|
| 12 | private static final Identifier SADDLE_SLOT_SPRITE = Identifier.withDefaultNamespace("container/slot/saddle");
|
| 13 | private static final Identifier LLAMA_ARMOR_SLOT_SPRITE = Identifier.withDefaultNamespace("container/slot/llama_armor");
|
| 14 | private static final Identifier ARMOR_SLOT_SPRITE = Identifier.withDefaultNamespace("container/slot/horse_armor");
|
| 15 |
|
| 16 | public HorseInventoryMenu(
|
| 17 | final int containerId, final Inventory playerInventory, final Container horseInventory, final AbstractHorse horse, final int inventoryColumns
|
| 18 | ) {
|
| 19 | super(containerId, playerInventory, horseInventory, horse);
|
| 20 | Container saddleContainer = horse.createEquipmentSlotContainer(EquipmentSlot.SADDLE);
|
| 21 | this.addSlot(new ArmorSlot(saddleContainer, horse, EquipmentSlot.SADDLE, 0, 8, 18, SADDLE_SLOT_SPRITE) {
|
| 22 | @Override
|
| 23 | public boolean isActive() {
|
| 24 | return horse.canUseSlot(EquipmentSlot.SADDLE) && horse.is(EntityTypeTags.CAN_EQUIP_SADDLE);
|
| 25 | }
|
| 26 | });
|
| 27 | final boolean isLlama = horse instanceof Llama;
|
| 28 | Identifier armorSprite = isLlama ? LLAMA_ARMOR_SLOT_SPRITE : ARMOR_SLOT_SPRITE;
|
| 29 | Container armorContainer = horse.createEquipmentSlotContainer(EquipmentSlot.BODY);
|
| 30 | this.addSlot(new ArmorSlot(armorContainer, horse, EquipmentSlot.BODY, 0, 8, 36, armorSprite) {
|
| 31 | @Override
|
| 32 | public boolean isActive() {
|
| 33 | return horse.canUseSlot(EquipmentSlot.BODY) && (horse.is(EntityTypeTags.CAN_WEAR_HORSE_ARMOR) || isLlama);
|
| 34 | }
|
| 35 | });
|
| 36 | if (inventoryColumns > 0) {
|
| 37 | for (int y = 0; y < 3; y++) {
|
| 38 | for (int x = 0; x < inventoryColumns; x++) {
|
| 39 | this.addSlot(new Slot(horseInventory, x + y * inventoryColumns, 80 + x * 18, 18 + y * 18));
|
| 40 | }
|
| 41 | }
|
| 42 | }
|
| 43 |
|
| 44 | this.addStandardInventorySlots(playerInventory, 8, 84);
|
| 45 | }
|
| 46 |
|
| 47 | @Override
|
| 48 | protected boolean hasInventoryChanged(final Container container) {
|
| 49 | return ((AbstractHorse)this.mount).hasInventoryChanged(container);
|
| 50 | }
|
| 51 | }
|
| 52 |
|