Guest User

Untitled

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