Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. public class ContainerDeck extends Container
  2. {
  3. private final int numRows;
  4.  
  5. public ContainerDeck(InventoryPlayer playerInv, EntityPlayer player)
  6. {
  7. this.numRows = 2;
  8.  
  9. for(int y = 0; y < this.numRows; y++)
  10. {
  11. for(int x = 0; x < 9; x++)
  12. {
  13. this.addSlotToContainer(new SlotItemInv(player.getHeldItemMainhand().getCapability(DeckDataCapability.CAPABILITY, null), x + y * 9, 8 + x * 18, (16 * y + 16) + y * 2));
  14. }
  15. }
  16.  
  17. for (int i = 0; i < 3; ++i)
  18. {
  19. for (int j = 0; j < 9; ++j)
  20. {
  21. this.addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
  22. }
  23. }
  24.  
  25. for (int k = 0; k < 9; ++k)
  26. {
  27. this.addSlotToContainer(new Slot(playerInv, k, 8 + k * 18, 142));
  28. }
  29. }
  30.  
  31. /**
  32. * Take a stack from the specified inventory slot.
  33. */
  34. @Nullable
  35. public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
  36. {
  37. ItemStack itemstack = null;
  38. Slot slot = (Slot) this.inventorySlots.get(index);
  39.  
  40. if (slot != null && slot.getHasStack())
  41. {
  42. ItemStack itemstack1 = slot.getStack();
  43. itemstack = itemstack1.copy();
  44.  
  45. if (index < this.numRows * 9)
  46. {
  47. if (!this.mergeItemStack(itemstack1, this.numRows * 9, this.inventorySlots.size(), true))
  48. {
  49. return null;
  50. }
  51. } else if (!this.mergeItemStack(itemstack1, 0, this.numRows * 9, false))
  52. {
  53. return null;
  54. }
  55.  
  56. if (itemstack1.stackSize == 0)
  57. {
  58. slot.putStack((ItemStack) null);
  59. } else
  60. {
  61. slot.onSlotChanged();
  62. }
  63.  
  64. if (itemstack1.stackSize == itemstack.stackSize)
  65. {
  66. return null;
  67. }
  68.  
  69. slot.onPickupFromSlot(playerIn, itemstack1);
  70. }
  71.  
  72. return itemstack;
  73. }
  74.  
  75. @Override
  76. public boolean canInteractWith(EntityPlayer playerIn)
  77. {
  78. return true;
  79. }
  80.  
  81. @Override
  82. public ItemStack slotClick(int slot, int button, ClickType clickTypeIn, EntityPlayer player)
  83. {
  84. if (slot >= 0 && getSlot(slot) != null
  85. && getSlot(slot).getStack() == player.getHeldItemMainhand())
  86. {
  87. return null;
  88. }
  89. return super.slotClick(slot, button, clickTypeIn, player);
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement