2024-09-11 19:12:31 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using MinecraftClient.Inventory;
|
2024-09-11 20:35:23 +02:00
|
|
|
using MinecraftClient.Inventory.ItemPalettes;
|
2024-09-11 19:12:31 +02:00
|
|
|
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
|
|
|
|
|
|
|
|
|
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
|
|
|
|
|
2026-06-04 11:42:41 +02:00
|
|
|
public class EnchantmentsComponent(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
|
2024-09-11 20:35:23 +02:00
|
|
|
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
|
2024-09-11 19:12:31 +02:00
|
|
|
{
|
|
|
|
|
public int NumberOfEnchantments { get; set; }
|
|
|
|
|
public List<Enchantment> Enchantments { get; set; } = new();
|
|
|
|
|
public bool ShowTooltip { get; set; }
|
|
|
|
|
|
|
|
|
|
public override void Parse(Queue<byte> data)
|
|
|
|
|
{
|
2026-03-24 01:16:05 +00:00
|
|
|
NumberOfEnchantments = DataTypes.ReadNextVarInt(data);
|
2024-09-11 19:12:31 +02:00
|
|
|
|
|
|
|
|
for (var i = 0; i < NumberOfEnchantments; i++)
|
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
2026-03-19 02:01:15 +08:00
|
|
|
{
|
2026-03-24 01:16:05 +00:00
|
|
|
var registryId = DataTypes.ReadNextVarInt(data);
|
|
|
|
|
var level = DataTypes.ReadNextVarInt(data);
|
2026-03-25 18:00:38 +00:00
|
|
|
Enchantments.Add(new Enchantment(EnchantmentMapping.GetEnchantmentByRegistryId1206(DataTypes.ProtocolVersion, registryId), level));
|
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
2026-03-19 02:01:15 +08:00
|
|
|
}
|
2024-09-11 19:12:31 +02:00
|
|
|
|
2026-03-24 01:16:05 +00:00
|
|
|
ShowTooltip = DataTypes.ReadNextBool(data);
|
2024-09-11 19:12:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Queue<byte> Serialize()
|
|
|
|
|
{
|
|
|
|
|
var data = new List<byte>();
|
|
|
|
|
data.AddRange(DataTypes.GetVarInt(Enchantments.Count));
|
|
|
|
|
foreach (var enchantment in Enchantments)
|
|
|
|
|
{
|
2026-03-25 18:00:38 +00:00
|
|
|
data.AddRange(DataTypes.GetVarInt(EnchantmentMapping.GetRegistryId1206ByEnchantment(DataTypes.ProtocolVersion, enchantment.Type)));
|
2024-09-11 19:12:31 +02:00
|
|
|
data.AddRange(DataTypes.GetVarInt(enchantment.Level));
|
|
|
|
|
}
|
|
|
|
|
data.AddRange(DataTypes.GetBool(ShowTooltip));
|
|
|
|
|
return new Queue<byte>(data);
|
|
|
|
|
}
|
2026-03-25 18:00:38 +00:00
|
|
|
}
|