Advertisement
Guest User

Slot.java

a guest
Feb 1st, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. public class Slot
  4. {
  5. /** The index of the slot in the inventory. */
  6. private final int slotIndex;
  7.  
  8. /** The inventory we want to extract a slot from. */
  9. public final IInventory inventory;
  10.  
  11. /** the id of the slot(also the index in the inventory arraylist) */
  12. public int slotNumber;
  13.  
  14. /** display position of the inventory slot on the screen x axis */
  15. public int xDisplayPosition;
  16.  
  17. /** display position of the inventory slot on the screen y axis */
  18. public int yDisplayPosition;
  19.  
  20. public Slot(IInventory par1IInventory, int par2, int par3, int par4)
  21. {
  22. this.inventory = par1IInventory;
  23. this.slotIndex = par2;
  24. this.xDisplayPosition = par3;
  25. this.yDisplayPosition = par4;
  26. }
  27.  
  28. /**
  29. * if par2 has more items than par1, onCrafting(item,countIncrease) is called
  30. */
  31. public void onSlotChange(ItemStack par1ItemStack, ItemStack par2ItemStack)
  32. {
  33. if (par1ItemStack != null && par2ItemStack != null)
  34. {
  35. if (par1ItemStack.itemID == par2ItemStack.itemID)
  36. {
  37. int var3 = par2ItemStack.stackSize - par1ItemStack.stackSize;
  38.  
  39. if (var3 > 0)
  40. {
  41. this.onCrafting(par1ItemStack, var3);
  42. }
  43. }
  44. }
  45. }
  46.  
  47. /**
  48. * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
  49. * internal count then calls onCrafting(item).
  50. */
  51. protected void onCrafting(ItemStack par1ItemStack, int par2) {}
  52.  
  53. /**
  54. * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
  55. */
  56. protected void onCrafting(ItemStack par1ItemStack) {}
  57.  
  58. public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack)
  59. {
  60. this.onSlotChanged();
  61. }
  62.  
  63. /**
  64. * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
  65. */
  66. public boolean isItemValid(ItemStack par1ItemStack)
  67. {
  68. return true;
  69. }
  70.  
  71. /**
  72. * Helper fnct to get the stack in the slot.
  73. */
  74. public ItemStack getStack()
  75. {
  76. return this.inventory.getStackInSlot(this.slotIndex);
  77. }
  78.  
  79. /**
  80. * Returns if this slot contains a stack.
  81. */
  82. public boolean getHasStack()
  83. {
  84. return this.getStack() != null;
  85. }
  86.  
  87. /**
  88. * Helper method to put a stack in the slot.
  89. */
  90. public void putStack(ItemStack par1ItemStack)
  91. {
  92. this.inventory.setInventorySlotContents(this.slotIndex, par1ItemStack);
  93. this.onSlotChanged();
  94. }
  95.  
  96. /**
  97. * Called when the stack in a Slot changes
  98. */
  99. public void onSlotChanged()
  100. {
  101. this.inventory.onInventoryChanged();
  102. }
  103.  
  104. /**
  105. * Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1 in the case
  106. * of armor slots)
  107. */
  108. public int getSlotStackLimit()
  109. {
  110. return this.inventory.getInventoryStackLimit();
  111. }
  112.  
  113. /**
  114. * Returns the icon index on items.png that is used as background image of the slot.
  115. */
  116. public Icon getBackgroundIconIndex()
  117. {
  118. return null;
  119. }
  120.  
  121. /**
  122. * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
  123. * stack.
  124. */
  125. public ItemStack decrStackSize(int par1)
  126. {
  127. return this.inventory.decrStackSize(this.slotIndex, par1);
  128. }
  129.  
  130. /**
  131. * returns true if this slot is in par2 of par1
  132. */
  133. public boolean isSlotInInventory(IInventory par1IInventory, int par2)
  134. {
  135. return par1IInventory == this.inventory && par2 == this.slotIndex;
  136. }
  137.  
  138. /**
  139. * Return whether this slot's stack can be taken from this slot.
  140. */
  141. public boolean canTakeStack(EntityPlayer par1EntityPlayer)
  142. {
  143. return true;
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement