| 1 | package net.minecraft.inventory;
|
| 2 |
|
| 3 | import net.minecraft.entity.player.EntityPlayer;
|
| 4 | import net.minecraft.item.ItemStack;
|
| 5 |
|
| 6 | public class Slot
|
| 7 | {
|
| 8 | /** The index of the slot in the inventory. */
|
| 9 | private final int slotIndex;
|
| 10 |
|
| 11 | /** The inventory we want to extract a slot from. */
|
| 12 | public final IInventory inventory;
|
| 13 |
|
| 14 | /** the id of the slot(also the index in the inventory arraylist) */
|
| 15 | public int slotNumber;
|
| 16 |
|
| 17 | /** display position of the inventory slot on the screen x axis */
|
| 18 | public int xDisplayPosition;
|
| 19 |
|
| 20 | /** display position of the inventory slot on the screen y axis */
|
| 21 | public int yDisplayPosition;
|
| 22 |
|
| 23 | public Slot(IInventory inventoryIn, int index, int xPosition, int yPosition)
|
| 24 | {
|
| 25 | this.inventory = inventoryIn;
|
| 26 | this.slotIndex = index;
|
| 27 | this.xDisplayPosition = xPosition;
|
| 28 | this.yDisplayPosition = yPosition;
|
| 29 | }
|
| 30 |
|
| 31 | /**
|
| 32 | * if par2 has more items than par1, onCrafting(item,countIncrease) is called
|
| 33 | */
|
| 34 | public void onSlotChange(ItemStack p_75220_1_, ItemStack p_75220_2_)
|
| 35 | {
|
| 36 | if (p_75220_1_ != null && p_75220_2_ != null)
|
| 37 | {
|
| 38 | if (p_75220_1_.getItem() == p_75220_2_.getItem())
|
| 39 | {
|
| 40 | int i = p_75220_2_.stackSize - p_75220_1_.stackSize;
|
| 41 |
|
| 42 | if (i > 0)
|
| 43 | {
|
| 44 | this.onCrafting(p_75220_1_, i);
|
| 45 | }
|
| 46 | }
|
| 47 | }
|
| 48 | }
|
| 49 |
|
| 50 | /**
|
| 51 | * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
|
| 52 | * internal count then calls onCrafting(item).
|
| 53 | */
|
| 54 | protected void onCrafting(ItemStack stack, int amount)
|
| 55 | {
|
| 56 | }
|
| 57 |
|
| 58 | /**
|
| 59 | * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
|
| 60 | */
|
| 61 | protected void onCrafting(ItemStack stack)
|
| 62 | {
|
| 63 | }
|
| 64 |
|
| 65 | public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack)
|
| 66 | {
|
| 67 | this.onSlotChanged();
|
| 68 | }
|
| 69 |
|
| 70 | /**
|
| 71 | * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
|
| 72 | */
|
| 73 | public boolean isItemValid(ItemStack stack)
|
| 74 | {
|
| 75 | return true;
|
| 76 | }
|
| 77 |
|
| 78 | /**
|
| 79 | * Helper fnct to get the stack in the slot.
|
| 80 | */
|
| 81 | public ItemStack getStack()
|
| 82 | {
|
| 83 | return this.inventory.getStackInSlot(this.slotIndex);
|
| 84 | }
|
| 85 |
|
| 86 | /**
|
| 87 | * Returns if this slot contains a stack.
|
| 88 | */
|
| 89 | public boolean getHasStack()
|
| 90 | {
|
| 91 | return this.getStack() != null;
|
| 92 | }
|
| 93 |
|
| 94 | /**
|
| 95 | * Helper method to put a stack in the slot.
|
| 96 | */
|
| 97 | public void putStack(ItemStack stack)
|
| 98 | {
|
| 99 | this.inventory.setInventorySlotContents(this.slotIndex, stack);
|
| 100 | this.onSlotChanged();
|
| 101 | }
|
| 102 |
|
| 103 | /**
|
| 104 | * Called when the stack in a Slot changes
|
| 105 | */
|
| 106 | public void onSlotChanged()
|
| 107 | {
|
| 108 | this.inventory.markDirty();
|
| 109 | }
|
| 110 |
|
| 111 | /**
|
| 112 | * Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1 in the case
|
| 113 | * of armor slots)
|
| 114 | */
|
| 115 | public int getSlotStackLimit()
|
| 116 | {
|
| 117 | return this.inventory.getInventoryStackLimit();
|
| 118 | }
|
| 119 |
|
| 120 | public int getItemStackLimit(ItemStack stack)
|
| 121 | {
|
| 122 | return this.getSlotStackLimit();
|
| 123 | }
|
| 124 |
|
| 125 | public String getSlotTexture()
|
| 126 | {
|
| 127 | return null;
|
| 128 | }
|
| 129 |
|
| 130 | /**
|
| 131 | * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
|
| 132 | * stack.
|
| 133 | */
|
| 134 | public ItemStack decrStackSize(int amount)
|
| 135 | {
|
| 136 | return this.inventory.decrStackSize(this.slotIndex, amount);
|
| 137 | }
|
| 138 |
|
| 139 | /**
|
| 140 | * returns true if the slot exists in the given inventory and location
|
| 141 | */
|
| 142 | public boolean isHere(IInventory inv, int slotIn)
|
| 143 | {
|
| 144 | return inv == this.inventory && slotIn == this.slotIndex;
|
| 145 | }
|
| 146 |
|
| 147 | /**
|
| 148 | * Return whether this slot's stack can be taken from this slot.
|
| 149 | */
|
| 150 | public boolean canTakeStack(EntityPlayer playerIn)
|
| 151 | {
|
| 152 | return true;
|
| 153 | }
|
| 154 |
|
| 155 | /**
|
| 156 | * Actualy only call when we want to render the white square effect over the slots. Return always True, except for
|
| 157 | * the armor slot of the Donkey/Mule (we can't interact with the Undead and Skeleton horses)
|
| 158 | */
|
| 159 | public boolean canBeHovered()
|
| 160 | {
|
| 161 | return true;
|
| 162 | }
|
| 163 | }
|
| 164 |
|