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 <modmuss50@gmail.com>
This commit is contained in:
RacoonDog 2024-07-07 08:53:03 -04:00 committed by GitHub
parent 8d16166232
commit 6ced4dd946
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 8 additions and 12 deletions

View file

@ -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

View file

@ -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()));

View file

@ -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<E extends Enum<E>> 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

View file

@ -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) {