diff --git a/src/main/java/org/auioc/mcmod/arnicalib/client/command/argument/LanguageInfoArgument.java b/src/main/java/org/auioc/mcmod/arnicalib/client/command/argument/LanguageInfoArgument.java index eb997a12..6eb22e01 100644 --- a/src/main/java/org/auioc/mcmod/arnicalib/client/command/argument/LanguageInfoArgument.java +++ b/src/main/java/org/auioc/mcmod/arnicalib/client/command/argument/LanguageInfoArgument.java @@ -2,6 +2,8 @@ import java.util.concurrent.CompletableFuture; import java.util.stream.Stream; +import org.auioc.mcmod.arnicalib.ArnicaLib; +import org.auioc.mcmod.arnicalib.utils.game.TextUtils; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.context.CommandContext; @@ -9,8 +11,6 @@ import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import org.auioc.mcmod.arnicalib.ArnicaLib; -import org.auioc.mcmod.arnicalib.utils.game.TextUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.language.LanguageInfo; import net.minecraft.commands.SharedSuggestionProvider; @@ -21,7 +21,7 @@ public class LanguageInfoArgument implements ArgumentType { private static final DynamicCommandExceptionType UNKNOWN_LANGUAGE_CODE = new DynamicCommandExceptionType( - (langCode) -> TextUtils.I18nText(ArnicaLib.i18n("argument.language_info.unknown"), langCode) + (langCode) -> TextUtils.translatable(ArnicaLib.i18n("argument.language_info.unknown"), langCode) ); public static LanguageInfoArgument languageInfo() { diff --git a/src/main/java/org/auioc/mcmod/arnicalib/client/event/handler/TooltipEventHandler.java b/src/main/java/org/auioc/mcmod/arnicalib/client/event/handler/TooltipEventHandler.java index a86611d8..33518a5d 100644 --- a/src/main/java/org/auioc/mcmod/arnicalib/client/event/handler/TooltipEventHandler.java +++ b/src/main/java/org/auioc/mcmod/arnicalib/client/event/handler/TooltipEventHandler.java @@ -1,9 +1,8 @@ package org.auioc.mcmod.arnicalib.client.event.handler; -import static org.auioc.mcmod.arnicalib.utils.game.TextUtils.I18nText; -import static org.auioc.mcmod.arnicalib.utils.game.TextUtils.StringText; import org.auioc.mcmod.arnicalib.ArnicaLib; import org.auioc.mcmod.arnicalib.client.config.ClientConfig; +import org.auioc.mcmod.arnicalib.utils.game.TextUtils; import org.lwjgl.glfw.GLFW; import com.mojang.blaze3d.platform.InputConstants; import net.minecraft.ChatFormatting; @@ -36,10 +35,10 @@ public static void handle(ItemTooltipEvent event) { if (itemStack.hasTag()) { addLine( event, - I18nText(ArnicaLib.i18n("advanced_tooltip.nbt")) + TextUtils.translatable(ArnicaLib.i18n("advanced_tooltip.nbt")) .setStyle(darkGary) .append( - StringText("") + TextUtils.empty() .setStyle(Style.EMPTY.withColor(ChatFormatting.WHITE)) .append(NbtUtils.toPrettyComponent(itemStack.getTag())) ) @@ -48,9 +47,9 @@ public static void handle(ItemTooltipEvent event) { var tags = itemStack.getTags().toList(); if (tags.size() > 0) { - addLine(event, I18nText(ArnicaLib.i18n("advanced_tooltip.tag")).setStyle(darkGary)); + addLine(event, TextUtils.translatable(ArnicaLib.i18n("advanced_tooltip.tag")).setStyle(darkGary)); for (TagKey tag : tags) { - addLine(event, StringText(" " + tag.location()).setStyle(darkGary)); + addLine(event, TextUtils.literal(" " + tag.location()).setStyle(darkGary)); } } diff --git a/src/main/java/org/auioc/mcmod/arnicalib/client/gui/screen/SimpleScreen.java b/src/main/java/org/auioc/mcmod/arnicalib/client/gui/screen/SimpleScreen.java index f7a4baf2..e00c64ab 100644 --- a/src/main/java/org/auioc/mcmod/arnicalib/client/gui/screen/SimpleScreen.java +++ b/src/main/java/org/auioc/mcmod/arnicalib/client/gui/screen/SimpleScreen.java @@ -1,10 +1,10 @@ package org.auioc.mcmod.arnicalib.client.gui.screen; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; import org.auioc.mcmod.arnicalib.ArnicaLib; import org.auioc.mcmod.arnicalib.api.game.screen.HScreen; import org.auioc.mcmod.arnicalib.utils.game.TextUtils; +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; @@ -49,7 +49,7 @@ public SimpleScreen(Component title) { } public SimpleScreen() { - this(TextUtils.StringText("SimpleScreen")); + this(TextUtils.literal("SimpleScreen")); } @Override diff --git a/src/main/java/org/auioc/mcmod/arnicalib/common/command/argument/CreativeModeTabArgument.java b/src/main/java/org/auioc/mcmod/arnicalib/common/command/argument/CreativeModeTabArgument.java index c12b3c72..0ab6f8cd 100644 --- a/src/main/java/org/auioc/mcmod/arnicalib/common/command/argument/CreativeModeTabArgument.java +++ b/src/main/java/org/auioc/mcmod/arnicalib/common/command/argument/CreativeModeTabArgument.java @@ -3,6 +3,9 @@ import java.util.Arrays; import java.util.concurrent.CompletableFuture; import java.util.stream.Stream; +import org.auioc.mcmod.arnicalib.ArnicaLib; +import org.auioc.mcmod.arnicalib.api.mixin.common.IMixinCreativeModeTab; +import org.auioc.mcmod.arnicalib.utils.game.TextUtils; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.context.CommandContext; @@ -10,16 +13,13 @@ import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import org.auioc.mcmod.arnicalib.ArnicaLib; -import org.auioc.mcmod.arnicalib.api.mixin.common.IMixinCreativeModeTab; -import org.auioc.mcmod.arnicalib.utils.game.TextUtils; import net.minecraft.commands.SharedSuggestionProvider; import net.minecraft.world.item.CreativeModeTab; public class CreativeModeTabArgument implements ArgumentType { private static final DynamicCommandExceptionType UNKNOWN_CREATIVE_MODE_TAB = new DynamicCommandExceptionType( - (langId) -> TextUtils.I18nText(ArnicaLib.i18n("argument.creative_mod_tab.unknown"), langId) + (langId) -> TextUtils.translatable(ArnicaLib.i18n("argument.creative_mod_tab.unknown"), langId) ); public static CreativeModeTabArgument creativeModeTab() { diff --git a/src/main/java/org/auioc/mcmod/arnicalib/common/command/impl/VersionCommand.java b/src/main/java/org/auioc/mcmod/arnicalib/common/command/impl/VersionCommand.java index 1d1a25c1..beaaf13a 100644 --- a/src/main/java/org/auioc/mcmod/arnicalib/common/command/impl/VersionCommand.java +++ b/src/main/java/org/auioc/mcmod/arnicalib/common/command/impl/VersionCommand.java @@ -3,15 +3,15 @@ import static net.minecraft.commands.Commands.literal; import static org.auioc.mcmod.arnicalib.ArnicaLib.LOGGER; import java.util.function.Function; +import org.apache.logging.log4j.Marker; +import org.auioc.mcmod.arnicalib.ArnicaLib; +import org.auioc.mcmod.arnicalib.utils.LogUtil; +import org.auioc.mcmod.arnicalib.utils.game.TextUtils; import com.mojang.brigadier.Command; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.tree.CommandNode; -import org.apache.logging.log4j.Marker; -import org.auioc.mcmod.arnicalib.ArnicaLib; -import org.auioc.mcmod.arnicalib.utils.LogUtil; -import org.auioc.mcmod.arnicalib.utils.game.TextUtils; import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.chat.MutableComponent; @@ -31,9 +31,9 @@ public static void addVersionNode(CommandNode node, Class } public static int getModVersion(CommandContext ctx, String mainVersion, String fullVersion, String modName) { - MutableComponent message = TextUtils.EmptyText(); + MutableComponent message = TextUtils.empty(); - message.append(TextUtils.StringText("[" + modName + "] ").withStyle(ChatFormatting.AQUA)); + message.append(TextUtils.literal("[" + modName + "] ").withStyle(ChatFormatting.AQUA)); if (mainVersion.equals("0") && fullVersion.equals("0")) { message.append(i18n("failure.zero")); @@ -61,7 +61,7 @@ public static int getModVersion(CommandContext ctx, Class } private static MutableComponent i18n(String key, Object... args) { - return TextUtils.I18nText(ArnicaLib.i18n("command.version." + key), args); + return TextUtils.translatable(ArnicaLib.i18n("command.version." + key), args); } private static MutableComponent i18n(String key) { diff --git a/src/main/java/org/auioc/mcmod/arnicalib/utils/game/CommandUtils.java b/src/main/java/org/auioc/mcmod/arnicalib/utils/game/CommandUtils.java index dd24ed32..db4c29f2 100644 --- a/src/main/java/org/auioc/mcmod/arnicalib/utils/game/CommandUtils.java +++ b/src/main/java/org/auioc/mcmod/arnicalib/utils/game/CommandUtils.java @@ -1,7 +1,7 @@ package org.auioc.mcmod.arnicalib.utils.game; import static org.auioc.mcmod.arnicalib.ArnicaLib.i18n; -import static org.auioc.mcmod.arnicalib.utils.game.TextUtils.I18nText; +import static org.auioc.mcmod.arnicalib.utils.game.TextUtils.translatable; import java.lang.reflect.Field; import java.util.List; import java.util.function.Predicate; @@ -20,11 +20,11 @@ public interface CommandUtils { - SimpleCommandExceptionType INTERNAL_ERROR = new SimpleCommandExceptionType(I18nText(i18n("command.failure.internal"))); - SimpleCommandExceptionType LOGGABLE_INTERNAL_ERROR = new SimpleCommandExceptionType(I18nText(i18n("command.failure.internal.loggable"))); - SimpleCommandExceptionType NOT_SERVER_ERROR = new SimpleCommandExceptionType(I18nText(i18n("command.failure.not_server"))); - SimpleCommandExceptionType NOT_DEDICATED_SERVER_ERROR = new SimpleCommandExceptionType(I18nText(i18n("command.failure.not_dedicated_server"))); - SimpleCommandExceptionType GET_REAL_SOURCE_REFLECTION_ERROR = new SimpleCommandExceptionType(I18nText(i18n("command.failure.get_real_source.reflection"))); + SimpleCommandExceptionType INTERNAL_ERROR = new SimpleCommandExceptionType(translatable(i18n("command.failure.internal"))); + SimpleCommandExceptionType LOGGABLE_INTERNAL_ERROR = new SimpleCommandExceptionType(translatable(i18n("command.failure.internal.loggable"))); + SimpleCommandExceptionType NOT_SERVER_ERROR = new SimpleCommandExceptionType(translatable(i18n("command.failure.not_server"))); + SimpleCommandExceptionType NOT_DEDICATED_SERVER_ERROR = new SimpleCommandExceptionType(translatable(i18n("command.failure.not_dedicated_server"))); + SimpleCommandExceptionType GET_REAL_SOURCE_REFLECTION_ERROR = new SimpleCommandExceptionType(translatable(i18n("command.failure.get_real_source.reflection"))); Predicate PERMISSION_LEVEL_0 = (source) -> source.hasPermission(0); Predicate PERMISSION_LEVEL_1 = (source) -> source.hasPermission(1); diff --git a/src/main/java/org/auioc/mcmod/arnicalib/utils/game/TextUtils.java b/src/main/java/org/auioc/mcmod/arnicalib/utils/game/TextUtils.java index 755a98a4..7dd13c31 100644 --- a/src/main/java/org/auioc/mcmod/arnicalib/utils/game/TextUtils.java +++ b/src/main/java/org/auioc/mcmod/arnicalib/utils/game/TextUtils.java @@ -10,60 +10,76 @@ public interface TextUtils { Object[] NO_ARGS = new Object[0]; + static TextComponent empty() { + return new TextComponent(""); + } + + static TextComponent literal(String text) { + return new TextComponent(text); + } + + static TranslatableComponent translatable(String key) { + return new TranslatableComponent(key); + } + + static TranslatableComponent translatable(String key, Object... arguments) { + return new TranslatableComponent(key, arguments); + } + + + /* ============================================================================================================== */ + // #region Deprecated + + @Deprecated(since = "5.4.1", forRemoval = true) static void chat(Player player, String message) { player.sendMessage(new TextComponent(message), Util.NIL_UUID); } + @Deprecated(since = "5.4.1", forRemoval = true) static void chat(Player player, Component message) { player.sendMessage(message, Util.NIL_UUID); } - static TextComponent empty() { - return new TextComponent(""); - } - + @Deprecated(since = "5.4.1", forRemoval = true) static TextComponent emptyText() { return new TextComponent(""); } + @Deprecated(since = "5.4.1", forRemoval = true) static TextComponent EmptyText() { return new TextComponent(""); } + @Deprecated(since = "5.4.1", forRemoval = true) static TextComponent getStringText(String text) { return new TextComponent(text); } - static TextComponent literal(String text) { - return new TextComponent(text); - } - + @Deprecated(since = "5.4.1", forRemoval = true) static TextComponent StringText(String text) { return new TextComponent(text); } + @Deprecated(since = "5.4.1", forRemoval = true) static TranslatableComponent getI18nText(String key) { return new TranslatableComponent(key); } - static TranslatableComponent translatable(String key) { - return new TranslatableComponent(key); - } - + @Deprecated(since = "5.4.1", forRemoval = true) static TranslatableComponent I18nText(String key) { return new TranslatableComponent(key); } + @Deprecated(since = "5.4.1", forRemoval = true) static TranslatableComponent getI18nText(String key, Object... arguments) { return new TranslatableComponent(key, arguments); } - static TranslatableComponent translatable(String key, Object... arguments) { - return new TranslatableComponent(key, arguments); - } - + @Deprecated(since = "5.4.1", forRemoval = true) static TranslatableComponent I18nText(String key, Object... arguments) { return new TranslatableComponent(key, arguments); } + // #endregion Deprecated + }