Guest User

Untitled

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