From cc264733bba8c50b342f7aa6695c340da6ffe97e Mon Sep 17 00:00:00 2001 From: Patbox <39821509+Patbox@users.noreply.github.com> Date: Thu, 14 Mar 2024 22:17:40 +0100 Subject: [PATCH] Fix bugs --- src/main/java/eu/pb4/sgui/api/GuiHelpers.java | 6 ++++-- .../pb4/sgui/api/elements/BookElementBuilder.java | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/pb4/sgui/api/GuiHelpers.java b/src/main/java/eu/pb4/sgui/api/GuiHelpers.java index df4343a..259944d 100644 --- a/src/main/java/eu/pb4/sgui/api/GuiHelpers.java +++ b/src/main/java/eu/pb4/sgui/api/GuiHelpers.java @@ -56,7 +56,7 @@ public static int getHeight(ScreenHandlerType type) { return 4; } else if (ScreenHandlerType.GENERIC_9X2.equals(type) || ScreenHandlerType.ENCHANTMENT.equals(type) || ScreenHandlerType.STONECUTTER.equals(type)) { return 2; - } else if (ScreenHandlerType.GENERIC_9X1.equals(type) || ScreenHandlerType.BEACON.equals(type) || ScreenHandlerType.HOPPER.equals(type) || ScreenHandlerType.BREWING_STAND.equals(type)) { + } else if (ScreenHandlerType.GENERIC_9X1.equals(type) || ScreenHandlerType.BEACON.equals(type) || ScreenHandlerType.HOPPER.equals(type) || ScreenHandlerType.BREWING_STAND.equals(type) || ScreenHandlerType.SMITHING.equals(type)) { return 1; } @@ -66,11 +66,13 @@ public static int getHeight(ScreenHandlerType type) { public static int getWidth(ScreenHandlerType type) { if (ScreenHandlerType.CRAFTING.equals(type)) { return 2; + } else if (ScreenHandlerType.SMITHING.equals(type)) { + return 4; } else if (ScreenHandlerType.GENERIC_3X3.equals(type)) { return 3; } else if (ScreenHandlerType.HOPPER.equals(type) || ScreenHandlerType.BREWING_STAND.equals(type)) { return 5; - } else if (ScreenHandlerType.ENCHANTMENT.equals(type) || ScreenHandlerType.STONECUTTER.equals(type) || ScreenHandlerType.BEACON.equals(type) || ScreenHandlerType.BLAST_FURNACE.equals(type) || ScreenHandlerType.FURNACE.equals(type) || ScreenHandlerType.SMOKER.equals(type) || ScreenHandlerType.ANVIL.equals(type) || ScreenHandlerType.SMITHING.equals(type) || ScreenHandlerType.GRINDSTONE.equals(type) || ScreenHandlerType.MERCHANT.equals(type) || ScreenHandlerType.CARTOGRAPHY_TABLE.equals(type) || ScreenHandlerType.LOOM.equals(type)) { + } else if (ScreenHandlerType.ENCHANTMENT.equals(type) || ScreenHandlerType.STONECUTTER.equals(type) || ScreenHandlerType.BEACON.equals(type) || ScreenHandlerType.BLAST_FURNACE.equals(type) || ScreenHandlerType.FURNACE.equals(type) || ScreenHandlerType.SMOKER.equals(type) || ScreenHandlerType.ANVIL.equals(type) || ScreenHandlerType.GRINDSTONE.equals(type) || ScreenHandlerType.MERCHANT.equals(type) || ScreenHandlerType.CARTOGRAPHY_TABLE.equals(type) || ScreenHandlerType.LOOM.equals(type)) { return 1; } diff --git a/src/main/java/eu/pb4/sgui/api/elements/BookElementBuilder.java b/src/main/java/eu/pb4/sgui/api/elements/BookElementBuilder.java index 667ca78..243b861 100644 --- a/src/main/java/eu/pb4/sgui/api/elements/BookElementBuilder.java +++ b/src/main/java/eu/pb4/sgui/api/elements/BookElementBuilder.java @@ -47,7 +47,7 @@ public BookElementBuilder(int count) { * @see BookElementBuilder#setPage(int, Text...) */ public BookElementBuilder addPage(Text... lines) { - var text = Text.literal(""); + var text = Text.empty(); for (Text line : lines) { text.append(line).append("\n"); } @@ -55,6 +55,11 @@ public BookElementBuilder addPage(Text... lines) { return this; } + public BookElementBuilder addPage(Text text) { + this.getOrCreatePages().add(NbtString.of(Text.Serialization.toJsonString(text))); + return this; + } + /** * Sets a page of the book.
* Note that only signed books support formatting @@ -66,7 +71,7 @@ public BookElementBuilder addPage(Text... lines) { * @see BookElementBuilder#addPage(Text...) */ public BookElementBuilder setPage(int index, Text... lines) { - var text = Text.literal(""); + var text = Text.empty(); for (Text line : lines) { text.append(line).append("\n"); } @@ -74,6 +79,11 @@ public BookElementBuilder setPage(int index, Text... lines) { return this; } + public BookElementBuilder setPage(int index, Text text) { + this.getOrCreatePages().set(index, NbtString.of(Text.Serialization.toJsonString(text))); + return this; + } + /** * Sets the author of the book, also marks * the book as signed.