From b9c568733a6a017a2ea4b734b843cdf19329b7d3 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Wed, 17 May 2023 20:11:14 -0400 Subject: [PATCH] Improve sign editing --- .../geysermc/geyser/session/cache/WorldCache.java | 4 ++++ .../block/entity/SignBlockEntityTranslator.java | 15 ++++++++++++--- .../bedrock/BedrockBlockEntityDataTranslator.java | 5 ++--- .../java/level/JavaOpenSignEditorTranslator.java | 2 ++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/WorldCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/WorldCache.java index dd166358d..6be57670c 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/WorldCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/WorldCache.java @@ -61,6 +61,10 @@ public final class WorldCache { private int currentSequence; private final Object2IntMap unverifiedPredictions = new Object2IntOpenHashMap<>(1); + @Getter + @Setter + private boolean editingSignOnFront; + public WorldCache(GeyserSession session) { this.session = session; this.scoreboard = new Scoreboard(session); diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SignBlockEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SignBlockEntityTranslator.java index f9c228f5f..76d4bfdf4 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SignBlockEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SignBlockEntityTranslator.java @@ -84,8 +84,9 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator { StringBuilder signText = new StringBuilder(); Tag messages = signData.get("messages"); if (messages instanceof ListTag listTag) { - for (int i = 0; i < listTag.size(); i++) { - String signLine = (String) listTag.get(i).getValue(); + var it = listTag.iterator(); + while (it.hasNext()) { + String signLine = (String) it.next().getValue(); signLine = MessageTranslator.convertMessageLenient(signLine); // Check the character width on the sign to ensure there is no overflow that is usually hidden @@ -114,10 +115,18 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator { } signText.append(finalSignLine); - signText.append("\n"); + if (it.hasNext()) { + signText.append("\n"); + } } } + // Trim extra newlines - this makes editing difficult if preserved because the cursor starts at the bottom, + // Which can easily go over the screen + while (!signText.isEmpty() && signText.charAt(signText.length() - 1) == '\n') { + signText.deleteCharAt(signText.length() - 1); + } + builder.putString("Text", signText.toString()); // Java Edition 1.14 added the ability to change the text color of the whole sign using dye diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockBlockEntityDataTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockBlockEntityDataTranslator.java index 60f14b230..3a04513e5 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockBlockEntityDataTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockBlockEntityDataTranslator.java @@ -44,9 +44,8 @@ public class BedrockBlockEntityDataTranslator extends PacketTranslator