Guest User

CapCompContainer

a guest
Oct 27th, 2020
19
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class CapCompContainer extends Container {
  2. private int containerID;
  3. private int containerInd;
  4. private IInventory containerInv;
  5. private int numRows;
  6.  
  7. @OnlyIn(Dist.CLIENT)
  8. public int getInvInd() {
  9. return this.containerInd;
  10. }
  11.  
  12. public IInventory getInv() {
  13. return this.containerInv;
  14. }
  15.  
  16. public int getID() {
  17. return this.containerID;
  18. }
  19.  
  20. @OnlyIn(Dist.CLIENT)
  21. public int getNumRows() {
  22. return this.numRows;
  23. }
  24.  
  25. public CapCompContainer(ContainerType<?> type, int id, int ind, PlayerInventory player, int rows) {
  26. this(type, id, ind, player, new Inventory[]{
  27. new Inventory(9 * rows),
  28. new Inventory(9 * rows),
  29. new Inventory(9 * rows),
  30. new Inventory(9 * rows),
  31. new Inventory(9 * rows),
  32. new Inventory(9 * rows),
  33. new Inventory(9 * rows),
  34. new Inventory(9 * rows),
  35. new Inventory(9 * rows),
  36. new Inventory(9 * rows),
  37. new Inventory(9 * rows),
  38. new Inventory(9 * rows),
  39. new Inventory(9 * rows),
  40. new Inventory(9 * rows),
  41. new Inventory(9 * rows),
  42. new Inventory(9 * rows)
  43. }, rows);
  44.  
  45. this.containerInv = new Inventory(9 * rows);
  46. this.containerID = id;
  47. this.containerInd = ind;
  48. this.numRows = rows;
  49. }
  50.  
  51. public static CapCompContainer createMulti9X3(int id, PlayerInventory player) {
  52. return new CapCompContainer(ModContainerTypes.MULTI_9X3.get(), id, 0, player, 3);
  53. }
  54.  
  55. public CapCompContainer(ContainerType<?> type, int id, int ind, PlayerInventory playerInventoryIn, IInventory[] p_i50092_4_, int rows) {
  56. super(type, id);
  57. this.containerID = id;
  58. this.containerInd = ind;
  59. this.containerInv = p_i50092_4_[ind];
  60. assertInventorySize(p_i50092_4_[ind], rows * 9);
  61. this.numRows = rows;
  62. p_i50092_4_[ind].openInventory(playerInventoryIn.player);
  63. int i = (this.numRows - 4) * 18;
  64.  
  65. for(int j = 0; j < this.numRows; ++j) {
  66. for(int k = 0; k < 9; ++k) {
  67. this.addSlot(new Slot(p_i50092_4_[ind], k + j * 9, 8 + k * 18, 19 + j * 18));
  68. }
  69. }
  70.  
  71. for(int l = 0; l < 3; ++l) {
  72. for(int j1 = 0; j1 < 9; ++j1) {
  73. this.addSlot(new Slot(playerInventoryIn, j1 + l * 9 + 9, 8 + j1 * 18, 122 + l * 18 + i));
  74. }
  75. }
  76.  
  77. for(int i1 = 0; i1 < 9; ++i1) {
  78. this.addSlot(new Slot(playerInventoryIn, i1, 8 + i1 * 18, 180 + i));
  79. }
  80.  
  81. }
  82.  
  83. public boolean canInteractWith(PlayerEntity playerIn) {
  84. return this.containerInv.isUsableByPlayer(playerIn);
  85. }
  86.  
  87. public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) {
  88. ItemStack itemstack = ItemStack.EMPTY;
  89. Slot slot = this.inventorySlots.get(index);
  90. if (slot != null && slot.getHasStack()) {
  91. ItemStack itemstack1 = slot.getStack();
  92. itemstack = itemstack1.copy();
  93. if (index < this.numRows * 9) {
  94. if (!this.mergeItemStack(itemstack1, this.numRows * 9, this.inventorySlots.size(), true)) {
  95. return ItemStack.EMPTY;
  96. }
  97. } else if (!this.mergeItemStack(itemstack1, 0, this.numRows * 9, false)) {
  98. return ItemStack.EMPTY;
  99. }
  100.  
  101. if (itemstack1.isEmpty()) {
  102. slot.putStack(ItemStack.EMPTY);
  103. } else {
  104. slot.onSlotChanged();
  105. }
  106. }
  107. return itemstack;
  108. }
  109.  
  110. public void onContainerClosed(PlayerEntity playerIn) {
  111. super.onContainerClosed(playerIn);
  112. this.containerInv.closeInventory(playerIn);
  113. }
  114. }
  115.  
RAW Paste Data