summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/moe/nea/funnyteleporters/TeleporterNexusScreen.java37
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));
}
}