| 1 | package net.minecraft.inventory;
|
| 2 |
|
| 3 | import net.minecraft.entity.passive.EntityHorse;
|
| 4 | import net.minecraft.entity.player.EntityPlayer;
|
| 5 | import net.minecraft.init.Items;
|
| 6 | import net.minecraft.item.ItemStack;
|
| 7 |
|
| 8 | public class ContainerHorseInventory extends Container
|
| 9 | {
|
| 10 | private IInventory horseInventory;
|
| 11 | private EntityHorse theHorse;
|
| 12 |
|
| 13 | public ContainerHorseInventory(IInventory playerInventory, final IInventory horseInventoryIn, final EntityHorse horse, EntityPlayer player)
|
| 14 | {
|
| 15 | this.horseInventory = horseInventoryIn;
|
| 16 | this.theHorse = horse;
|
| 17 | int i = 3;
|
| 18 | horseInventoryIn.openInventory(player);
|
| 19 | int j = (i - 4) * 18;
|
| 20 | this.addSlotToContainer(new Slot(horseInventoryIn, 0, 8, 18)
|
| 21 | {
|
| 22 | public boolean isItemValid(ItemStack stack)
|
| 23 | {
|
| 24 | return super.isItemValid(stack) && stack.getItem() == Items.saddle && !this.getHasStack();
|
| 25 | }
|
| 26 | });
|
| 27 | this.addSlotToContainer(new Slot(horseInventoryIn, 1, 8, 36)
|
| 28 | {
|
| 29 | public boolean isItemValid(ItemStack stack)
|
| 30 | {
|
| 31 | return super.isItemValid(stack) && horse.canWearArmor() && EntityHorse.isArmorItem(stack.getItem());
|
| 32 | }
|
| 33 | public boolean canBeHovered()
|
| 34 | {
|
| 35 | return horse.canWearArmor();
|
| 36 | }
|
| 37 | });
|
| 38 |
|
| 39 | if (horse.isChested())
|
| 40 | {
|
| 41 | for (int k = 0; k < i; ++k)
|
| 42 | {
|
| 43 | for (int l = 0; l < 5; ++l)
|
| 44 | {
|
| 45 | this.addSlotToContainer(new Slot(horseInventoryIn, 2 + l + k * 5, 80 + l * 18, 18 + k * 18));
|
| 46 | }
|
| 47 | }
|
| 48 | }
|
| 49 |
|
| 50 | for (int i1 = 0; i1 < 3; ++i1)
|
| 51 | {
|
| 52 | for (int k1 = 0; k1 < 9; ++k1)
|
| 53 | {
|
| 54 | this.addSlotToContainer(new Slot(playerInventory, k1 + i1 * 9 + 9, 8 + k1 * 18, 102 + i1 * 18 + j));
|
| 55 | }
|
| 56 | }
|
| 57 |
|
| 58 | for (int j1 = 0; j1 < 9; ++j1)
|
| 59 | {
|
| 60 | this.addSlotToContainer(new Slot(playerInventory, j1, 8 + j1 * 18, 160 + j));
|
| 61 | }
|
| 62 | }
|
| 63 |
|
| 64 | public boolean canInteractWith(EntityPlayer playerIn)
|
| 65 | {
|
| 66 | return this.horseInventory.isUseableByPlayer(playerIn) && this.theHorse.isEntityAlive() && this.theHorse.getDistanceToEntity(playerIn) < 8.0F;
|
| 67 | }
|
| 68 |
|
| 69 | /**
|
| 70 | * Take a stack from the specified inventory slot.
|
| 71 | */
|
| 72 | public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
|
| 73 | {
|
| 74 | ItemStack itemstack = null;
|
| 75 | Slot slot = (Slot)this.inventorySlots.get(index);
|
| 76 |
|
| 77 | if (slot != null && slot.getHasStack())
|
| 78 | {
|
| 79 | ItemStack itemstack1 = slot.getStack();
|
| 80 | itemstack = itemstack1.copy();
|
| 81 |
|
| 82 | if (index < this.horseInventory.getSizeInventory())
|
| 83 | {
|
| 84 | if (!this.mergeItemStack(itemstack1, this.horseInventory.getSizeInventory(), this.inventorySlots.size(), true))
|
| 85 | {
|
| 86 | return null;
|
| 87 | }
|
| 88 | }
|
| 89 | else if (this.getSlot(1).isItemValid(itemstack1) && !this.getSlot(1).getHasStack())
|
| 90 | {
|
| 91 | if (!this.mergeItemStack(itemstack1, 1, 2, false))
|
| 92 | {
|
| 93 | return null;
|
| 94 | }
|
| 95 | }
|
| 96 | else if (this.getSlot(0).isItemValid(itemstack1))
|
| 97 | {
|
| 98 | if (!this.mergeItemStack(itemstack1, 0, 1, false))
|
| 99 | {
|
| 100 | return null;
|
| 101 | }
|
| 102 | }
|
| 103 | else if (this.horseInventory.getSizeInventory() <= 2 || !this.mergeItemStack(itemstack1, 2, this.horseInventory.getSizeInventory(), false))
|
| 104 | {
|
| 105 | return null;
|
| 106 | }
|
| 107 |
|
| 108 | if (itemstack1.stackSize == 0)
|
| 109 | {
|
| 110 | slot.putStack((ItemStack)null);
|
| 111 | }
|
| 112 | else
|
| 113 | {
|
| 114 | slot.onSlotChanged();
|
| 115 | }
|
| 116 | }
|
| 117 |
|
| 118 | return itemstack;
|
| 119 | }
|
| 120 |
|
| 121 | /**
|
| 122 | * Called when the container is closed.
|
| 123 | */
|
| 124 | public void onContainerClosed(EntityPlayer playerIn)
|
| 125 | {
|
| 126 | super.onContainerClosed(playerIn);
|
| 127 | this.horseInventory.closeInventory(playerIn);
|
| 128 | }
|
| 129 | }
|
| 130 |
|