From a6e2fa7fc55ce2867dd03270c39d9edae383be65 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 25 Dec 2022 17:51:08 +0100 Subject: [PATCH] Add button to go to Book form --- .../screen/ScriptEditScreen.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java b/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java index 628d982..e4211d6 100644 --- a/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java +++ b/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java @@ -7,6 +7,7 @@ import de.zonlykroks.advancedscripts.lexer.TokenTypeColors; import net.minecraft.client.font.TextHandler; import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.BookEditScreen; import net.minecraft.client.gui.screen.ingame.BookScreen; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; import net.minecraft.client.gui.widget.PressableWidget; @@ -24,7 +25,10 @@ import net.minecraft.text.Text; import net.minecraft.util.Hand; import org.apache.commons.lang3.mutable.MutableInt; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; public class ScriptEditScreen extends Screen { @@ -70,20 +74,27 @@ public class ScriptEditScreen extends Screen { @Override protected void init() { this.addDrawableChild( - new DoneButton(this.width / 2 - 98 / 2, height - 40, () -> { + new Button(DONE, this.width / 2 - 98 / 2, height - 55, () -> { this.client.setScreen(null); finalizeBook(); }) ); + this.addDrawableChild( + new Button(BOOK, this.width - 98 - 5, height - 20 - 5, () -> { + finalizeBook(); + this.client.setScreen(new BookEditScreen(player, itemStack, hand)); + }) + ); } public static final Text DONE = Text.translatable("gui.done"); + public static final Text BOOK = Text.translatable("item.minecraft.book"); - private class DoneButton extends PressableWidget { + private static class Button extends PressableWidget { private Runnable onPress; - public DoneButton(int x, int y, Runnable onPress) { - super(x, y, 98, 20, DONE); + public Button(Text text, int x, int y, Runnable onPress) { + super(x, y, 98, 20, text); visible = true; this.onPress = onPress; }