Advertisement
Guest User

Untitled

a guest
Jul 28th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. package binary404.mystictools.common.tile;
  2.  
  3. import net.minecraft.client.Minecraft;
  4. import net.minecraft.entity.player.PlayerEntity;
  5. import net.minecraft.entity.player.PlayerInventory;
  6. import net.minecraft.inventory.container.Container;
  7. import net.minecraft.inventory.container.ContainerType;
  8. import net.minecraft.inventory.container.Slot;
  9. import net.minecraft.item.ItemStack;
  10. import net.minecraft.network.PacketBuffer;
  11. import net.minecraftforge.items.IItemHandler;
  12. import net.minecraftforge.items.ItemStackHandler;
  13. import net.minecraftforge.items.SlotItemHandler;
  14.  
  15. import javax.annotation.Nonnull;
  16. import java.util.Stack;
  17.  
  18. public class UpgraderContainer extends Container {
  19.  
  20. protected final int invenSize;
  21.  
  22. public TileEntityUpgrader tileEntity;
  23.  
  24. public UpgraderContainer(int windowId, PlayerInventory playerInventory, PacketBuffer buffer) {
  25. this(windowId, playerInventory, new ItemStackHandler(3), (TileEntityUpgrader) Minecraft.getInstance().world.getTileEntity(buffer.readBlockPos()));
  26. }
  27.  
  28. public UpgraderContainer(int windowId, PlayerInventory inventory, IItemHandler handler, TileEntityUpgrader upgrader) {
  29. super(ModContainers.UPGRADER, windowId);
  30. invenSize = 3;
  31.  
  32. bindPlayerInventory(inventory);
  33. addSlot(new SlotItemHandler(handler, 0, 12, 16));
  34. addSlot(new SlotItemHandler(handler, 1, 70, 16));
  35. addSlot(new SlotOutput(handler, 2, 42, 57));
  36. this.tileEntity = upgrader;
  37. }
  38.  
  39. public class SlotOutput extends SlotItemHandler {
  40. public SlotOutput(IItemHandler itemHandler, int index, int xPosition, int yPosition) {
  41. super(itemHandler, index, xPosition, yPosition);
  42. }
  43.  
  44. @Override
  45. public boolean isItemValid(@Nonnull ItemStack stack) {
  46. return false;
  47. }
  48. }
  49.  
  50. @Override
  51. public boolean canInteractWith(PlayerEntity playerIn) {
  52. return true;
  53. }
  54.  
  55. protected void bindPlayerInventory(PlayerInventory playerInventory) {
  56. for (int i = 0; i < 3; ++i) {
  57. for (int j = 0; j < 9; ++j) {
  58. this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 6 + j * 16, 86 + i * 18));
  59. }
  60. }
  61.  
  62. for (int k = 0; k < 9; ++k) {
  63. this.addSlot(new Slot(playerInventory, k, 6 + k * 16, 144));
  64. }
  65. }
  66.  
  67. @Override
  68. @Nonnull
  69. public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) {
  70. ItemStack itemstack = ItemStack.EMPTY;
  71. Slot slot = (Slot) this.inventorySlots.get(index);
  72.  
  73. if (slot != null && slot.getHasStack()) {
  74. ItemStack itemstack1 = slot.getStack();
  75. itemstack = itemstack1.copy();
  76.  
  77. if (index < invenSize) {
  78. if (!this.mergeItemStack(itemstack1, invenSize, this.inventorySlots.size(), true)) {
  79. return ItemStack.EMPTY;
  80. }
  81. } else if (!this.mergeItemStack(itemstack1, 0, invenSize, false)) {
  82. return ItemStack.EMPTY;
  83. }
  84.  
  85. if (itemstack1.getCount() == 0) {
  86. slot.putStack(ItemStack.EMPTY);
  87. } else {
  88. slot.onSlotChanged();
  89. }
  90. }
  91.  
  92. return itemstack;
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement