feat: Added Minecraft 26.2 support

Add Minecraft 26.2 support (protocol 776)
This commit is contained in:
Anon 2026-07-04 21:58:48 +02:00 committed by GitHub
commit 142fb107db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 4569 additions and 21 deletions

View file

@ -48,9 +48,9 @@ namespace MinecraftClient.Protocol.Handlers
{
PacketTypePalette p = protocol switch
{
> Protocol18Handler.MC_26_1_Version => throw new NotImplementedException(Translations
> Protocol18Handler.MC_26_2_Version => throw new NotImplementedException(Translations
.exception_palette_packet),
>= Protocol18Handler.MC_26_1_Version => new PacketPalette261(),
>= Protocol18Handler.MC_26_1_Version => new PacketPalette261(), // 26.1 - 26.2 (packet IDs unchanged in 26.2)
<= Protocol18Handler.MC_1_21_11_Version and > Protocol18Handler.MC_1_21_7_Version => new PacketPalette1219(),
<= Protocol18Handler.MC_1_21_7_Version and > Protocol18Handler.MC_1_21_5_Version => new PacketPalette1216(),
<= Protocol18Handler.MC_1_21_5_Version and > Protocol18Handler.MC_1_21_4_Version => new PacketPalette1215(),

View file

@ -84,6 +84,7 @@ namespace MinecraftClient.Protocol.Handlers
internal const int MC_1_21_9_Version = 773;
internal const int MC_1_21_11_Version = 774;
internal const int MC_26_1_Version = 775;
internal const int MC_26_2_Version = 776;
private int compression_treshold = -1;
private int autocomplete_transaction_id = 0;
@ -145,21 +146,21 @@ namespace MinecraftClient.Protocol.Handlers
lastSeenMessagesCollector = protocolVersion >= MC_1_19_3_Version ? new(20) : new(5);
chunkBatchStartTime = GetNanos();
if (handler.GetTerrainEnabled() && protocolVersion > MC_26_1_Version)
if (handler.GetTerrainEnabled() && protocolVersion > MC_26_2_Version)
{
log.Error($"§c{Translations.extra_terrainandmovement_disabled}");
handler.SetTerrainEnabled(false);
}
if (handler.GetInventoryEnabled() &&
protocolVersion is < MC_1_8_Version or > MC_26_1_Version)
protocolVersion is < MC_1_8_Version or > MC_26_2_Version)
{
log.Error($"§c{Translations.extra_inventory_disabled}");
handler.SetInventoryEnabled(false);
}
if (handler.GetEntityHandlingEnabled() &&
protocolVersion is < MC_1_8_Version or > MC_26_1_Version)
protocolVersion is < MC_1_8_Version or > MC_26_2_Version)
{
log.Error($"§c{Translations.extra_entity_disabled}");
handler.SetEntityHandlingEnabled(false);
@ -168,8 +169,9 @@ namespace MinecraftClient.Protocol.Handlers
Block.Palette = protocolVersion switch
{
// Block palette
> MC_26_1_Version when handler.GetTerrainEnabled() =>
> MC_26_2_Version when handler.GetTerrainEnabled() =>
throw new NotImplementedException(Translations.exception_palette_block),
>= MC_26_2_Version => new Palette262(),
>= MC_26_1_Version => new Palette261(),
>= MC_1_21_9_Version => new Palette1219(),
>= MC_1_21_6_Version => new Palette1216(), // 1.21.7/1.21.8 blocks unchanged, reuse 1216
@ -193,8 +195,9 @@ namespace MinecraftClient.Protocol.Handlers
entityPalette = protocolVersion switch
{
// Entity palette
> MC_26_1_Version when handler.GetEntityHandlingEnabled() =>
> MC_26_2_Version when handler.GetEntityHandlingEnabled() =>
throw new NotImplementedException(Translations.exception_palette_entity),
>= MC_26_2_Version => new EntityPalette262(),
>= MC_26_1_Version => new EntityPalette261(),
>= MC_1_21_11_Version => new EntityPalette12111(),
>= MC_1_21_9_Version => new EntityPalette1219(),
@ -224,8 +227,9 @@ namespace MinecraftClient.Protocol.Handlers
itemPalette = protocolVersion switch
{
// Item palette
> MC_26_1_Version when handler.GetInventoryEnabled() =>
> MC_26_2_Version when handler.GetInventoryEnabled() =>
throw new NotImplementedException(Translations.exception_palette_item),
>= MC_26_2_Version => new ItemPalette262(),
>= MC_26_1_Version => new ItemPalette261(),
>= MC_1_21_11_Version => new ItemPalette12111(),
>= MC_1_21_9_Version => new ItemPalette1219(),
@ -2823,7 +2827,7 @@ namespace MinecraftClient.Protocol.Handlers
// Also make a palette for field? Will be a lot of work
var healthField = protocolVersion switch
{
> MC_26_1_Version => throw new NotImplementedException(Translations
> MC_26_2_Version => throw new NotImplementedException(Translations
.exception_palette_healthfield),
// 1.17 and above
>= MC_1_17_Version => 9,
@ -3196,10 +3200,15 @@ namespace MinecraftClient.Protocol.Handlers
// displayName (component), options (byte),
// nameTagVisibility, collisionRule, color (VarInt),
// prefix (component), suffix (component)
// 1.21.5+ method 0/2:
// 1.21.5-26.1 method 0/2:
// displayName (component), options (byte),
// nameTagVisibility (VarInt), collisionRule (VarInt),
// color (VarInt), prefix (component), suffix (component)
// 26.2+ method 0/2:
// displayName (component), prefix (component),
// suffix (component), nameTagVisibility (VarInt),
// collisionRule (VarInt), color (Optional<VarInt>),
// options (byte)
// method 0/3/4: players list (VarInt count + strings)
var teamName = dataTypes.ReadNextString(packetData);
var teamMethod = dataTypes.ReadNextByte(packetData);
@ -3227,6 +3236,39 @@ namespace MinecraftClient.Protocol.Handlers
teamColor = unchecked((sbyte)dataTypes.ReadNextByte(packetData));
}
else if (protocolVersion >= MC_26_2_Version)
{
teamDisplayName = dataTypes.ReadNextChat(packetData);
teamPrefix = dataTypes.ReadNextChat(packetData);
teamSuffix = dataTypes.ReadNextChat(packetData);
// STREAM_CODEC: 0=always, 1=never, 2=hideForOtherTeams, 3=hideForOwnTeam
teamNameTagVisibility = dataTypes.ReadNextVarInt(packetData) switch
{
0 => "always",
1 => "never",
2 => "hideForOtherTeams",
3 => "hideForOwnTeam",
_ => "always"
};
// STREAM_CODEC: 0=always, 1=never, 2=pushOtherTeams, 3=pushOwnTeam
teamCollisionRule = dataTypes.ReadNextVarInt(packetData) switch
{
0 => "always",
1 => "never",
2 => "pushOtherTeams",
3 => "pushOwnTeam",
_ => "always"
};
// Optional<TeamColor>: bool + VarInt id (ids match legacy color ordinals 0-15)
teamColor = dataTypes.ReadNextBool(packetData)
? dataTypes.ReadNextVarInt(packetData)
: -1;
teamFriendlyFlags = dataTypes.ReadNextByte(packetData);
}
else
{
teamDisplayName = dataTypes.ReadNextChat(packetData);

View file

@ -0,0 +1,25 @@
using System.Collections.Generic;
using MinecraftClient.Inventory;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._26_2;
public class SulfurCubeContentComponent262(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public Item? AbsorbedBlockItemStack { get; set; }
public override void Parse(Queue<byte> data)
{
AbsorbedBlockItemStack = DataTypes.ReadNextItemStackTemplate(data, ItemPalette);
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
if (AbsorbedBlockItemStack is not null && !AbsorbedBlockItemStack.IsEmpty)
data.AddRange(DataTypes.GetItemStackTemplate(AbsorbedBlockItemStack, ItemPalette));
return new Queue<byte>(data);
}
}

View file

@ -0,0 +1,134 @@
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_8;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21_9;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21_11;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._26_1;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._26_2;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Registries;
public class StructuredComponentsRegistry262 : StructuredComponentRegistry
{
public StructuredComponentsRegistry262(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<VarIntComponent>(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<CanPlaceOnComponent1215>(14, "minecraft:can_place_on");
RegisterComponent<CanBreakComponent1215>(15, "minecraft:can_break");
RegisterComponent<AttributeModifiersComponent1218>(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<UseRemainderComponent261>(25, "minecraft:use_remainder");
RegisterComponent<UseCooldownComponent>(26, "minecraft:use_cooldown");
RegisterComponent<HolderSetComponent261>(27, "minecraft:damage_resistant");
RegisterComponent<ToolComponent1215>(28, "minecraft:tool");
RegisterComponent<WeaponComponent>(29, "minecraft:weapon");
RegisterComponent<AttackRangeComponent>(30, "minecraft:attack_range");
RegisterComponent<EnchantableComponent>(31, "minecraft:enchantable");
RegisterComponent<EquippableComponent1218>(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<VarIntComponent>(41, "minecraft:additional_trade_cost"); // New in 26.1
RegisterComponent<StoredEnchantmentsComponent1215>(42, "minecraft:stored_enchantments");
RegisterComponent<VarIntComponent>(43, "minecraft:dye"); // New in 26.1
RegisterComponent<DyeColorComponent1215>(44, "minecraft:dyed_color");
RegisterComponent<MapColorComponent>(45, "minecraft:map_color");
RegisterComponent<MapIdComponent>(46, "minecraft:map_id");
RegisterComponent<MapDecorationsComponent>(47, "minecraft:map_decorations");
RegisterComponent<MapPostProcessingComponent>(48, "minecraft:map_post_processing");
RegisterComponent<ItemStackTemplateListComponent261>(49, "minecraft:charged_projectiles");
RegisterComponent<ItemStackTemplateListComponent261>(50, "minecraft:bundle_contents");
RegisterComponent<PotionContentsComponent1212>(51, "minecraft:potion_contents");
RegisterComponent<PotionDurationScaleComponent>(52, "minecraft:potion_duration_scale");
RegisterComponent<SuspiciousStewEffectsComponent>(53, "minecraft:suspicious_stew_effects");
RegisterComponent<WritableBookContentComponent>(54, "minecraft:writable_book_content");
RegisterComponent<WrittenBookContentComponent>(55, "minecraft:written_book_content");
RegisterComponent<TrimComponent1215>(56, "minecraft:trim");
RegisterComponent<DebugStickStateComponent>(57, "minecraft:debug_stick_state");
RegisterComponent<TypedEntityDataComponent>(58, "minecraft:entity_data");
RegisterComponent<BucketEntityDataComponent>(59, "minecraft:bucket_entity_data");
RegisterComponent<TypedBlockEntityDataComponent>(60, "minecraft:block_entity_data");
RegisterComponent<InstrumentComponent261>(61, "minecraft:instrument");
RegisterComponent<ProvidesTrimMaterialComponent261>(62, "minecraft:provides_trim_material");
RegisterComponent<OminousBottleAmplifierComponent>(63, "minecraft:ominous_bottle_amplifier");
RegisterComponent<JukeBoxPlayableComponent1215>(64, "minecraft:jukebox_playable");
RegisterComponent<HolderSetComponent261>(65, "minecraft:provides_banner_patterns");
RegisterComponent<NbtTagComponent261>(66, "minecraft:recipes");
RegisterComponent<LodestoneTrackerComponent>(67, "minecraft:lodestone_tracker");
RegisterComponent<FireworkExplosionComponent>(68, "minecraft:firework_explosion");
RegisterComponent<FireworksComponent>(69, "minecraft:fireworks");
RegisterComponent<ProfileComponent>(70, "minecraft:profile");
RegisterComponent<NoteBlockSoundComponent>(71, "minecraft:note_block_sound");
RegisterComponent<BannerPatternsComponent>(72, "minecraft:banner_patterns");
RegisterComponent<BaseColorComponent>(73, "minecraft:base_color");
RegisterComponent<PotDecorationsComponent>(74, "minecraft:pot_decorations");
RegisterComponent<ContainerComponent261>(75, "minecraft:container");
RegisterComponent<BlockStateComponent>(76, "minecraft:block_state");
RegisterComponent<BeesComponent1219>(77, "minecraft:bees");
RegisterComponent<SulfurCubeContentComponent262>(78, "minecraft:sulfur_cube_content"); // New in 26.2
RegisterComponent<LockComponent>(79, "minecraft:lock");
RegisterComponent<ContainerLootComponent>(80, "minecraft:container_loot");
RegisterComponent<SoundEventHolderComponent>(81, "minecraft:break_sound");
RegisterComponent<VarIntComponent>(82, "minecraft:villager/variant");
RegisterComponent<VarIntComponent>(83, "minecraft:wolf/variant");
RegisterComponent<VarIntComponent>(84, "minecraft:wolf/sound_variant");
RegisterComponent<VarIntComponent>(85, "minecraft:wolf/collar");
RegisterComponent<VarIntComponent>(86, "minecraft:fox/variant");
RegisterComponent<VarIntComponent>(87, "minecraft:salmon/size");
RegisterComponent<VarIntComponent>(88, "minecraft:parrot/variant");
RegisterComponent<VarIntComponent>(89, "minecraft:tropical_fish/pattern");
RegisterComponent<VarIntComponent>(90, "minecraft:tropical_fish/base_color");
RegisterComponent<VarIntComponent>(91, "minecraft:tropical_fish/pattern_color");
RegisterComponent<VarIntComponent>(92, "minecraft:mooshroom/variant");
RegisterComponent<VarIntComponent>(93, "minecraft:rabbit/variant");
RegisterComponent<VarIntComponent>(94, "minecraft:pig/variant");
RegisterComponent<VarIntComponent>(95, "minecraft:pig/sound_variant"); // New in 26.1
RegisterComponent<VarIntComponent>(96, "minecraft:cow/variant");
RegisterComponent<VarIntComponent>(97, "minecraft:cow/sound_variant"); // New in 26.1
RegisterComponent<VarIntComponent>(98, "minecraft:chicken/variant");
RegisterComponent<VarIntComponent>(99, "minecraft:chicken/sound_variant"); // New in 26.1
RegisterComponent<VarIntComponent>(100, "minecraft:zombie_nautilus/variant");
RegisterComponent<VarIntComponent>(101, "minecraft:frog/variant");
RegisterComponent<VarIntComponent>(102, "minecraft:horse/variant");
RegisterComponent<PaintingVariantHolderComponent>(103, "minecraft:painting/variant");
RegisterComponent<VarIntComponent>(104, "minecraft:llama/variant");
RegisterComponent<VarIntComponent>(105, "minecraft:axolotl/variant");
RegisterComponent<VarIntComponent>(106, "minecraft:cat/variant");
RegisterComponent<VarIntComponent>(107, "minecraft:cat/sound_variant"); // New in 26.1
RegisterComponent<VarIntComponent>(108, "minecraft:cat/collar");
RegisterComponent<VarIntComponent>(109, "minecraft:sheep/color");
RegisterComponent<VarIntComponent>(110, "minecraft:shulker/color");
}
}

View file

@ -33,6 +33,7 @@ public class StructuredComponentsHandler
{
Protocol18Handler.MC_1_20_6_Version => typeof(StructuredComponentsRegistry1206),
Protocol18Handler.MC_1_21_Version => typeof(StructuredComponentsRegistry121),
>= Protocol18Handler.MC_26_2_Version => typeof(StructuredComponentsRegistry262),
>= Protocol18Handler.MC_26_1_Version => typeof(StructuredComponentsRegistry261),
>= Protocol18Handler.MC_1_21_11_Version => typeof(StructuredComponentsRegistry12111),
>= Protocol18Handler.MC_1_21_5_Version => typeof(StructuredComponentsRegistry1215),

View file

@ -156,7 +156,7 @@ namespace MinecraftClient.Protocol
{
4, 5, 47, 107, 108, 109, 110, 210, 315, 316, 335, 338, 340, 393, 401, 404, 477, 480, 485, 490, 498, 573,
575, 578, 735, 736, 751, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768,
769, 770, 771, 772, 773, 774, 775
769, 770, 771, 772, 773, 774, 775, 776
};
if (Array.IndexOf(suppoertedVersionsProtocol18, normalizedVersion) > -1)
@ -374,6 +374,8 @@ namespace MinecraftClient.Protocol
return 774;
case "26.1":
return 775;
case "26.2":
return 776;
default:
return 0;
}
@ -396,7 +398,7 @@ namespace MinecraftClient.Protocol
4, 5, 47, 107, 108, 109, 110, 210, 315, 316, 335, 338, 340, 393, 401, 404,
477, 480, 485, 490, 498, 573, 575, 578, 735, 736, 751, 753, 754, 755, 756,
757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771,
772, 773, 774, 775
772, 773, 774, 775, 776
];
/// <summary>
@ -518,6 +520,7 @@ namespace MinecraftClient.Protocol
773 => "1.21.9",
774 => "1.21.11",
775 => "26.1",
776 => "26.2",
_ => "0.0"
};
}