Fix tooltip durability/NBT not being translated

Fixes #2706
This commit is contained in:
Camotoy 2021-12-19 15:54:31 -05:00
parent 222c9d7a24
commit 71a975b805

View file

@ -34,14 +34,16 @@ import com.nukkitx.nbt.NbtType;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.text.MessageTranslator;
import org.geysermc.geyser.registry.BlockRegistries; import org.geysermc.geyser.registry.BlockRegistries;
import org.geysermc.geyser.registry.type.ItemMapping; import org.geysermc.geyser.registry.type.ItemMapping;
import org.geysermc.geyser.registry.type.ItemMappings; import org.geysermc.geyser.registry.type.ItemMappings;
import org.geysermc.geyser.util.FileUtils; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.MinecraftLocale; import org.geysermc.geyser.text.MinecraftLocale;
import org.geysermc.geyser.translator.text.MessageTranslator;
import org.geysermc.geyser.util.FileUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.*; import java.util.*;
@ -206,15 +208,31 @@ public abstract class ItemTranslator {
int maxDurability = mapping.getMaxDamage(); int maxDurability = mapping.getMaxDamage();
if (maxDurability != 0) { if (maxDurability != 0) {
int durability = maxDurability - ((IntTag) newNbt.get("Damage")).getValue(); Tag durabilityTag = newNbt.get("Damage");
if (durabilityTag instanceof IntTag) {
int durability = maxDurability - ((IntTag) durabilityTag).getValue();
if (durability != maxDurability) { if (durability != maxDurability) {
listTag.add(new StringTag("", "§r§f" + String.format(MessageTranslator.convertMessage("item.durability", language), durability, maxDurability))); Component component = Component.text()
.resetStyle()
.color(NamedTextColor.WHITE)
.append(Component.translatable("item.durability",
Component.text(durability),
Component.text(maxDurability)))
.build();
listTag.add(new StringTag("", MessageTranslator.convertMessage(component, language)));
}
} }
} }
listTag.add(new StringTag("", "§r§8" + mapping.getJavaIdentifier())); listTag.add(new StringTag("", "§r§8" + mapping.getJavaIdentifier()));
if (nbt != null) { if (nbt != null) {
listTag.add(new StringTag("", "§r§8" + String.format(MessageTranslator.convertMessage("item.nbt_tags", language), nbt.size()))); Component component = Component.text()
.resetStyle()
.color(NamedTextColor.DARK_GRAY)
.append(Component.translatable("item.nbt_tags",
Component.text(nbt.size())))
.build();
listTag.add(new StringTag("", MessageTranslator.convertMessage(component, language)));
} }
compoundTag.put(listTag); compoundTag.put(listTag);
newNbt.put(compoundTag); newNbt.put(compoundTag);