2024-09-01 20:42:39 +02:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using MinecraftClient.Inventory.ItemPalettes;
|
|
|
|
|
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
|
|
|
|
using MinecraftClient.Protocol.Handlers.StructuredComponents.Registries;
|
|
|
|
|
using MinecraftClient.Protocol.Handlers.StructuredComponents.Registries.Subcomponents;
|
|
|
|
|
|
|
|
|
|
namespace MinecraftClient.Protocol.Handlers.StructuredComponents;
|
|
|
|
|
|
|
|
|
|
public class StructuredComponentsHandler
|
|
|
|
|
{
|
|
|
|
|
private StructuredComponentRegistry ComponentRegistry { get; }
|
|
|
|
|
|
|
|
|
|
public StructuredComponentsHandler(
|
|
|
|
|
int protocolVersion,
|
2024-09-11 20:35:23 +02:00
|
|
|
DataTypes dataTypes,
|
|
|
|
|
ItemPalette itemPalette)
|
2024-09-01 20:42:39 +02:00
|
|
|
{
|
|
|
|
|
// Get the appropriate subcomponent registry type based on the protocol version and then instantiate it
|
|
|
|
|
var subcomponentRegistryType = protocolVersion switch
|
|
|
|
|
{
|
2024-09-11 19:12:31 +02:00
|
|
|
Protocol18Handler.MC_1_20_6_Version => typeof(SubComponentRegistry1206),
|
2024-12-06 16:45:48 +01:00
|
|
|
Protocol18Handler.MC_1_21_Version => typeof(SubComponentRegistry121),
|
feat: add packet palette, data components, and protocol fixes for MC 1.21.2
Packet Palette (Phase 2.1):
- Create PacketPalette1212.cs with complete ID mapping for protocol 768
(131 clientbound + 60 serverbound play packets, plus config packets)
- Add new PacketTypesIn enum values: EntityPositionSync, MoveMinecartAlongTrack,
PlayerRotation, RecipeBookAdd/Remove/Settings, SetCursorItem, SetHeldSlot,
SetPlayerInventory
- Add new PacketTypesOut enum values: BundleItemSelected, ClientTickEnd
- Update PacketType18Handler routing for 1.21.2
Data Components (Phase 1.4):
- Create StructuredComponentsRegistry1212 with 67 components (was 57 in 1.21)
reflecting the new 1.21.2 DataComponents ordering
- Implement 11 new component parsers: ConsumableComponent, UseRemainderComponent,
UseCooldownComponent, DamageResistantComponent, EnchantableComponent,
EquippableComponent, RepairableComponent, GliderComponent, TooltipStyleComponent,
DeathProtectionComponent, ItemModelComponent
- Create FoodComponent1212 (simplified: nutrition/saturation/canAlwaysEat only;
eatSeconds/effects/usingConvertsTo moved to consumable/use_remainder)
- Create SubComponentRegistry1212 and route in StructuredComponentsHandler
Protocol Fixes:
- Fix PlayerPositionAndLook packet for 1.21.2 (new format: teleportId first,
added deltaMovement Vec3, flags as Int instead of Byte)
- Fix login success packet (remove strictErrorHandling read for >= 1.21.2)
- Fix ClientSettings/ClientInformation packet (add particleStatus VarInt)
- Add SetHeldSlot as alias for HeldItemChange in packet handler
Verified: MCC connects to 1.21.2 vanilla server, stays connected, chat works.
Made-with: Cursor
2026-03-20 03:25:20 +08:00
|
|
|
>= Protocol18Handler.MC_1_21_2_Version => typeof(SubComponentRegistry1212),
|
2024-09-01 20:42:39 +02:00
|
|
|
_ => throw new NotSupportedException($"Protocol version {protocolVersion} is not supported for subcomponent registries!")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var subcomponentRegistry = Activator.CreateInstance(subcomponentRegistryType, dataTypes) as SubComponentRegistry
|
|
|
|
|
?? throw new InvalidOperationException($"Failed to instantiate a component registry for type {nameof(subcomponentRegistryType)}");
|
|
|
|
|
|
|
|
|
|
// Get the appropriate component registry type based on the protocol version and then instantiate it
|
|
|
|
|
var registryType = protocolVersion switch
|
|
|
|
|
{
|
|
|
|
|
Protocol18Handler.MC_1_20_6_Version => typeof(StructuredComponentsRegistry1206),
|
2024-12-06 16:45:48 +01:00
|
|
|
Protocol18Handler.MC_1_21_Version => typeof(StructuredComponentsRegistry121),
|
feat: add version routing, structured components, and metadata for MC 1.21.11
- Add MC_1_21_11_Version constant (protocol 774)
- Create StructuredComponentsRegistry12111 with 104 components (8 new:
use_effects, minimum_attack_charge, damage_type, attack_range,
piercing_weapon, kinetic_weapon, swing_animation, zombie_nautilus/variant)
- Add 6 new component classes for 1.21.11 wire formats
- Add RegistryEitherHolderComponent for holderRegistry-backed EitherHolder
- Add ZombieNautilusVariant and HumanoidArm cases in DataTypes.ReadNextMetadata
- Update all version routing in Protocol18, PacketType18Handler,
EntityMetadataPalette, StructuredComponentsHandler, and ProtocolHandler
- Bump MCHighestVersion to 1.21.11
Made-with: Cursor
2026-03-22 00:56:04 +08:00
|
|
|
>= Protocol18Handler.MC_1_21_11_Version => typeof(StructuredComponentsRegistry12111),
|
feat: add MC 1.21.5 (protocol 770) support
Full protocol adaptation for Minecraft 1.21.5:
- Protocol version mapping: 770 -> 1.21.5
- Packet palette: AddExperienceOrb removed (S2C), TestInstanceBlockStatus
added (S2C), SetTestBlock and TestInstanceBlockAction added (C2S)
- Entity metadata palette: 5 new serializer types (OptionalLivingEntityReference,
CowVariant, WolfSoundVariant, PigVariant, ChickenVariant), OPTIONAL_UUID
replaced by OPTIONAL_LIVING_ENTITY_REFERENCE
- Item palette: 11 new items (Bush, FireflyBush, DryShortGrass, DryTallGrass,
Wildflowers, LeafLitter, CactusFlower, TestBlock, TestInstanceBlock,
BlueEgg, BrownEgg)
- Entity palette: Potion split into SplashPotion and LingeringPotion
- Block palette: 9 new blocks (bush, cactus_flower, firefly_bush, leaf_litter,
short_dry_grass, tall_dry_grass, test_block, test_instance_block, wildflowers)
- Structured components: 31 new components including tooltip_display, weapon,
blocks_attacks, potion_duration_scale, provides_trim_material,
provides_banner_patterns, break_sound, and 25 entity variant components;
unbreakable changed from Bool to Unit; instrument changed to EitherHolder
Made-with: Cursor
2026-03-21 00:48:27 +08:00
|
|
|
>= Protocol18Handler.MC_1_21_5_Version => typeof(StructuredComponentsRegistry1215),
|
feat: add packet palette, data components, and protocol fixes for MC 1.21.2
Packet Palette (Phase 2.1):
- Create PacketPalette1212.cs with complete ID mapping for protocol 768
(131 clientbound + 60 serverbound play packets, plus config packets)
- Add new PacketTypesIn enum values: EntityPositionSync, MoveMinecartAlongTrack,
PlayerRotation, RecipeBookAdd/Remove/Settings, SetCursorItem, SetHeldSlot,
SetPlayerInventory
- Add new PacketTypesOut enum values: BundleItemSelected, ClientTickEnd
- Update PacketType18Handler routing for 1.21.2
Data Components (Phase 1.4):
- Create StructuredComponentsRegistry1212 with 67 components (was 57 in 1.21)
reflecting the new 1.21.2 DataComponents ordering
- Implement 11 new component parsers: ConsumableComponent, UseRemainderComponent,
UseCooldownComponent, DamageResistantComponent, EnchantableComponent,
EquippableComponent, RepairableComponent, GliderComponent, TooltipStyleComponent,
DeathProtectionComponent, ItemModelComponent
- Create FoodComponent1212 (simplified: nutrition/saturation/canAlwaysEat only;
eatSeconds/effects/usingConvertsTo moved to consumable/use_remainder)
- Create SubComponentRegistry1212 and route in StructuredComponentsHandler
Protocol Fixes:
- Fix PlayerPositionAndLook packet for 1.21.2 (new format: teleportId first,
added deltaMovement Vec3, flags as Int instead of Byte)
- Fix login success packet (remove strictErrorHandling read for >= 1.21.2)
- Fix ClientSettings/ClientInformation packet (add particleStatus VarInt)
- Add SetHeldSlot as alias for HeldItemChange in packet handler
Verified: MCC connects to 1.21.2 vanilla server, stays connected, chat works.
Made-with: Cursor
2026-03-20 03:25:20 +08:00
|
|
|
>= Protocol18Handler.MC_1_21_2_Version => typeof(StructuredComponentsRegistry1212),
|
2024-09-01 20:42:39 +02:00
|
|
|
_ => throw new NotSupportedException($"Protocol version {protocolVersion} is not supported for structured component registries!")
|
|
|
|
|
};
|
|
|
|
|
|
2024-09-11 20:35:23 +02:00
|
|
|
ComponentRegistry = Activator.CreateInstance(registryType, dataTypes, itemPalette, subcomponentRegistry) as StructuredComponentRegistry
|
2024-09-01 20:42:39 +02:00
|
|
|
?? throw new InvalidOperationException($"Failed to instantiate a component registry for type {nameof(registryType)}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public StructuredComponent Parse(int componentId, Queue<byte> data)
|
|
|
|
|
{
|
|
|
|
|
return ComponentRegistry.ParseComponent(componentId, data);
|
|
|
|
|
}
|
|
|
|
|
}
|