diff options
Diffstat (limited to 'src/main/java/lv/enes/mc/eris_alchemy/menu/AlchemicalChestMenu.java')
| -rw-r--r-- | src/main/java/lv/enes/mc/eris_alchemy/menu/AlchemicalChestMenu.java | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/menu/AlchemicalChestMenu.java b/src/main/java/lv/enes/mc/eris_alchemy/menu/AlchemicalChestMenu.java new file mode 100644 index 0000000..e4135c9 --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/menu/AlchemicalChestMenu.java | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.menu; | ||
| 2 | |||
| 3 | import jakarta.annotation.Nonnull; | ||
| 4 | import net.minecraft.world.Container; | ||
| 5 | import net.minecraft.world.SimpleContainer; | ||
| 6 | import net.minecraft.world.entity.player.Inventory; | ||
| 7 | import net.minecraft.world.entity.player.Player; | ||
| 8 | import net.minecraft.world.inventory.AbstractContainerMenu; | ||
| 9 | import net.minecraft.world.inventory.Slot; | ||
| 10 | import net.minecraft.world.item.ItemStack; | ||
| 11 | |||
| 12 | public class AlchemicalChestMenu extends AbstractContainerMenu { | ||
| 13 | private static final int WIDTH = 13; | ||
| 14 | private static final int HEIGHT = 8; | ||
| 15 | |||
| 16 | private final Container container; | ||
| 17 | |||
| 18 | public AlchemicalChestMenu(int syncId, Inventory playerInventory) { | ||
| 19 | this(syncId, playerInventory, new SimpleContainer(WIDTH * HEIGHT)); | ||
| 20 | } | ||
| 21 | |||
| 22 | public AlchemicalChestMenu(int syncId, Inventory playerInventory, Container inventory) { | ||
| 23 | super(ErisAlchemyMenus.ALCHEMICAL_CHEST, syncId); | ||
| 24 | checkContainerSize(inventory, WIDTH * HEIGHT); | ||
| 25 | |||
| 26 | this.container = inventory; | ||
| 27 | inventory.startOpen(playerInventory.player); | ||
| 28 | |||
| 29 | var x_off = 8; | ||
| 30 | var y_off = 8; | ||
| 31 | |||
| 32 | for (var y = 0; y < HEIGHT; y++) { | ||
| 33 | for (var x = 0; x < WIDTH; x++ ) { | ||
| 34 | addSlot(new Slot(inventory, y * WIDTH + x, x_off + x * 18, y_off + y * 18)); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | x_off = 44; | ||
| 39 | y_off = 155; | ||
| 40 | |||
| 41 | for (var y = 0; y < 3; y++) { | ||
| 42 | for (var x = 0; x < 9; x++) { | ||
| 43 | addSlot(new Slot(playerInventory, y * 9 + x + 9, x_off + x * 18, y_off + y * 18)); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | y_off = 213; | ||
| 48 | |||
| 49 | for (var x = 0; x < 9; x++) { | ||
| 50 | addSlot(new Slot(playerInventory, x, x_off + x * 18, y_off)); | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | public Container getContainer() { | ||
| 55 | return container; | ||
| 56 | } | ||
| 57 | |||
| 58 | @Nonnull | ||
| 59 | @Override | ||
| 60 | public ItemStack quickMoveStack(Player player, int fromIndex) { | ||
| 61 | var newStack = ItemStack.EMPTY; | ||
| 62 | var slot = slots.get(fromIndex); | ||
| 63 | if (!slot.hasItem()) { | ||
| 64 | return newStack; | ||
| 65 | } | ||
| 66 | |||
| 67 | var originalStack = slot.getItem(); | ||
| 68 | newStack = originalStack.copy(); | ||
| 69 | |||
| 70 | if (fromIndex < container.getContainerSize()) { | ||
| 71 | if (!moveItemStackTo(originalStack, container.getContainerSize(), slots.size(), true)) { | ||
| 72 | return ItemStack.EMPTY; | ||
| 73 | } | ||
| 74 | } else if (!moveItemStackTo(originalStack, 0, container.getContainerSize(), false)) { | ||
| 75 | return ItemStack.EMPTY; | ||
| 76 | } | ||
| 77 | |||
| 78 | if (originalStack.isEmpty()) { | ||
| 79 | slot.setByPlayer(ItemStack.EMPTY); | ||
| 80 | } else { | ||
| 81 | slot.setChanged(); | ||
| 82 | } | ||
| 83 | |||
| 84 | return newStack; | ||
| 85 | } | ||
| 86 | |||
| 87 | @Override | ||
| 88 | public boolean stillValid(Player player) { | ||
| 89 | return container.stillValid(player); | ||
| 90 | } | ||
| 91 | } | ||