Minecraft-Console-Client/MinecraftClient/Protocol/Handlers/StructuredComponents/Registries/StructuredComponentsRegistry12111.cs
BruceChen c0c4c078c0 fix: use HashedStack for container_click and fix enchantments parsing for 1.21.5+
Two bugs fixed:

1. EnchantmentsComponent was reading a trailing ShowTooltip boolean that
   was removed from the wire format in MC 1.21.5. Created
   EnchantmentsComponent1215 and StoredEnchantmentsComponent1215 that
   omit the boolean. Used by StructuredComponentsRegistry1215 and 12111.

2. MC 1.21.5+ changed ServerboundContainerClickPacket to use HashedStack
   (item holder id + count + hashed component patch map) instead of full
   ItemStack for changed slots and carried item. Added GetHashedItemSlot()
   in DataTypes.cs and gated SendWindowAction in Protocol18.cs to use it
   for 1.21.5+. Since MCC doesn't track component hashes, an empty
   HashedPatchMap is sent; the server detects stateId mismatch and resyncs.

Tested: AutoFishing bot successfully catches fish on MC 1.21.11 with
enchanted fishing rods (Lure III + Luck of the Sea III).

Made-with: Cursor
2026-03-22 02:18:01 +08:00

123 lines
9.1 KiB
C#

