summaryrefslogtreecommitdiff
path: root/src/main/java/lv/enes/mc/eris_alchemy/menu/EnergyCondenserMenu.java
blob: bdba77bdcba882cc087297bc4c5a049050c4f7cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package lv.enes.mc.eris_alchemy.menu;

import lv.enes.mc.eris_alchemy.ErisAlchemyRegistry;
import lv.enes.mc.eris_alchemy.block.entity.EnergyCondenserEntity;
import lv.enes.mc.eris_alchemy.utils.SyncedValue.SyncedDouble;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.Container;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.Slot;

public class EnergyCondenserMenu extends ChestLikeMenu {
	private static final int WIDTH = 13;
	private static final int HEIGHT = 7;

	private final SyncedDouble storedEmc;

	public EnergyCondenserMenu(int syncId, Inventory playerInventory, FriendlyByteBuf buf) {
		this(syncId, playerInventory, new SimpleContainer(WIDTH * HEIGHT + 1), SyncedDouble.deserialize(buf));
	}

	public EnergyCondenserMenu(int syncId, Inventory playerInventory, EnergyCondenserEntity entity) {
		this(syncId, playerInventory, entity, entity.getStoredEmcSyncer());
	}

	public EnergyCondenserMenu(int syncId, Inventory playerInventory, Container container, SyncedDouble storedEmc) {
		super(ErisAlchemyRegistry.Menus.ENERGY_CONDENSER, syncId, playerInventory, container);
		this.storedEmc = storedEmc;
	}

	@Override
	protected void addSlots(Inventory playerInventory) {
		addSlot(new Slot(container, 0, 8, 7));

		var xOff = 8;
		var yOff = 28;
		for (var y = 0; y < HEIGHT; y++) {
			for (var x = 0; x < WIDTH; x++) {
				addSlot(new Slot(container, y * WIDTH + x + 1, xOff + x * 18, yOff + y * 18));
			}
		}

		addPlayerInventorySlots(playerInventory, 44, 157);
		addPlayerHotbarSlots(playerInventory, 44, 213);
	}

	@Override
	protected int getQuickMoveStart() {
		return 1;
	}

	@Override
	protected int getRequiredSize() {
		return WIDTH * HEIGHT + 1;
	}

	public double getStoredEmc() {
		return storedEmc.getValue();
	}
}