Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. package jinkhya.pinkmod.pinkblocks.pinkgrinder;
  2.  
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.inventory.Container;
  5. import net.minecraft.inventory.IInventory;
  6. import net.minecraft.inventory.Slot;
  7. import net.minecraft.item.ItemStack;
  8. import net.minecraftforge.items.CapabilityItemHandler;
  9. import net.minecraftforge.items.IItemHandler;
  10. import net.minecraftforge.items.SlotItemHandler;
  11.  
  12.  
  13. public class ContainerPinkGrinder extends Container {
  14.  
  15. private TilePinkGrinder te;
  16. public ContainerPinkGrinder(IInventory playerInventory, TilePinkGrinder te) {
  17. this.te = te;
  18.  
  19. addOwnSlots();
  20. addPlayerSlots(playerInventory);
  21. }
  22.  
  23. private void addPlayerSlots(IInventory playerInventory) {
  24. // Slots for the main inventory
  25. for (int row = 0; row < 3; ++row) {
  26. for (int col = 0; col < 9; ++col) {
  27. int x = 10 + col * 18;
  28. int y = row * 18 + 70;
  29. this.addSlotToContainer(new Slot(playerInventory, col + row * 9 + 9, x, y));
  30. }
  31. }
  32.  
  33. // Slots for the hotbar
  34. for (int row = 0; row < 9; ++row) {
  35. int x = 10 + row * 18;
  36. int y = 58 + 70;
  37. this.addSlotToContainer(new Slot(playerInventory, row, x, y));
  38. }
  39. }
  40.  
  41.  
  42. private void addOwnSlots() {
  43. IItemHandler itemHandler = this.te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
  44. int x = 10;
  45. int y = 26;
  46.  
  47. int slotIndex = 0;
  48. addSlotToContainer(new SlotItemHandler(itemHandler, slotIndex++, x, y));
  49. x += 18;
  50. addSlotToContainer(new SlotItemHandler(itemHandler, slotIndex++, x, y));
  51. x += 18;
  52. addSlotToContainer(new SlotItemHandler(itemHandler, slotIndex++, x, y));
  53.  
  54. x = 118;
  55. addSlotToContainer(new SlotItemHandler(itemHandler, slotIndex++, x, y));
  56. x += 18;
  57. addSlotToContainer(new SlotItemHandler(itemHandler, slotIndex++, x, y));
  58. x += 18;
  59. addSlotToContainer(new SlotItemHandler(itemHandler, slotIndex++, x, y));
  60. }
  61.  
  62. @Override
  63. public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
  64. ItemStack itemstack = ItemStack.EMPTY;
  65. Slot slot = this.inventorySlots.get(index);
  66.  
  67. if (slot != null && slot.getHasStack()) {
  68. ItemStack itemstack1 = slot.getStack();
  69. itemstack = itemstack1.copy();
  70.  
  71. if (index < TilePinkGrinder.SIZE) {
  72. if (!this.mergeItemStack(itemstack1, TilePinkGrinder.SIZE, this.inventorySlots.size(), true)) {
  73. return ItemStack.EMPTY;
  74. }
  75. } else if (!this.mergeItemStack(itemstack1, 0, TilePinkGrinder.SIZE, false)) {
  76. return ItemStack.EMPTY;
  77. }
  78.  
  79. if (itemstack1.isEmpty()) {
  80. slot.putStack(ItemStack.EMPTY);
  81. } else {
  82. slot.onSlotChanged();
  83. }
  84. }
  85.  
  86. return itemstack;
  87. }
  88.  
  89. @Override
  90. public boolean canInteractWith(EntityPlayer playerIn) {
  91.  
  92. return te.canInteractWith(playerIn);
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement