Fix enchantment name display for 1.20.6 structured components

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
This commit is contained in:
BruceChen 2026-03-19 02:01:15 +08:00
parent 1e2b853b14
commit 79a0dff8cd
3 changed files with 44 additions and 20 deletions

View file

@ -17,7 +17,11 @@ public class EnchantmentsComponent(DataTypes dataTypes, ItemPalette itemPalette,
NumberOfEnchantments = dataTypes.ReadNextVarInt(data);
for (var i = 0; i < NumberOfEnchantments; i++)
Enchantments.Add(new Enchantment((Enchantments)dataTypes.ReadNextVarInt(data), dataTypes.ReadNextVarInt(data)));
{
var registryId = dataTypes.ReadNextVarInt(data);
var level = dataTypes.ReadNextVarInt(data);
Enchantments.Add(new Enchantment(EnchantmentMapping.GetEnchantmentByRegistryId1206(registryId), level));
}
ShowTooltip = dataTypes.ReadNextBool(data);
}
@ -28,7 +32,7 @@ public class EnchantmentsComponent(DataTypes dataTypes, ItemPalette itemPalette,
data.AddRange(DataTypes.GetVarInt(Enchantments.Count));
foreach (var enchantment in Enchantments)
{
data.AddRange(DataTypes.GetVarInt((int)enchantment.Type));
data.AddRange(DataTypes.GetVarInt(EnchantmentMapping.GetRegistryId1206ByEnchantment(enchantment.Type)));
data.AddRange(DataTypes.GetVarInt(enchantment.Level));
}
data.AddRange(DataTypes.GetBool(ShowTooltip));