summaryrefslogtreecommitdiff
path: root/src/main/java/lv/enes/mc/eris_alchemy/menu
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/lv/enes/mc/eris_alchemy/menu')
-rw-r--r--src/main/java/lv/enes/mc/eris_alchemy/menu/AlchemicalChestMenu.java20
-rw-r--r--src/main/java/lv/enes/mc/eris_alchemy/menu/ChestLikeMenu.java (renamed from src/main/java/lv/enes/mc/eris_alchemy/menu/ChestLikeBlockMenu.java)42
-rw-r--r--src/main/java/lv/enes/mc/eris_alchemy/menu/EnergyCondenserMenu.java60
3 files changed, 102 insertions, 20 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 1dc3364..35db476 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
@@ -6,7 +6,7 @@ import net.minecraft.world.SimpleContainer;
6import net.minecraft.world.entity.player.Inventory; 6import net.minecraft.world.entity.player.Inventory;
7import net.minecraft.world.inventory.Slot; 7import net.minecraft.world.inventory.Slot;
8 8
9public class AlchemicalChestMenu extends ChestLikeBlockMenu { 9public class AlchemicalChestMenu extends ChestLikeMenu {
10 private static final int WIDTH = 13; 10 private static final int WIDTH = 13;
11 private static final int HEIGHT = 8; 11 private static final int HEIGHT = 8;
12 12
@@ -24,25 +24,13 @@ public class AlchemicalChestMenu extends ChestLikeBlockMenu {
24 var y_off = 8; 24 var y_off = 8;
25 25
26 for (var y = 0; y < HEIGHT; y++) { 26 for (var y = 0; y < HEIGHT; y++) {
27 for (var x = 0; x < WIDTH; x++ ) { 27 for (var x = 0; x < WIDTH; x++) {
28 addSlot(new Slot(container, 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));
29 } 29 }
30 } 30 }
31 31
32 x_off = 44; 32 addPlayerInventorySlots(playerInventory, 44, 155);
33 y_off = 155; 33 addPlayerHotbarSlots(playerInventory, 44, 213);
34
35 for (var y = 0; y < 3; y++) {
36 for (var x = 0; x < 9; x++) {
37 addSlot(new Slot(playerInventory, y * 9 + x + 9, x_off + x * 18, y_off + y * 18));
38 }
39 }
40
41 y_off = 213;
42
43 for (var x = 0; x < 9; x++) {
44 addSlot(new Slot(playerInventory, x, x_off + x * 18, y_off));
45 }
46 } 34 }
47 35
48 @Override 36 @Override
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/menu/ChestLikeBlockMenu.java b/src/main/java/lv/enes/mc/eris_alchemy/menu/ChestLikeMenu.java
index 897abe9..e561f0d 100644
--- a/src/main/java/lv/enes/mc/eris_alchemy/menu/ChestLikeBlockMenu.java
+++ b/src/main/java/lv/enes/mc/eris_alchemy/menu/ChestLikeMenu.java
@@ -6,13 +6,14 @@ import net.minecraft.world.entity.player.Inventory;
6import net.minecraft.world.entity.player.Player; 6import net.minecraft.world.entity.player.Player;
7import net.minecraft.world.inventory.AbstractContainerMenu; 7import net.minecraft.world.inventory.AbstractContainerMenu;
8import net.minecraft.world.inventory.MenuType; 8import net.minecraft.world.inventory.MenuType;
9import net.minecraft.world.inventory.Slot;
9import net.minecraft.world.item.ItemStack; 10import net.minecraft.world.item.ItemStack;
10 11
11public abstract class ChestLikeBlockMenu extends AbstractContainerMenu { 12public abstract class ChestLikeMenu extends AbstractContainerMenu {
12 protected final Container container; 13 protected final Container container;
13 14
14 public ChestLikeBlockMenu( 15 public ChestLikeMenu(
15 MenuType<? extends ChestLikeBlockMenu> type, 16 MenuType<? extends ChestLikeMenu> type,
16 int syncId, 17 int syncId,
17 Inventory playerInventory, 18 Inventory playerInventory,
18 Container container 19 Container container
@@ -27,10 +28,42 @@ public abstract class ChestLikeBlockMenu extends AbstractContainerMenu {
27 protected abstract void addSlots(Inventory playerInventory); 28 protected abstract void addSlots(Inventory playerInventory);
28 protected abstract int getRequiredSize(); 29 protected abstract int getRequiredSize();
29 30
31 protected void addPlayerInventorySlots(Inventory playerInventory, int xOff, int yOff) {
32 for (var y = 0; y < 3; y++) {
33 for (var x = 0; x < 9; x++) {
34 addSlot(new Slot(playerInventory, y * 9 + x + 9, xOff + x * 18, yOff + y * 18));
35 }
36 }
37 }
38
39 protected void addPlayerHotbarSlots(Inventory playerInventory, int xOff, int yOff) {
40 for (var x = 0; x < 9; x++) {
41 addSlot(new Slot(playerInventory, x, xOff + x * 18, yOff));
42 }
43 }
44
30 public Container getContainer() { 45 public Container getContainer() {
31 return container; 46 return container;
32 } 47 }
33 48
49 protected int getQuickMoveStart() {
50 return 0;
51 }
52
53 protected int getQuickMoveEnd() {
54 return container.getContainerSize();
55 }
56
57 @Override
58 public void broadcastChanges() {
59 super.broadcastChanges();
60 }
61
62 @Override
63 public void broadcastFullState() {
64 super.broadcastFullState();
65 }
66
34 @Nonnull 67 @Nonnull
35 @Override 68 @Override
36 public ItemStack quickMoveStack(Player player, int fromIndex) { 69 public ItemStack quickMoveStack(Player player, int fromIndex) {
@@ -44,10 +77,11 @@ public abstract class ChestLikeBlockMenu extends AbstractContainerMenu {
44 newStack = originalStack.copy(); 77 newStack = originalStack.copy();
45 78
46 if (fromIndex < container.getContainerSize()) { 79 if (fromIndex < container.getContainerSize()) {
80 // In container, else player inv
47 if (!moveItemStackTo(originalStack, container.getContainerSize(), slots.size(), true)) { 81 if (!moveItemStackTo(originalStack, container.getContainerSize(), slots.size(), true)) {
48 return ItemStack.EMPTY; 82 return ItemStack.EMPTY;
49 } 83 }
50 } else if (!moveItemStackTo(originalStack, 0, container.getContainerSize(), false)) { 84 } else if (!moveItemStackTo(originalStack, getQuickMoveStart(), getQuickMoveEnd(), false)) {
51 return ItemStack.EMPTY; 85 return ItemStack.EMPTY;
52 } 86 }
53 87
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/menu/EnergyCondenserMenu.java b/src/main/java/lv/enes/mc/eris_alchemy/menu/EnergyCondenserMenu.java
new file mode 100644
index 0000000..bdba77b
--- /dev/null
+++ b/src/main/java/lv/enes/mc/eris_alchemy/menu/EnergyCondenserMenu.java
@@ -0,0 +1,60 @@
1package lv.enes.mc.eris_alchemy.menu;
2
3import lv.enes.mc.eris_alchemy.ErisAlchemyRegistry;
4import lv.enes.mc.eris_alchemy.block.entity.EnergyCondenserEntity;
5import lv.enes.mc.eris_alchemy.utils.SyncedValue.SyncedDouble;
6import net.minecraft.network.FriendlyByteBuf;
7import net.minecraft.world.Container;
8import net.minecraft.world.SimpleContainer;
9import net.minecraft.world.entity.player.Inventory;
10import net.minecraft.world.inventory.Slot;
11
12public class EnergyCondenserMenu extends ChestLikeMenu {
13 private static final int WIDTH = 13;
14 private static final int HEIGHT = 7;
15
16 private final SyncedDouble storedEmc;
17
18 public EnergyCondenserMenu(int syncId, Inventory playerInventory, FriendlyByteBuf buf) {
19 this(syncId, playerInventory, new SimpleContainer(WIDTH * HEIGHT + 1), SyncedDouble.deserialize(buf));
20 }
21
22 public EnergyCondenserMenu(int syncId, Inventory playerInventory, EnergyCondenserEntity entity) {
23 this(syncId, playerInventory, entity, entity.getStoredEmcSyncer());
24 }
25
26 public EnergyCondenserMenu(int syncId, Inventory playerInventory, Container container, SyncedDouble storedEmc) {
27 super(ErisAlchemyRegistry.Menus.ENERGY_CONDENSER, syncId, playerInventory, container);
28 this.storedEmc = storedEmc;
29 }
30
31 @Override
32 protected void addSlots(Inventory playerInventory) {
33 addSlot(new Slot(container, 0, 8, 7));
34
35 var xOff = 8;
36 var yOff = 28;
37 for (var y = 0; y < HEIGHT; y++) {
38 for (var x = 0; x < WIDTH; x++) {
39 addSlot(new Slot(container, y * WIDTH + x + 1, xOff + x * 18, yOff + y * 18));
40 }
41 }
42
43 addPlayerInventorySlots(playerInventory, 44, 157);
44 addPlayerHotbarSlots(playerInventory, 44, 213);
45 }
46
47 @Override
48 protected int getQuickMoveStart() {
49 return 1;
50 }
51
52 @Override
53 protected int getRequiredSize() {
54 return WIDTH * HEIGHT + 1;
55 }
56
57 public double getStoredEmc() {
58 return storedEmc.getValue();
59 }
60}