using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21_2;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21_5;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21_11;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Registries;
public class StructuredComponentsRegistry12111 : StructuredComponentRegistry
{
public StructuredComponentsRegistry12111(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: base(dataTypes, itemPalette, subComponentRegistry)
{
RegisterComponent<CustomDataComponent>(0, "minecraft:custom_data");
RegisterComponent<MaxStackSizeComponent>(1, "minecraft:max_stack_size");
RegisterComponent<MaxDamageComponent>(2, "minecraft:max_damage");
RegisterComponent<DamageComponent>(3, "minecraft:damage");
RegisterComponent<EmptyComponent>(4, "minecraft:unbreakable");
RegisterComponent<UseEffectsComponent>(5, "minecraft:use_effects");
RegisterComponent<CustomNameComponent>(6, "minecraft:custom_name");
RegisterComponent<PotionDurationScaleComponent>(7, "minecraft:minimum_attack_charge");
RegisterComponent<RegistryEitherHolderComponent>(8, "minecraft:damage_type");
RegisterComponent<ItemNameComponent>(9, "minecraft:item_name");
RegisterComponent<ItemModelComponent>(10, "minecraft:item_model");
RegisterComponent<LoreNameComponent1206>(11, "minecraft:lore");
RegisterComponent<RarityComponent>(12, "minecraft:rarity");
RegisterComponent<EnchantmentsComponent1215>(13, "minecraft:enchantments");
RegisterComponent<CanPlaceOnComponent>(14, "minecraft:can_place_on");
RegisterComponent<CanBreakComponent>(15, "minecraft:can_break");
RegisterComponent<AttributeModifiersComponent>(16, "minecraft:attribute_modifiers");
RegisterComponent<CustomModelDataComponent>(17, "minecraft:custom_model_data");
RegisterComponent<TooltipDisplayComponent>(18, "minecraft:tooltip_display");
RegisterComponent<RepairCostComponent>(19, "minecraft:repair_cost");
RegisterComponent<CreativeSlotLockComponent>(20, "minecraft:creative_slot_lock");
RegisterComponent<EnchantmentGlintOverrideComponent>(21, "minecraft:enchantment_glint_override");
RegisterComponent<IntangibleProjectileComponent>(22, "minecraft:intangible_projectile");
RegisterComponent<FoodComponent1212>(23, "minecraft:food");
RegisterComponent<ConsumableComponent>(24, "minecraft:consumable");
RegisterComponent<UseRemainderComponent>(25, "minecraft:use_remainder");
RegisterComponent<UseCooldownComponent>(26, "minecraft:use_cooldown");
RegisterComponent<DamageResistantComponent>(27, "minecraft:damage_resistant");
RegisterComponent<ToolComponent>(28, "minecraft:tool");
RegisterComponent<WeaponComponent>(29, "minecraft:weapon");
RegisterComponent<AttackRangeComponent>(30, "minecraft:attack_range");
RegisterComponent<EnchantableComponent>(31, "minecraft:enchantable");
RegisterComponent<EquippableComponent>(32, "minecraft:equippable");
RegisterComponent<RepairableComponent>(33, "minecraft:repairable");
RegisterComponent<GliderComponent>(34, "minecraft:glider");
RegisterComponent<TooltipStyleComponent>(35, "minecraft:tooltip_style");
RegisterComponent<DeathProtectionComponent>(36, "minecraft:death_protection");
RegisterComponent<BlocksAttacksComponent>(37, "minecraft:blocks_attacks");
RegisterComponent<PiercingWeaponComponent>(38, "minecraft:piercing_weapon");
RegisterComponent<KineticWeaponComponent>(39, "minecraft:kinetic_weapon");
RegisterComponent<SwingAnimationComponent>(40, "minecraft:swing_animation");
RegisterComponent<StoredEnchantmentsComponent1215>(41, "minecraft:stored_enchantments");
RegisterComponent<DyeColorComponent>(42, "minecraft:dyed_color");
RegisterComponent<MapColorComponent>(43, "minecraft:map_color");
RegisterComponent<MapIdComponent>(44, "minecraft:map_id");
RegisterComponent<MapDecorationsComponent>(45, "minecraft:map_decorations");
RegisterComponent<MapPostProcessingComponent>(46, "minecraft:map_post_processing");
RegisterComponent<ChargedProjectilesComponent>(47, "minecraft:charged_projectiles");
RegisterComponent<BundleContentsComponent>(48, "minecraft:bundle_contents");
RegisterComponent<PotionContentsComponent>(49, "minecraft:potion_contents");
RegisterComponent<PotionDurationScaleComponent>(50, "minecraft:potion_duration_scale");
RegisterComponent<SuspiciousStewEffectsComponent>(51, "minecraft:suspicious_stew_effects");
RegisterComponent<WritableBlookContentComponent>(52, "minecraft:writable_book_content");
RegisterComponent<WrittenBlookContentComponent>(53, "minecraft:written_book_content");
RegisterComponent<TrimComponent>(54, "minecraft:trim");
RegisterComponent<DebugStickStateComponent>(55, "minecraft:debug_stick_state");
RegisterComponent<EntityDataComponent>(56, "minecraft:entity_data");
RegisterComponent<BucketEntityDataComponent>(57, "minecraft:bucket_entity_data");
RegisterComponent<BlockEntityDataComponent>(58, "minecraft:block_entity_data");
RegisterComponent<InstrumentComponent1215>(59, "minecraft:instrument");
RegisterComponent<ProvidesTrimMaterialComponent>(60, "minecraft:provides_trim_material");
RegisterComponent<OmniousBottleAmplifierComponent>(61, "minecraft:ominous_bottle_amplifier");
RegisterComponent<JukeBoxPlayableComponent>(62, "minecraft:jukebox_playable");
RegisterComponent<ProvidesBannerPatternsComponent>(63, "minecraft:provides_banner_patterns");
RegisterComponent<RecipesComponent>(64, "minecraft:recipes");
RegisterComponent<LodestoneTrackerComponent>(65, "minecraft:lodestone_tracker");
RegisterComponent<FireworkExplosionComponent>(66, "minecraft:firework_explosion");
RegisterComponent<FireworksComponent>(67, "minecraft:fireworks");
RegisterComponent<ProfileComponent>(68, "minecraft:profile");
RegisterComponent<NoteBlockSoundComponent>(69, "minecraft:note_block_sound");
RegisterComponent<BannerPatternsComponent>(70, "minecraft:banner_patterns");
RegisterComponent<BaseColorComponent>(71, "minecraft:base_color");
RegisterComponent<PotDecorationsComponent>(72, "minecraft:pot_decorations");
RegisterComponent<ContainerComponent>(73, "minecraft:container");
RegisterComponent<BlockStateComponent>(74, "minecraft:block_state");
RegisterComponent<BeesComponent>(75, "minecraft:bees");
RegisterComponent<LockComponent>(76, "minecraft:lock");
RegisterComponent<ContainerLootComponent>(77, "minecraft:container_loot");
RegisterComponent<SoundEventHolderComponent>(78, "minecraft:break_sound");
RegisterComponent<VarIntComponent>(79, "minecraft:villager/variant");
RegisterComponent<VarIntComponent>(80, "minecraft:wolf/variant");
RegisterComponent<VarIntComponent>(81, "minecraft:wolf/sound_variant");
RegisterComponent<VarIntComponent>(82, "minecraft:wolf/collar");
RegisterComponent<VarIntComponent>(83, "minecraft:fox/variant");
RegisterComponent<VarIntComponent>(84, "minecraft:salmon/size");
RegisterComponent<VarIntComponent>(85, "minecraft:parrot/variant");
RegisterComponent<VarIntComponent>(86, "minecraft:tropical_fish/pattern");
RegisterComponent<VarIntComponent>(87, "minecraft:tropical_fish/base_color");
RegisterComponent<VarIntComponent>(88, "minecraft:tropical_fish/pattern_color");
RegisterComponent<VarIntComponent>(89, "minecraft:mooshroom/variant");
RegisterComponent<VarIntComponent>(90, "minecraft:rabbit/variant");
RegisterComponent<VarIntComponent>(91, "minecraft:pig/variant");
RegisterComponent<VarIntComponent>(92, "minecraft:cow/variant");
RegisterComponent<EitherHolderComponent>(93, "minecraft:chicken/variant");
RegisterComponent<RegistryEitherHolderComponent>(94, "minecraft:zombie_nautilus/variant");
RegisterComponent<VarIntComponent>(95, "minecraft:frog/variant");
RegisterComponent<VarIntComponent>(96, "minecraft:horse/variant");
RegisterComponent<PaintingVariantHolderComponent>(97, "minecraft:painting/variant");
RegisterComponent<VarIntComponent>(98, "minecraft:llama/variant");
RegisterComponent<VarIntComponent>(99, "minecraft:axolotl/variant");
RegisterComponent<VarIntComponent>(100, "minecraft:cat/variant");
RegisterComponent<VarIntComponent>(101, "minecraft:cat/collar");
RegisterComponent<VarIntComponent>(102, "minecraft:sheep/color");
RegisterComponent<VarIntComponent>(103, "minecraft:shulker/color");
}
}