Advertisement
ButterAleks

container

Jan 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. package com.ButterAleks.RandomIdeas.blocks.container;
  2.  
  3. import com.ButterAleks.RandomIdeas.blocks.tileentity.TileEntityRainbowChestBlock;
  4.  
  5. import net.minecraft.entity.player.EntityPlayer;
  6. import net.minecraft.entity.player.InventoryPlayer;
  7. import net.minecraft.inventory.Container;
  8. import net.minecraft.inventory.Slot;
  9. import net.minecraft.item.ItemStack;
  10. import net.minecraft.util.math.BlockPos;
  11.  
  12. public class ContainerRainbowChestBlock extends Container
  13. {
  14. private final int numRows;
  15. private final TileEntityRainbowChestBlock chestInventory;
  16.  
  17. public ContainerRainbowChestBlock(InventoryPlayer playerInv, TileEntityRainbowChestBlock tileEntityRainbowChestBlock, EntityPlayer player)
  18. {
  19. this.chestInventory = tileEntityRainbowChestBlock;
  20. this.numRows = tileEntityRainbowChestBlock.getSizeInventory() / 9;
  21. tileEntityRainbowChestBlock.openInventory(player);
  22.  
  23. for(int i = 0; i < this.numRows; ++ i)
  24. {
  25. for(int j = 0; j < 9; ++ j)
  26. {
  27. this.addSlotToContainer(new Slot(tileEntityRainbowChestBlock, j + i*9, 8 + j*18, 18 + i*18));
  28. }
  29. }
  30. for(int y = 0; y < 3; y++)
  31. {
  32. for(int x = 0; x < 9; x++)
  33. {
  34. this.addSlotToContainer(new Slot(playerInv, x + y*9 + 9, 8 + x*18, 175 + y*18));
  35. }
  36. }
  37. for(int x = 0; x < 9; x++)
  38. {
  39. this.addSlotToContainer(new Slot(playerInv, x, 8 + x*18, 233));
  40. }
  41.  
  42. }
  43. @Override
  44. public boolean canInteractWith(EntityPlayer playerIn)
  45. {
  46. return this.chestInventory.isUsableByPlayer(playerIn);
  47. }
  48.  
  49. @Override
  50. public void onContainerClosed(EntityPlayer playerIn)
  51. {
  52. super.onContainerClosed(playerIn);
  53. chestInventory.closeInventory(playerIn);
  54. }
  55.  
  56. @Override
  57. public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
  58. {
  59. ItemStack itemstack = ItemStack.EMPTY;
  60. Slot slot = this.inventorySlots.get(index);
  61.  
  62. if (slot != null && slot.getHasStack())
  63. {
  64. ItemStack itemstack1 = slot.getStack();
  65. itemstack = itemstack1.copy();
  66.  
  67. if (index < this.numRows * 9)
  68. {
  69. if (!this.mergeItemStack(itemstack1, this.numRows * 9, this.inventorySlots.size(), true))
  70. {
  71. return ItemStack.EMPTY;
  72. }
  73. }
  74. else if (!this.mergeItemStack(itemstack1, 0, this.numRows * 9, false))
  75. {
  76. return ItemStack.EMPTY;
  77. }
  78.  
  79. if (itemstack1.isEmpty())
  80. {
  81. slot.putStack(ItemStack.EMPTY);
  82. }
  83. else
  84. {
  85. slot.onSlotChanged();
  86. }
  87. }
  88.  
  89. return itemstack;
  90. }
  91. public TileEntityRainbowChestBlock getChestInventory()
  92. {
  93. return this.chestInventory;
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement