Advertisement
Guest User

Contian_Jamiga

a guest
Apr 12th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. package aJamigaPack1;
  2.  
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.entity.player.InventoryPlayer;
  5. import net.minecraft.inventory.Container;
  6. import net.minecraft.inventory.Slot;
  7. import net.minecraft.item.ItemArmor;
  8. import net.minecraft.item.ItemStack;
  9.  
  10. public class ContainerCustomPlayer extends Container
  11. {
  12. /** Avoid magic numbers! This will greatly reduce the chance of you making errors in 'transferStackInSlot' method */
  13. private static final int ARMOR_START = InventoryCustomPlayer.INV_SIZE, ARMOR_END = ARMOR_START+3,
  14. INV_START = ARMOR_END+1, INV_END = INV_START+26, HOTBAR_START = INV_END+1,
  15. HOTBAR_END = HOTBAR_START+8;
  16.  
  17. public ContainerCustomPlayer(EntityPlayer player, InventoryPlayer inventoryPlayer, InventoryCustomPlayer inventoryCustom)
  18. {
  19. int i;
  20.  
  21. // Add CUSTOM slots - we'll just add two for now, both of the same type.
  22. // Make a new Slot class for each different item type you want to add
  23. this.addSlotToContainer(new SlotCustom(inventoryCustom, 0, 80, 8));
  24. this.addSlotToContainer(new SlotCustom(inventoryCustom, 1, 80, 26));
  25.  
  26. // Add ARMOR slots; note you need to make a public version of SlotArmor
  27. // just copy and paste the vanilla code into a new class and change what you need
  28. for (i = 0; i < 4; ++i)
  29. {
  30. this.addSlotToContainer(new SlotArmor(player, inventoryPlayer, inventoryPlayer.getSizeInventory() - 1 - i, 8, 8 + i * 18, i));
  31. }
  32.  
  33. // Add vanilla PLAYER INVENTORY - just copied/pasted from vanilla classes
  34. for (i = 0; i < 3; ++i)
  35. {
  36. for (int j = 0; j < 9; ++j)
  37. {
  38. this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
  39. }
  40. }
  41.  
  42. // Add ACTION BAR - just copied/pasted from vanilla classes
  43. for (i = 0; i < 9; ++i)
  44. {
  45. this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
  46. }
  47. }
  48.  
  49. /**
  50. * This should always return true, since custom inventory can be accessed from anywhere
  51. */
  52. @Override
  53. public boolean canInteractWith(EntityPlayer player)
  54. {
  55. return true;
  56. }
  57.  
  58. /**
  59. * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
  60. * Basically the same as every other container I make, since I define the same constant indices for all of them
  61. */
  62. public ItemStack transferStackInSlot(EntityPlayer player, int par2)
  63. {
  64. ItemStack itemstack = null;
  65. Slot slot = (Slot) this.inventorySlots.get(par2);
  66.  
  67. if (slot != null && slot.getHasStack())
  68. {
  69. ItemStack itemstack1 = slot.getStack();
  70. itemstack = itemstack1.copy();
  71.  
  72. // Either armor slot or custom item slot was clicked
  73. if (par2 < INV_START)
  74. {
  75. // try to place in player inventory / action bar
  76. if (!this.mergeItemStack(itemstack1, INV_START, HOTBAR_END + 1, true))
  77. {
  78. return null;
  79. }
  80.  
  81. slot.onSlotChange(itemstack1, itemstack);
  82. }
  83. // Item is in inventory / hotbar, try to place either in custom or armor slots
  84. else
  85. {
  86. // if item is our custom item
  87. if (itemstack1.getItem() instanceof MyCraftWing1)
  88. {
  89. if (!this.mergeItemStack(itemstack1, 0, InventoryCustomPlayer.INV_SIZE, false))
  90. {
  91. return null;
  92. }
  93. }
  94. // if item is armor
  95. else if (itemstack1.getItem() instanceof ItemArmor)
  96. {
  97. int type = ((ItemArmor) itemstack1.getItem()).armorType;
  98. if (!this.mergeItemStack(itemstack1, ARMOR_START + type, ARMOR_START + type + 1, false))
  99. {
  100. return null;
  101. }
  102. }
  103. // item in player's inventory, but not in action bar
  104. else if (par2 >= INV_START && par2 < HOTBAR_START)
  105. {
  106. // place in action bar
  107. if (!this.mergeItemStack(itemstack1, HOTBAR_START, HOTBAR_START + 1, false))
  108. {
  109. return null;
  110. }
  111. }
  112. // item in action bar - place in player inventory
  113. else if (par2 >= HOTBAR_START && par2 < HOTBAR_END + 1)
  114. {
  115. if (!this.mergeItemStack(itemstack1, INV_START, INV_END + 1, false))
  116. {
  117. return null;
  118. }
  119. }
  120. }
  121.  
  122. if (itemstack1.stackSize == 0)
  123. {
  124. slot.putStack((ItemStack) null);
  125. }
  126. else
  127. {
  128. slot.onSlotChanged();
  129. }
  130.  
  131. if (itemstack1.stackSize == itemstack.stackSize)
  132. {
  133. return null;
  134. }
  135.  
  136. slot.onPickupFromSlot(player, itemstack1);
  137. }
  138.  
  139. return itemstack;
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement