Skip to content

Commit

Permalink
refactor(utils): TextUtils deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Aug 16, 2022
1 parent 7e8f623 commit bbf1a29
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 45 deletions.
Expand Up @@ -2,15 +2,15 @@

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;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
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;
Expand All @@ -21,7 +21,7 @@
public class LanguageInfoArgument implements ArgumentType<LanguageInfo> {

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() {
Expand Down
@@ -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;
Expand Down Expand Up @@ -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()))
)
Expand All @@ -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<Item> tag : tags) {
addLine(event, StringText(" " + tag.location()).setStyle(darkGary));
addLine(event, TextUtils.literal(" " + tag.location()).setStyle(darkGary));
}
}

Expand Down
@@ -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;
Expand Down Expand Up @@ -49,7 +49,7 @@ public SimpleScreen(Component title) {
}

public SimpleScreen() {
this(TextUtils.StringText("SimpleScreen"));
this(TextUtils.literal("SimpleScreen"));
}

@Override
Expand Down
Expand Up @@ -3,23 +3,23 @@
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;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
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<CreativeModeTab> {

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() {
Expand Down
Expand Up @@ -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;
Expand All @@ -31,9 +31,9 @@ public static void addVersionNode(CommandNode<CommandSourceStack> node, Class<?>
}

public static int getModVersion(CommandContext<CommandSourceStack> 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"));
Expand Down Expand Up @@ -61,7 +61,7 @@ public static int getModVersion(CommandContext<CommandSourceStack> 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) {
Expand Down
@@ -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;
Expand All @@ -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<CommandSourceStack> PERMISSION_LEVEL_0 = (source) -> source.hasPermission(0);
Predicate<CommandSourceStack> PERMISSION_LEVEL_1 = (source) -> source.hasPermission(1);
Expand Down
48 changes: 32 additions & 16 deletions src/main/java/org/auioc/mcmod/arnicalib/utils/game/TextUtils.java
Expand Up @@ -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

}

0 comments on commit bbf1a29

Please sign in to comment.