From 6ced4dd946e0c9fedd4ff50a76f68d8bec56f9b3 Mon Sep 17 00:00:00 2001 From: RacoonDog <32882447+RacoonDog@users.noreply.github.com> Date: Sun, 7 Jul 2024 08:53:03 -0400 Subject: [PATCH] Cleanup usages of `Text` (#3916) * replace Text.literal("") with Text.empty() * Replace newline `Text` literals with `ScreenTexts.LINE_BREAK` * Use `Text#translatableWithFallback` * Fix checkstyle --------- Co-authored-by: modmuss50 --- .../mixin/command/client/ClientCommandSourceMixin.java | 2 +- .../fabric/impl/gamerule/widget/DoubleRuleWidget.java | 5 +++-- .../fabric/impl/gamerule/widget/EnumRuleWidget.java | 8 +------- .../fabric/impl/registry/sync/RegistrySyncManager.java | 5 +++-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/fabric-command-api-v2/src/client/java/net/fabricmc/fabric/mixin/command/client/ClientCommandSourceMixin.java b/fabric-command-api-v2/src/client/java/net/fabricmc/fabric/mixin/command/client/ClientCommandSourceMixin.java index 5b4ee32e6..a5075734a 100644 --- a/fabric-command-api-v2/src/client/java/net/fabricmc/fabric/mixin/command/client/ClientCommandSourceMixin.java +++ b/fabric-command-api-v2/src/client/java/net/fabricmc/fabric/mixin/command/client/ClientCommandSourceMixin.java @@ -43,7 +43,7 @@ abstract class ClientCommandSourceMixin implements FabricClientCommandSource { @Override public void sendError(Text message) { - sendFeedback(Text.literal("").append(message).formatted(Formatting.RED)); + sendFeedback(Text.empty().append(message).formatted(Formatting.RED)); } @Override diff --git a/fabric-game-rule-api-v1/src/client/java/net/fabricmc/fabric/impl/gamerule/widget/DoubleRuleWidget.java b/fabric-game-rule-api-v1/src/client/java/net/fabricmc/fabric/impl/gamerule/widget/DoubleRuleWidget.java index a15b96de8..14ce4f61e 100644 --- a/fabric-game-rule-api-v1/src/client/java/net/fabricmc/fabric/impl/gamerule/widget/DoubleRuleWidget.java +++ b/fabric-game-rule-api-v1/src/client/java/net/fabricmc/fabric/impl/gamerule/widget/DoubleRuleWidget.java @@ -22,6 +22,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.world.EditGameRulesScreen; import net.minecraft.client.gui.widget.TextFieldWidget; +import net.minecraft.screen.ScreenTexts; import net.minecraft.text.OrderedText; import net.minecraft.text.Text; @@ -37,9 +38,9 @@ public final class DoubleRuleWidget extends EditGameRulesScreen.NamedRuleWidget this.textFieldWidget = new TextFieldWidget(MinecraftClient.getInstance().textRenderer, 10, 5, 42, 20, name.copy() - .append("\n") + .append(ScreenTexts.LINE_BREAK) .append(ruleName) - .append("\n") + .append(ScreenTexts.LINE_BREAK) ); this.textFieldWidget.setText(Double.toString(rule.get())); diff --git a/fabric-game-rule-api-v1/src/client/java/net/fabricmc/fabric/impl/gamerule/widget/EnumRuleWidget.java b/fabric-game-rule-api-v1/src/client/java/net/fabricmc/fabric/impl/gamerule/widget/EnumRuleWidget.java index a2b923410..75e18a155 100644 --- a/fabric-game-rule-api-v1/src/client/java/net/fabricmc/fabric/impl/gamerule/widget/EnumRuleWidget.java +++ b/fabric-game-rule-api-v1/src/client/java/net/fabricmc/fabric/impl/gamerule/widget/EnumRuleWidget.java @@ -23,7 +23,6 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.world.EditGameRulesScreen; import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.resource.language.I18n; import net.minecraft.text.OrderedText; import net.minecraft.text.Text; @@ -51,12 +50,7 @@ public final class EnumRuleWidget> extends EditGameRulesScreen public Text getValueText(E value) { final String key = this.rootTranslationKey + "." + value.name().toLowerCase(Locale.ROOT); - - if (I18n.hasTranslation(key)) { - return Text.translatable(key); - } - - return Text.literal(value.toString()); + return Text.translatableWithFallback(key, value.toString()); } @Override diff --git a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/RegistrySyncManager.java b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/RegistrySyncManager.java index 9725a2472..cbc6e2ced 100644 --- a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/RegistrySyncManager.java +++ b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/RegistrySyncManager.java @@ -46,6 +46,7 @@ import net.minecraft.network.packet.Packet; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; +import net.minecraft.screen.ScreenTexts; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerConfigurationNetworkHandler; import net.minecraft.server.network.ServerPlayerConfigurationTask; @@ -325,7 +326,7 @@ public final class RegistrySyncManager { } // Create a nice user friendly error message. - MutableText text = Text.literal(""); + MutableText text = Text.empty(); final int count = missingEntries.values().stream().mapToInt(List::size).sum(); @@ -349,7 +350,7 @@ public final class RegistrySyncManager { for (int i = 0; i < Math.min(namespaces.size(), toDisplay); i++) { text = text.append(Text.literal(namespaces.get(i)).formatted(Formatting.YELLOW)); - text = text.append("\n"); + text = text.append(ScreenTexts.LINE_BREAK); } if (namespaces.size() > toDisplay) {