Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize names #4393

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import meteordevelopment.meteorclient.settings.*;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
import net.minecraft.client.resource.language.I18n;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
Expand Down Expand Up @@ -343,7 +344,7 @@ private void blockDataW(WTable table, BlockDataSetting<?> setting) {

private void potionW(WTable table, PotionSetting setting) {
WHorizontalList list = table.add(theme.horizontalList()).expandX().widget();
WItemWithLabel item = list.add(theme.itemWithLabel(setting.get().potion, setting.get().potion.getName().getString())).widget();
WItemWithLabel item = list.add(theme.itemWithLabel(setting.get().potion, I18n.translate(setting.get().potion.getTranslationKey()))).widget();

WButton button = list.add(theme.button("Select")).expandCellX().widget();
button.action = () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import meteordevelopment.meteorclient.gui.widgets.pressable.WButton;
import meteordevelopment.meteorclient.settings.PotionSetting;
import meteordevelopment.meteorclient.utils.misc.MyPotion;
import net.minecraft.client.resource.language.I18n;

public class PotionSettingScreen extends WindowScreen {
private final PotionSetting setting;
Expand All @@ -26,7 +27,7 @@ public void initWidgets() {
WTable table = add(theme.table()).expandX().widget();

for (MyPotion potion : MyPotion.values()) {
table.add(theme.itemWithLabel(potion.potion, potion.potion.getName().getString()));
table.add(theme.itemWithLabel(potion.potion, I18n.translate(potion.potion.getTranslationKey())));

WButton select = table.add(theme.button("Select")).widget();
select.action = () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package meteordevelopment.meteorclient.gui.widgets;

import meteordevelopment.meteorclient.gui.widgets.containers.WHorizontalList;
import meteordevelopment.meteorclient.utils.misc.Names;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffectUtil;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -57,7 +58,7 @@ public void set(ItemStack itemStack) {
this.itemStack = itemStack;
item.itemStack = itemStack;

name = itemStack.getName().getString();
name = Names.get(itemStack);
label.set(name + getStringToAppend());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import meteordevelopment.meteorclient.systems.modules.misc.NameProtect;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.entity.EntityUtils;
import meteordevelopment.meteorclient.utils.misc.Names;
import meteordevelopment.meteorclient.utils.player.PlayerUtils;
import meteordevelopment.meteorclient.utils.render.NametagUtils;
import meteordevelopment.meteorclient.utils.render.RenderUtils;
Expand Down Expand Up @@ -550,7 +551,7 @@ private void renderNametagItem(ItemStack stack, boolean shadow) {
TextRenderer text = TextRenderer.get();
NametagUtils.begin(pos);

String name = stack.getName().getString();
String name = Names.get(stack);
String count = " x" + stack.getCount();

double nameWidth = text.getWidth(name, shadow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.misc.MyPotion;
import meteordevelopment.meteorclient.utils.player.InvUtils;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.potion.Potion;
Expand Down Expand Up @@ -94,7 +95,7 @@ private boolean insertIngredient(BrewingStandScreenHandler c, Item ingredient) {
}

if (slot == -1) {
error("You do not have any %s left in your inventory... disabling.", ingredient.getName().getString());
error("You do not have any %s left in your inventory... disabling.", I18n.translate(ingredient.getTranslationKey()));
toggle();
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.screen.world.SelectWorldScreen;
import net.minecraft.client.resource.ResourceReloadLogger;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.Entity;
import net.minecraft.entity.effect.StatusEffect;
Expand Down Expand Up @@ -250,7 +251,7 @@ public static Object2IntMap<StatusEffect> createStatusEffectMap() {
}

public static String getEnchantSimpleName(Enchantment enchantment, int length) {
return enchantment.getName(0).getString().substring(0, length);
return I18n.translate(enchantment.getTranslationKey()).substring(0, length);
}

public static boolean searchTextDefault(String text, String filter, boolean caseSensitive) {
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/meteordevelopment/meteorclient/utils/misc/Names.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
import meteordevelopment.meteorclient.utils.PreInit;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.block.Block;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.sound.WeightedSoundSet;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtElement;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleType;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -54,23 +57,23 @@ private static void onResourcePacksReloaded(ResourcePacksReloadedEvent event) {
}

public static String get(StatusEffect effect) {
return statusEffectNames.computeIfAbsent(effect, effect1 -> StringHelper.stripTextFormat(effect1.getName().getString()));
return statusEffectNames.computeIfAbsent(effect, effect1 -> StringHelper.stripTextFormat(I18n.translate(effect1.getTranslationKey())));
}

public static String get(Item item) {
return itemNames.computeIfAbsent(item, item1 -> StringHelper.stripTextFormat(item1.getName().getString()));
return itemNames.computeIfAbsent(item, item1 -> StringHelper.stripTextFormat(I18n.translate(item1.getTranslationKey())));
}

public static String get(Block block) {
return blockNames.computeIfAbsent(block, block1 -> StringHelper.stripTextFormat(block1.getName().getString()));
return blockNames.computeIfAbsent(block, block1 -> StringHelper.stripTextFormat(I18n.translate(block1.getTranslationKey())));
}

public static String get(Enchantment enchantment) {
return enchantmentNames.computeIfAbsent(enchantment, enchantment1 -> StringHelper.stripTextFormat(Text.translatable(enchantment1.getTranslationKey()).getString()));
return enchantmentNames.computeIfAbsent(enchantment, enchantment1 -> StringHelper.stripTextFormat(I18n.translate(enchantment1.getTranslationKey())));
}

public static String get(EntityType<?> entityType) {
return entityTypeNames.computeIfAbsent(entityType, entityType1 -> StringHelper.stripTextFormat(entityType1.getName().getString()));
return entityTypeNames.computeIfAbsent(entityType, entityType1 -> StringHelper.stripTextFormat(I18n.translate(entityType1.getTranslationKey())));
}

public static String get(ParticleType<?> type) {
Expand All @@ -89,4 +92,8 @@ public static String getSoundName(Identifier id) {
return StringHelper.stripTextFormat(text.getString());
});
}

public static String get(ItemStack stack) {
return stack.hasNbt() && stack.getNbt().contains("display", NbtElement.COMPOUND_TYPE) ? stack.getName().getString() : I18n.translate(stack.getTranslationKey());
}
}