From 99da2a7454313bc9cf4035a3f693b2681708d3d6 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Wed, 20 Nov 2024 20:07:31 +0100 Subject: Add vie --- .../funnyteleporters/ColouredChestConfigGUI.java | 61 ++++++++++++---------- .../funnyteleporters/ColouredChestViewScreen.java | 44 ++++++++++++++++ .../moe/nea/funnyteleporters/FunnyRegistry.java | 1 - 3 files changed, 76 insertions(+), 30 deletions(-) create mode 100644 src/main/java/moe/nea/funnyteleporters/ColouredChestViewScreen.java diff --git a/src/main/java/moe/nea/funnyteleporters/ColouredChestConfigGUI.java b/src/main/java/moe/nea/funnyteleporters/ColouredChestConfigGUI.java index 8c1aff8..6a2ee40 100644 --- a/src/main/java/moe/nea/funnyteleporters/ColouredChestConfigGUI.java +++ b/src/main/java/moe/nea/funnyteleporters/ColouredChestConfigGUI.java @@ -1,6 +1,5 @@ package moe.nea.funnyteleporters; -import com.google.common.collect.ImmutableList; import eu.pb4.sgui.api.ClickType; import eu.pb4.sgui.api.elements.GuiElementInterface; import eu.pb4.sgui.api.gui.SimpleGui; @@ -9,14 +8,18 @@ import net.minecraft.item.DyeItem; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.screen.SimpleNamedScreenHandlerFactory; import net.minecraft.screen.slot.SlotActionType; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Style; import net.minecraft.text.Text; import net.minecraft.util.DyeColor; import net.minecraft.util.Formatting; +import net.minecraft.util.Unit; import net.minecraft.util.math.MathHelper; +import javax.xml.crypto.Data; +import java.text.Format; import java.util.ArrayList; import java.util.Collections; @@ -25,7 +28,7 @@ public class ColouredChestConfigGUI extends SimpleGui { private final ColouredChestBlockEntity blockEntity; public ColouredChestConfigGUI(ColouredChestBlockEntity blockEntity, ServerPlayerEntity player) { - super(ScreenHandlerType.GENERIC_3X3, player, false); + super(ScreenHandlerType.GENERIC_9X3, player, false); setTitle(Text.literal("Funny Enderchest")); this.blockEntity = blockEntity; this.updateFromBlockEntity(); @@ -45,20 +48,15 @@ public class ColouredChestConfigGUI extends SimpleGui { @Override public boolean onClick(int index, ClickType type, SlotActionType action, GuiElementInterface element) { - if (index == 0) - cycleColour(0, 1); - else if (index == 6) - cycleColour(0, -1); - else if (index == 1) - cycleColour(1, 1); - else if (index == 7) - cycleColour(1, -1); - else if (index == 2) - cycleColour(2, 1); - else if (index == 8) - cycleColour(2, -1); - else return super.onClick(index, type, action, element); - return false; + int x = index % width; + int y = index / width; + if (x == 0 || x == 1 || x == 2) { + cycleColour(x, y == 0 ? -1 : y == 2 ? 1 : 0); + } + if (index == width + 5) { + new ColouredChestViewScreen(player, blockEntity).open(); + } + return super.onClick(index, type, action, element); } void cycleColour(int frequencyIndex, int direction) { @@ -74,18 +72,23 @@ public class ColouredChestConfigGUI extends SimpleGui { } public void updateFromBlockEntity() { - setSlot(0, createUpItem(0, "up")); - setSlot(3, createFrequencyItem(0, blockEntity.extra.frequency().get(0))); - setSlot(6, createUpItem(0, "down")); - - setSlot(1, createUpItem(1, "up")); - setSlot(4, createFrequencyItem(1, blockEntity.extra.frequency().get(1))); - setSlot(7, createUpItem(1, "down")); - - setSlot(2, createUpItem(2, "up")); - setSlot(5, createFrequencyItem(2, blockEntity.extra.frequency().get(2))); - setSlot(8, createUpItem(2, "down")); + for (int i = 0; i < 3; i++) { + setSlot(i, createUpItem(i, "up")); + setSlot(i + width, createFrequencyItem(i, blockEntity.extra.frequency().get(i))); + setSlot(i + 2 * width, createUpItem(i, "down")); + } + for (int x = 3; x < 9; x++) { + for (int y = 0; y < 3; y++) { + var s = new ItemStack(Items.BLACK_STAINED_GLASS_PANE); + s.set(DataComponentTypes.CUSTOM_NAME, Text.empty()); + s.set(DataComponentTypes.HIDE_TOOLTIP, Unit.INSTANCE); + setSlot(y * width + x, s); + } + } + { + var s = new ItemStack(Items.CHEST); + s.set(DataComponentTypes.CUSTOM_NAME, Text.literal("View chest").setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.DARK_RED))); + setSlot(width + 5, s); + } } - - } diff --git a/src/main/java/moe/nea/funnyteleporters/ColouredChestViewScreen.java b/src/main/java/moe/nea/funnyteleporters/ColouredChestViewScreen.java new file mode 100644 index 0000000..0e14c87 --- /dev/null +++ b/src/main/java/moe/nea/funnyteleporters/ColouredChestViewScreen.java @@ -0,0 +1,44 @@ +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.Unit; + +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(); + } + + @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)); + } + } +} diff --git a/src/main/java/moe/nea/funnyteleporters/FunnyRegistry.java b/src/main/java/moe/nea/funnyteleporters/FunnyRegistry.java index 7b3e3c2..a7fb40b 100644 --- a/src/main/java/moe/nea/funnyteleporters/FunnyRegistry.java +++ b/src/main/java/moe/nea/funnyteleporters/FunnyRegistry.java @@ -6,7 +6,6 @@ import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.Items; import net.minecraft.registry.Registries; -- cgit