mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
EnchantmentsComponent (used by both regular and stored enchantments) was directly casting the registry VarInt ID to the Enchantments enum via (Enchantments)id. However, the Enchantments enum is ordered alphabetically (AquaAffinity=0, BaneOfArthropods=1, ..., Sharpness=32) while the 1.20.6 registry uses a completely different order (protection=0, fire_protection=1, ..., sharpness=13). This caused all enchantment names to display incorrectly (e.g. Sharpness V shown as "Unknown Enchantment with ID: 32"). Changes: - Parse now uses EnchantmentMapping.GetEnchantmentByRegistryId1206() to properly map registry IDs to enum values via the existing 1.20.6+ mapping table - Serialize now uses EnchantmentMapping.GetRegistryId1206ByEnchantment() to convert enum values back to registry IDs (reverse lookup) - Fixed translation key prefix: "Enchantments.minecraft." (wrong) -> "enchantment.minecraft." (matches en_us.json resource keys) - Fixed 3 long-standing typos in the Enchantments enum that prevented translation lookup from matching resource keys: - DepthStrieder -> DepthStrider (depth_strieder vs depth_strider) - Efficency -> Efficiency (efficency vs efficiency) - Loyality -> Loyalty (loyality vs loyalty) Verified on vanilla 1.20.6 server: items with sharpness, efficiency, unbreaking, fortune, mending, and bane_of_arthropods all display correct localized names (锋利, 效率, 耐久, 时运, 经验修补, 节肢杀手). Made-with: Cursor
41 lines
No EOL
1.6 KiB
C#
41 lines
No EOL
1.6 KiB
C#
using System.Collections.Generic;
|
|
using MinecraftClient.Inventory;
|
|
using MinecraftClient.Inventory.ItemPalettes;
|
|
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
|
|
|
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
|
|
|
public class EnchantmentsComponent(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
|
|
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
|
|
{
|
|
public int NumberOfEnchantments { get; set; }
|
|
public List<Enchantment> Enchantments { get; set; } = new();
|
|
public bool ShowTooltip { get; set; }
|
|
|
|
public override void Parse(Queue<byte> data)
|
|
{
|
|
NumberOfEnchantments = dataTypes.ReadNextVarInt(data);
|
|
|
|
for (var i = 0; i < NumberOfEnchantments; i++)
|
|
{
|
|
var registryId = dataTypes.ReadNextVarInt(data);
|
|
var level = dataTypes.ReadNextVarInt(data);
|
|
Enchantments.Add(new Enchantment(EnchantmentMapping.GetEnchantmentByRegistryId1206(registryId), level));
|
|
}
|
|
|
|
ShowTooltip = dataTypes.ReadNextBool(data);
|
|
}
|
|
|
|
public override Queue<byte> Serialize()
|
|
{
|
|
var data = new List<byte>();
|
|
data.AddRange(DataTypes.GetVarInt(Enchantments.Count));
|
|
foreach (var enchantment in Enchantments)
|
|
{
|
|
data.AddRange(DataTypes.GetVarInt(EnchantmentMapping.GetRegistryId1206ByEnchantment(enchantment.Type)));
|
|
data.AddRange(DataTypes.GetVarInt(enchantment.Level));
|
|
}
|
|
data.AddRange(DataTypes.GetBool(ShowTooltip));
|
|
return new Queue<byte>(data);
|
|
}
|
|
} |