summaryrefslogtreecommitdiff
path: root/src/main/java/moe/nea/funnyteleporters/ColouredChestViewScreen.java
blob: 21d8c8a6350569da220ce73de6783692ceea70a8 (plain)
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
package moe.nea.funnyteleporters;

import eu.pb4.sgui.api.ClickType;
import eu.pb4.sgui.api.elements.GuiElementInterface;
import eu.pb4.sgui.api.gui.SimpleGui;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Unit;

import java.util.stream.Collectors;

public class ColouredChestViewScreen extends SimpleGui {
	private final ColouredChestBlockEntity blockEntity;

	public ColouredChestViewScreen(ServerPlayerEntity player, ColouredChestBlockEntity blockEntity) {
		super(ScreenHandlerType.GENERIC_9X4, player, false);
		this.blockEntity = blockEntity;
		setSlots();
		setTitle(Text.literal("Funny Storage: " + blockEntity.extra.frequency().stream().map(DyeColor::getName)
		                                                           .collect(Collectors.joining(", "))));
	}

	@Override
	public boolean onClick(int index, ClickType type, SlotActionType action, GuiElementInterface element) {
		if (index == 0)
			return new ColouredChestConfigGUI(blockEntity, player).open();
		return super.onClick(index, type, action, element);
	}

	void setSlots() {
		for (int i = 1; i < 9; i++) {
			var s = new ItemStack(Items.BLACK_STAINED_GLASS_PANE);
			s.set(DataComponentTypes.CUSTOM_NAME, Text.empty());
			s.set(DataComponentTypes.HIDE_TOOLTIP, Unit.INSTANCE);
			setSlot(i, s);
		}
		setSlot(0, new ItemStack(Items.ARROW));
		for (int i = 0; i < 27; i++) {
			setSlotRedirect(i + 9, new Slot(blockEntity, i, 0, 0));
		}
	}
}