Guest User

Untitled

a guest
Mar 26th, 2022
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. public class CrafterContainer extends AbstractContainerMenu {
  2. private static CrafterBlockEntity blockEntity;
  3. private final ContainerLevelAccess containerAccess;
  4.  
  5. public CrafterContainer(int id, Inventory playerInv) {
  6. this(id, playerInv, new ItemStackHandler(9), BlockPos.ZERO);
  7. }
  8. public CrafterContainer(int id, Inventory playerInv, IItemHandler slot, BlockPos pos) {
  9. super(TankModContainers.CRAFTER_CONTAINER.get(), id);
  10. this.containerAccess = ContainerLevelAccess.create(playerInv.player.level, pos);
  11. //Top Row
  12. addSlot(new SlotItemHandler(slot, 0, 44, 17));
  13. //Row 2
  14. addSlot(new SlotItemHandler(slot, 1, 26, 35));
  15. addSlot(new SlotItemHandler(slot, 2, 44, 35));
  16. addSlot(new SlotItemHandler(slot, 3, 62, 35));
  17. //Row 3
  18. addSlot(new SlotItemHandler(slot, 4, 26, 53));
  19. addSlot(new SlotItemHandler(slot, 5, 44, 53));
  20. addSlot(new SlotItemHandler(slot, 6, 62, 53));
  21. //Blueprint Slot
  22. addSlot(new SlotItemHandler(slot, 7, 98, 53));
  23. //Output Slot
  24. addSlot(new SlotItemHandler(slot, 8, 134, 35));
  25.  
  26.  
  27. for (int row = 0; row < 3; row++) {
  28. for (int col = 0; col < 9; col++) {
  29. this.addSlot(new Slot(playerInv, col + row * 9 + 9, 8 + col * 18, 166 - (4 - row) * 18 - 10));
  30. }
  31. }
  32. for (int col = 0; col < 9; col++) {
  33. this.addSlot(new Slot(playerInv, col, 8 + col * 18, 142));
  34. }
  35.  
  36.  
  37. }
  38. @Override
  39. public boolean stillValid(Player player) {
  40. return stillValid(this.containerAccess, player, TankModItems.CRAFTER_BLOCK.get());
  41. }
  42.  
  43.  
  44. public static MenuConstructor getServerContainer(CrafterBlockEntity crafter, BlockPos pos) {
  45. return (id, playerInv, player) -> new CrafterContainer(id, playerInv, crafter.inventory, pos);
  46. }
  47.  
  48. @Override
  49. public ItemStack quickMoveStack(Player player, int index) {
  50. var retStack = ItemStack.EMPTY;
  51. final Slot slot = getSlot(index);
  52. if (slot.hasItem()) {
  53. final ItemStack item = slot.getItem();
  54. retStack = item.copy();
  55. if (index < 27) {
  56. if (!moveItemStackTo(item, 27, this.slots.size(), true))
  57. return ItemStack.EMPTY;
  58. } else if (!moveItemStackTo(item, 0, 27, false))
  59. return ItemStack.EMPTY;
  60.  
  61. if (item.isEmpty()) {
  62. slot.set(ItemStack.EMPTY);
  63. } else {
  64. slot.setChanged();
  65. }
  66. }
  67.  
  68. return retStack;
  69. }
  70. }
  71.  
Add Comment
Please, Sign In to add comment