Guest User

Untitled

a guest
Nov 15th, 2018
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 KB | None | 0 0
  1. package com.TheRPGAdventurer.ROTD.client.inventory;
  2.  
  3. import com.TheRPGAdventurer.ROTD.client.initialization.ModItems;
  4. import com.TheRPGAdventurer.ROTD.server.entity.EntityTameableDragon;
  5.  
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.init.Blocks;
  8. import net.minecraft.init.Items;
  9. import net.minecraft.inventory.Container;
  10. import net.minecraft.inventory.IInventory;
  11. import net.minecraft.inventory.Slot;
  12. import net.minecraft.item.Item;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraftforge.fml.relauncher.Side;
  15. import net.minecraftforge.fml.relauncher.SideOnly;
  16.  
  17. public class ContainerDragon extends Container {
  18. private final IInventory dragonInv;
  19. private final EntityTameableDragon dragon;
  20. private final EntityPlayer player;
  21. public static final int chestStartIndex = 3;
  22.  
  23. public ContainerDragon(final EntityTameableDragon dragon, EntityPlayer player) {
  24. this.dragonInv = dragon.dragonInv;
  25. this.dragon = dragon;
  26. this.player = player;
  27. int b0 = 3;
  28. int i = (b0 - 4) * 18;
  29. final int inventoryColumn = 9;
  30. dragonInv.openInventory(player);
  31. int j = -21;
  32.  
  33. // location of the slot for the saddle in the dragon inventory
  34. this.addSlotToContainer(new Slot(dragonInv, 0, 8, 18) {
  35.  
  36. public boolean isItemValid(ItemStack stack) {
  37. return stack.getItem() == Items.SADDLE && !this.getHasStack();
  38. }
  39.  
  40. @SideOnly(Side.CLIENT)
  41. public boolean isEnabled() {
  42. return true;
  43. }
  44.  
  45. });
  46.  
  47. // location of the slot for chest in the dragon inventory
  48. this.addSlotToContainer(new Slot(dragonInv, 1, 8, 36) {
  49.  
  50. public boolean isItemValid(ItemStack stack) {
  51. return stack.getItem() == Item.getItemFromBlock(Blocks.CHEST) && !this.getHasStack();
  52. }
  53.  
  54. public void onSlotChanged() {
  55. ContainerDragon.this.dragon.refreshInventory();
  56. }
  57.  
  58. @SideOnly(Side.CLIENT)
  59. public boolean isEnabled() {
  60. return true;
  61. }
  62. });
  63.  
  64. // location of the slot for armor in the dragon inventory
  65. this.addSlotToContainer(new Slot(dragonInv, 2, 8, 53) {
  66.  
  67. public boolean isItemValid(ItemStack stack) {
  68. return dragon.getIntFromArmor(stack) != 0;
  69. }
  70.  
  71. });
  72.  
  73. // location of the slot for the banner1 in the dragon inventory
  74. this.addSlotToContainer(new Slot(dragonInv, 31, 153, 18) {
  75.  
  76. public boolean isItemValid(ItemStack stack) {
  77. return stack.getItem() == Items.BANNER && !this.getHasStack();
  78. }
  79.  
  80. @SideOnly(Side.CLIENT)
  81. public boolean isEnabled() {
  82. return true;
  83. }
  84.  
  85. });
  86.  
  87. // location of the slot for the dragon banner2 in the dragon inventory
  88. this.addSlotToContainer(new Slot(dragonInv, 32, 153, 36) {
  89.  
  90. public boolean isItemValid(ItemStack stack) {
  91. return stack.getItem() == Items.BANNER && !this.getHasStack();
  92. }
  93.  
  94. @SideOnly(Side.CLIENT)
  95. public boolean isEnabled() {
  96. return true;
  97. }
  98.  
  99. });
  100.  
  101. // location of the dragon's inventory when chested in the dragon inventory
  102. for (int k = 0; k < 3; ++k) {
  103. for (int l = 0; l < 9; ++l) {
  104. this.addSlotToContainer(new Slot(dragonInv, chestStartIndex + l + k * inventoryColumn, 8 + l * 18, 75 + k * 18) {
  105.  
  106. @SideOnly(Side.CLIENT)
  107. public boolean isEnabled() {
  108. return ContainerDragon.this.dragon.isChested();
  109. }
  110.  
  111. });
  112. }
  113. }
  114.  
  115. int j1;
  116. int k;
  117.  
  118. // location of the player's inventory in the dragon inventory
  119. for (j = 0; j < 3; ++j) {
  120. for (k = 0; k < 9; ++k) {
  121. this.addSlotToContainer(new Slot(player.inventory, k + j * 9 + 9, 8 + k * 18, 150 + j * 18 + i));
  122. }
  123. }
  124.  
  125. for (j = 0; j < 9; ++j) {
  126. this.addSlotToContainer(new Slot(player.inventory, j, 8 + j * 18, 208 + i));
  127. }
  128.  
  129. }
  130.  
  131. public boolean canInteractWith(EntityPlayer playerIn) {
  132. return this.dragonInv.isUsableByPlayer(playerIn) && this.dragon.isEntityAlive() && this.dragon.getDistanceToEntity(playerIn) < 8.0F;
  133. }
  134.  
  135. public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
  136. ItemStack itemstack = ItemStack.EMPTY;
  137. Slot slot = (Slot) this.inventorySlots.get(index);
  138.  
  139. if (slot != null && slot.getHasStack()) {
  140. ItemStack itemstack1 = slot.getStack();
  141. itemstack = itemstack1.copy();
  142.  
  143. if (index < this.dragonInv.getSizeInventory()) {
  144. if (!this.mergeItemStack(itemstack1, this.dragonInv.getSizeInventory(), this.inventorySlots.size(), true)) {
  145. return ItemStack.EMPTY;
  146. }
  147. } else if (this.getSlot(2).isItemValid(itemstack1)) {
  148. if (!this.mergeItemStack(itemstack1, 2, 3, false)) {
  149. return ItemStack.EMPTY;
  150. }
  151. } else if (this.getSlot(1).isItemValid(itemstack1) && !this.getSlot(1).getHasStack()) {
  152. if (!this.mergeItemStack(itemstack1, 1, 2, false)) {
  153. return ItemStack.EMPTY;
  154. }
  155. } else if (this.getSlot(0).isItemValid(itemstack1)) {
  156. if (!this.mergeItemStack(itemstack1, 0, 1, false)) {
  157. return ItemStack.EMPTY;
  158. }
  159. } else if (this.dragonInv.getSizeInventory() <= chestStartIndex || !this.mergeItemStack(itemstack1, chestStartIndex, this.dragonInv.getSizeInventory(), false)) {
  160. return ItemStack.EMPTY;
  161. }
  162.  
  163. if (itemstack1.isEmpty()) {
  164. slot.putStack(ItemStack.EMPTY);
  165. } else {
  166. slot.onSlotChanged();
  167. }
  168. }
  169.  
  170. return itemstack;
  171. }
  172.  
  173. /**
  174. * Called when the container is closed.
  175. */
  176. public void onContainerClosed(EntityPlayer playerIn) {
  177. super.onContainerClosed(playerIn);
  178. this.dragonInv.closeInventory(playerIn);
  179. }
  180. }
Advertisement
Add Comment
Please, Sign In to add comment