Guest User

Untitled

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