Advertisement
flidiii

Untitled

Feb 20th, 2025
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. package org.example.ecosub;
  2.  
  3. import net.minecraftforge.items.ItemStackHandler;
  4. import net.minecraftforge.items.IItemHandler;
  5.  
  6. import net.minecraft.world.level.block.entity.BlockEntity;
  7. import net.minecraft.world.level.Level;
  8. import net.minecraft.world.item.ItemStack;
  9. import net.minecraft.world.inventory.Slot;
  10. import net.minecraft.world.inventory.ContainerLevelAccess;
  11. import net.minecraft.world.inventory.AbstractContainerMenu;
  12. import net.minecraft.world.entity.player.Player;
  13. import net.minecraft.world.entity.player.Inventory;
  14. import net.minecraft.world.entity.Entity;
  15. import net.minecraft.network.FriendlyByteBuf;
  16. import net.minecraft.core.BlockPos;
  17.  
  18. import java.util.function.Supplier;
  19. import java.util.Map;
  20. import java.util.HashMap;
  21.  
  22. public class WalletguiMenu extends AbstractContainerMenu implements Supplier<Map<Integer, Slot>> {
  23. public final static HashMap<String, Object> guistate = new HashMap<>();
  24. public final Level world;
  25. public final Player entity;
  26. public int x, y, z;
  27. private ContainerLevelAccess access = ContainerLevelAccess.NULL;
  28. private IItemHandler internal;
  29. private final Map<Integer, Slot> customSlots = new HashMap<>();
  30. private boolean bound = false;
  31. private Supplier<Boolean> boundItemMatcher = null;
  32. private Entity boundEntity = null;
  33. private BlockEntity boundBlockEntity = null;
  34. public int balance;
  35.  
  36. public WalletguiMenu(int id, Inventory inv, FriendlyByteBuf extraData, FriendlyByteBuf balanceData) {
  37. super(EcosubModMenus.WALLETGUI.get(), id);
  38. this.entity = inv.player;
  39. this.world = inv.player.level();
  40. this.internal = new ItemStackHandler(0);
  41. BlockPos pos = null;
  42. if (extraData != null) {
  43. pos = extraData.readBlockPos();
  44. this.x = pos.getX();
  45. this.y = pos.getY();
  46. this.z = pos.getZ();
  47. access = ContainerLevelAccess.create(world, pos);
  48. balance = balanceData.readInt();
  49. }
  50. System.out.println(1 + " " + balance);
  51. }
  52.  
  53. public WalletguiMenu(int id, Inventory inv, FriendlyByteBuf extraData) {
  54. super(EcosubModMenus.WALLETGUI.get(), id);
  55. this.entity = inv.player;
  56. this.world = inv.player.level();
  57. this.internal = new ItemStackHandler(0);
  58. BlockPos pos = null;
  59. if (extraData != null) {
  60. pos = extraData.readBlockPos();
  61. this.x = pos.getX();
  62. this.y = pos.getY();
  63. this.z = pos.getZ();
  64. access = ContainerLevelAccess.create(world, pos);
  65. }
  66. }
  67.  
  68. @Override
  69. public boolean stillValid(Player player) {
  70. if (this.bound) {
  71. if (this.boundItemMatcher != null)
  72. return this.boundItemMatcher.get();
  73. else if (this.boundBlockEntity != null)
  74. return AbstractContainerMenu.stillValid(this.access, player, this.boundBlockEntity.getBlockState().getBlock());
  75. else if (this.boundEntity != null)
  76. return this.boundEntity.isAlive();
  77. }
  78. return true;
  79. }
  80.  
  81. @Override
  82. public ItemStack quickMoveStack(Player playerIn, int index) {
  83. return ItemStack.EMPTY;
  84. }
  85.  
  86.  
  87. public Map<Integer, Slot> get() {
  88. return customSlots;
  89. }
  90. }
  91.  
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement