diff options
author | Linnea Gräf <nea@nea.moe> | 2024-11-22 20:32:31 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-11-22 20:32:31 +0100 |
commit | eab15793dba8740451b77ec6d551c2fd649ad27c (patch) | |
tree | 7e65e147fc1dfa2641e96e90218d82da77bb4d99 /src/main/java/moe | |
parent | a8b2f2036a45b2d28cfc8a8f4df624aaf3259f5a (diff) | |
download | funny-teleporters-eab15793dba8740451b77ec6d551c2fd649ad27c.tar.gz funny-teleporters-eab15793dba8740451b77ec6d551c2fd649ad27c.tar.bz2 funny-teleporters-eab15793dba8740451b77ec6d551c2fd649ad27c.zip |
Add scrolling
Diffstat (limited to 'src/main/java/moe')
-rw-r--r-- | src/main/java/moe/nea/funnyteleporters/TeleporterNexusScreen.java | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/main/java/moe/nea/funnyteleporters/TeleporterNexusScreen.java b/src/main/java/moe/nea/funnyteleporters/TeleporterNexusScreen.java index 1413519..4a9088e 100644 --- a/src/main/java/moe/nea/funnyteleporters/TeleporterNexusScreen.java +++ b/src/main/java/moe/nea/funnyteleporters/TeleporterNexusScreen.java @@ -6,6 +6,7 @@ import eu.pb4.sgui.api.elements.GuiElementBuilderInterface; import eu.pb4.sgui.api.gui.SimpleGui; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.server.network.ServerPlayerEntity; @@ -25,12 +26,20 @@ public class TeleporterNexusScreen extends SimpleGui { setTitle(Text.literal("Teleport Nexus")); } + int scroll = 0; + void setSlots() { for (int i = 0; i < 9; i++) { setSlot(i, Utils.createBlankBlack()); setSlot(i + (height - 1) * width, Utils.createBlankBlack()); } + if (scroll > 0) { + setSlot(0, GuiElementBuilder.from(new ItemStack(Items.ARROW)) + .setName(Text.literal("Previous page")) + .setCallback(() -> scroll(-1))); + } var it = blockEntity.destinations.entrySet().iterator(); + Utils.skipIt(it, scroll * width * (height - 2)); for (int i = 1; i < height - 1 && it.hasNext(); i++) { for (int j = 0; j < width && it.hasNext(); j++) { int index = i * width + j; @@ -38,6 +47,25 @@ public class TeleporterNexusScreen extends SimpleGui { setSlot(index, getHandlerForEntry(entry)); } } + if (it.hasNext()) { + setSlot(1, GuiElementBuilder.from(new ItemStack(Items.ARROW)) + .setName(Text.literal("Next page")) + .setCallback(() -> scroll(1))); + } + } + + void scroll(int offset) { + scroll = Math.max(0, scroll + offset); + setSlots(); + } + + void handleClick(ClickType clickType, TeleporterDestination destination) { + if (clickType == ClickType.MOUSE_RIGHT) { + new TeleporterNexusEditorScreen(blockEntity, destination, player).open(); + return; + } + destination.teleport(player); + close(); } private GuiElementBuilderInterface<?> getHandlerForEntry(Map.Entry<TeleporterDestination, TeleporterNexusBlockEntity.Label> entry) { @@ -52,13 +80,6 @@ public class TeleporterNexusScreen extends SimpleGui { .addLoreLine(Text.empty()) .addLoreLine(Text.literal("Left-Click to teleport.").setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.GRAY))) .addLoreLine(Text.literal("Right-Click to edit item.").setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.GRAY))) - .setCallback((clickType) -> { - if (clickType == ClickType.MOUSE_RIGHT) { - new TeleporterNexusEditorScreen(blockEntity, dest, player).open(); - return; - } - dest.teleport(player); - close(); - }); + .setCallback(clickType -> handleClick(clickType, dest)); } } |