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