mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
WIP: Added some strctured components
This commit is contained in:
parent
63b027d84a
commit
76e873ed54
36 changed files with 857 additions and 231 deletions
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
||||
|
||||
public class AttributeModifiersComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public int NumberOfAttributes { get; set; }
|
||||
public List<AttributeSubComponent1206> Attributes { get; set; } = new();
|
||||
public bool ShowInTooltip { get; set; }
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
NumberOfAttributes = dataTypes.ReadNextVarInt(data);
|
||||
|
||||
for (var i = 0; i < NumberOfAttributes; i++)
|
||||
Attributes.Add((AttributeSubComponent1206)subComponentRegistry.ParseSubComponent(SubComponents.Attribute, data));
|
||||
|
||||
ShowInTooltip = dataTypes.ReadNextBool(data);
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetVarInt(NumberOfAttributes));
|
||||
|
||||
if(NumberOfAttributes > 0 && Attributes.Count == 0)
|
||||
throw new ArgumentNullException($"Can not serialize a AttributeModifiersComponent when the Attributes is empty but NumberOfAttributes is > 0!");
|
||||
|
||||
foreach (var attribute in Attributes)
|
||||
data.AddRange(attribute.Serialize());
|
||||
|
||||
data.AddRange(DataTypes.GetBool(ShowInTooltip));
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
||||
|
||||
public class CanBreakComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public int NumberOfPredicates { get; set; }
|
||||
public List<BlockPredicateSubcomponent1206> BlockPredicates { get; set; } = new();
|
||||
public bool ShowInTooltip { get; set; }
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
NumberOfPredicates = dataTypes.ReadNextVarInt(data);
|
||||
|
||||
for (var i = 0; i < NumberOfPredicates; i++)
|
||||
BlockPredicates.Add((BlockPredicateSubcomponent1206)subComponentRegistry.ParseSubComponent(SubComponents.BlockPredicate, data));
|
||||
|
||||
ShowInTooltip = dataTypes.ReadNextBool(data);
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetVarInt(NumberOfPredicates));
|
||||
|
||||
if(NumberOfPredicates > 0 && BlockPredicates.Count == 0)
|
||||
throw new ArgumentNullException($"Can not serialize a CanBreakComponent when the BlockPredicates is empty but NumberOfPredicates is > 0!");
|
||||
|
||||
foreach (var blockPredicate in BlockPredicates)
|
||||
data.AddRange(blockPredicate.Serialize());
|
||||
|
||||
data.AddRange(DataTypes.GetBool(ShowInTooltip));
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
||||
|
||||
public class CanPlaceOnComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public int NumberOfPredicates { get; set; }
|
||||
public List<BlockPredicateSubcomponent1206> BlockPredicates { get; set; } = new();
|
||||
public bool ShowInTooltip { get; set; }
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
NumberOfPredicates = dataTypes.ReadNextVarInt(data);
|
||||
|
||||
for (var i = 0; i < NumberOfPredicates; i++)
|
||||
BlockPredicates.Add((BlockPredicateSubcomponent1206)subComponentRegistry.ParseSubComponent(SubComponents.BlockPredicate, data));
|
||||
|
||||
ShowInTooltip = dataTypes.ReadNextBool(data);
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetVarInt(NumberOfPredicates));
|
||||
|
||||
if(NumberOfPredicates > 0 && BlockPredicates.Count == 0)
|
||||
throw new ArgumentNullException($"Can not serialize a CanPlaceOnComponent when the BlockPredicates is empty but NumberOfPredicates is > 0!");
|
||||
|
||||
foreach (var blockPredicate in BlockPredicates)
|
||||
data.AddRange(blockPredicate.Serialize());
|
||||
|
||||
data.AddRange(DataTypes.GetBool(ShowInTooltip));
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
||||
|
||||
public class CustomDataComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public Dictionary<string, object>? Nbt { get; set; } = new();
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
Nbt = dataTypes.ReadNextNbt(data);
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetNbt(Nbt));
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
||||
|
||||
public class CustomModelDataComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public int Value { get; set; }
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
Value = dataTypes.ReadNextVarInt(data);
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetVarInt(Value));
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
using MinecraftClient.Protocol.Message;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
||||
|
||||
public class CustomNameComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public string CustomName { get; set; } = string.Empty;
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
CustomName = ChatParser.ParseText(dataTypes.ReadNextString(data));
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetString(CustomName));
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
||||
|
||||
public class DamageComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public int Damage { get; set; }
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
Damage = dataTypes.ReadNextVarInt(data);
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetVarInt(Damage));
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
using System.Collections.Generic;
|
||||
using MinecraftClient.Inventory;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
||||
|
||||
public class EnchantmentsComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public int NumberOfEnchantments { get; set; }
|
||||
public List<Enchantment> Enchantments { get; set; } = new();
|
||||
public bool ShowTooltip { get; set; }
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
NumberOfEnchantments = dataTypes.ReadNextVarInt(data);
|
||||
|
||||
for (var i = 0; i < NumberOfEnchantments; i++)
|
||||
Enchantments.Add(new Enchantment((Enchantments)dataTypes.ReadNextVarInt(data), dataTypes.ReadNextVarInt(data)));
|
||||
|
||||
ShowTooltip = dataTypes.ReadNextBool(data);
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetVarInt(Enchantments.Count));
|
||||
foreach (var enchantment in Enchantments)
|
||||
{
|
||||
data.AddRange(DataTypes.GetVarInt((int)enchantment.Type));
|
||||
data.AddRange(DataTypes.GetVarInt(enchantment.Level));
|
||||
}
|
||||
data.AddRange(DataTypes.GetBool(ShowTooltip));
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
||||
|
||||
public class HideAdditionalTooltipComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : EmptyComponent(dataTypes, subComponentRegistry);
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
||||
|
||||
public class HideTooltipComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : EmptyComponent(dataTypes, subComponentRegistry);
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
using MinecraftClient.Protocol.Message;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
||||
|
||||
public class ItemNameComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public string ItemName { get; set; } = string.Empty;
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
ItemName = ChatParser.ParseText(dataTypes.ReadNextString(data));
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetString(ItemName));
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
using MinecraftClient.Protocol.Message;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
||||
|
||||
public class LoreNameComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public int NumberOfLines { get; set; }
|
||||
public List<string> Lines { get; set; } = [];
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
NumberOfLines = dataTypes.ReadNextVarInt(data);
|
||||
|
||||
if (NumberOfLines <= 0) return;
|
||||
|
||||
for (var i = 0; i < NumberOfLines; i++)
|
||||
Lines.Add(ChatParser.ParseText(dataTypes.ReadNextString(data)));
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetVarInt(Lines.Count));
|
||||
|
||||
if (Lines.Count <= 0) return new Queue<byte>(data);
|
||||
|
||||
foreach (var line in Lines)
|
||||
data.AddRange(DataTypes.GetString(line));
|
||||
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
||||
|
||||
public class MaxDamageComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public int MaxDamage { get; set; }
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
MaxDamage = dataTypes.ReadNextVarInt(data);
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetVarInt(MaxDamage));
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
||||
|
||||
public class MaxStackSizeComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public int MaxStackSize { get; set; }
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
MaxStackSize = dataTypes.ReadNextVarInt(data);
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetVarInt(MaxStackSize));
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
using System.Collections.Generic;
|
||||
using MinecraftClient.Inventory;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
||||
|
||||
public class RarityComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public ItemRarity Rarity { get; set; }
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
Rarity = (ItemRarity)dataTypes.ReadNextVarInt(data);
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetVarInt((int)Rarity));
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
||||
|
||||
public class UnbrekableComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public bool Unbrekable { get; set; }
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
Unbrekable = dataTypes.ReadNextBool(data);
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetBool(Unbrekable));
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +1,16 @@
|
|||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components;
|
||||
|
||||
public class TestSubComonent(DataTypes dataTypes) : SubComponent(dataTypes)
|
||||
public class EmptyComponent(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public int Test { get; set; }
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
Test = DataTypes.ReadNextVarInt(data);
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
return new Queue<byte>();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
|
||||
|
||||
public class AttributeSubComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : SubComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public int TypeId { get; set; }
|
||||
public Guid Uuid { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public double Value { get; set; }
|
||||
public int Operation { get; set; }
|
||||
public int Slot { get; set; }
|
||||
|
||||
protected override void Parse(Queue<byte> data)
|
||||
{
|
||||
TypeId = dataTypes.ReadNextVarInt(data);
|
||||
Uuid = dataTypes.ReadNextUUID(data);
|
||||
Name = dataTypes.ReadNextString(data);
|
||||
Value = dataTypes.ReadNextDouble(data);
|
||||
Operation = dataTypes.ReadNextVarInt(data);
|
||||
Slot = dataTypes.ReadNextVarInt(data);
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetVarInt(TypeId));
|
||||
data.AddRange(DataTypes.GetUUID(Uuid));
|
||||
|
||||
if (string.IsNullOrEmpty(Name?.Trim()))
|
||||
throw new ArgumentNullException($"Can not serialize AttributeSubComponent due to Name being null or empty!");
|
||||
|
||||
data.AddRange(DataTypes.GetString(Name));
|
||||
data.AddRange(DataTypes.GetDouble(Value));
|
||||
data.AddRange(DataTypes.GetVarInt(Operation));
|
||||
data.AddRange(DataTypes.GetVarInt(Slot));
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
|
||||
|
||||
public class BlockPredicateSubcomponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : SubComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public bool HasBlocks { get; set; }
|
||||
public BlockSetSubcomponent1206? BlockSet { get; set; }
|
||||
public bool HasProperities { get; set; }
|
||||
public List<PropertySubComponent1206>? Properties { get; set; }
|
||||
public bool HasNbt { get; set; }
|
||||
public Dictionary<string, object>? Nbt { get; set; }
|
||||
|
||||
protected override void Parse(Queue<byte> data)
|
||||
{
|
||||
HasBlocks = dataTypes.ReadNextBool(data);
|
||||
|
||||
if (HasBlocks)
|
||||
BlockSet = (BlockSetSubcomponent1206)subComponentRegistry.ParseSubComponent(SubComponents.BlockSet, data);
|
||||
|
||||
HasProperities = dataTypes.ReadNextBool(data);
|
||||
|
||||
if (HasProperities)
|
||||
{
|
||||
Properties = new();
|
||||
var numberOfProperties = dataTypes.ReadNextVarInt(data);
|
||||
for (var i = 0; i < numberOfProperties; i++)
|
||||
Properties.Add((PropertySubComponent1206)subComponentRegistry.ParseSubComponent(SubComponents.Property, data));
|
||||
}
|
||||
|
||||
HasNbt = dataTypes.ReadNextBool(data);
|
||||
|
||||
if (HasNbt)
|
||||
Nbt = dataTypes.ReadNextNbt(data);
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
|
||||
// Block Sets
|
||||
data.AddRange(DataTypes.GetBool(HasBlocks));
|
||||
if (HasBlocks)
|
||||
{
|
||||
if(BlockSet == null)
|
||||
throw new ArgumentNullException($"Can not serialize a BlockPredicate when the BlockSet is empty but HasBlocks is true!");
|
||||
|
||||
data.AddRange(BlockSet.Serialize());
|
||||
}
|
||||
|
||||
// Properites
|
||||
data.AddRange(DataTypes.GetBool(HasProperities));
|
||||
if (HasProperities)
|
||||
{
|
||||
if(Properties == null || Properties.Count == 0)
|
||||
throw new ArgumentNullException($"Can not serialize a BlockPredicate when the Properties is empty but HasProperties is true!");
|
||||
|
||||
foreach (var property in Properties)
|
||||
data.AddRange(property.Serialize());
|
||||
}
|
||||
|
||||
// NBT
|
||||
if (HasNbt)
|
||||
{
|
||||
if(Nbt == null)
|
||||
throw new ArgumentNullException($"Can not serialize a BlockPredicate when the Nbt is empty but HasNbt is true!");
|
||||
|
||||
data.AddRange(DataTypes.GetNbt(Nbt));
|
||||
}
|
||||
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
|
||||
|
||||
public class BlockSetSubcomponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : SubComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public int Type { get; set; }
|
||||
public string? TagName { get; set; }
|
||||
public List<int>? BlockIds { get; set; }
|
||||
|
||||
protected override void Parse(Queue<byte> data)
|
||||
{
|
||||
Type = DataTypes.ReadNextVarInt(data);
|
||||
|
||||
if (Type == 0)
|
||||
TagName = dataTypes.ReadNextString(data);
|
||||
|
||||
if (Type == 0) return;
|
||||
|
||||
BlockIds = [];
|
||||
|
||||
for (var i = 0; i < Type - 1; i++)
|
||||
BlockIds.Add(dataTypes.ReadNextVarInt(data));
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetVarInt(Type));
|
||||
if (Type == 0)
|
||||
{
|
||||
if (string.IsNullOrEmpty(TagName?.Trim()))
|
||||
throw new ArgumentNullException($"Can not serialize an empty tag name when the Block Set type is 0!");
|
||||
|
||||
data.AddRange(DataTypes.GetString(TagName));
|
||||
}
|
||||
|
||||
if (Type == 0) return new Queue<byte>(data);
|
||||
|
||||
if(BlockIds == null || BlockIds.Count == 0)
|
||||
throw new ArgumentNullException($"Can not serialize an empty list of Block IDs in a Block Set when the type is not 0!");
|
||||
|
||||
for(var i = 0; i < Type - 1; i++)
|
||||
data.AddRange(DataTypes.GetVarInt(BlockIds[i]));
|
||||
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
|
||||
|
||||
public class PropertySubComponent1206(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : SubComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
public bool IsExactMatch { get; set; }
|
||||
public string? ExactValue { get; set; }
|
||||
public string? MinValue { get; set; }
|
||||
public string? MaxValue { get; set; }
|
||||
|
||||
protected override void Parse(Queue<byte> data)
|
||||
{
|
||||
Name = dataTypes.ReadNextString(data);
|
||||
IsExactMatch = dataTypes.ReadNextBool(data);
|
||||
|
||||
if (IsExactMatch)
|
||||
ExactValue = dataTypes.ReadNextString(data);
|
||||
else // Ranged Match
|
||||
{
|
||||
MinValue = dataTypes.ReadNextString(data);
|
||||
MaxValue = dataTypes.ReadNextString(data);
|
||||
}
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
|
||||
if (string.IsNullOrEmpty(Name?.Trim()))
|
||||
throw new ArgumentNullException($"Can not serialize a Property sub-component if the Name is null or empty!");
|
||||
|
||||
data.AddRange(DataTypes.GetString(Name));
|
||||
data.AddRange(DataTypes.GetBool(IsExactMatch));
|
||||
|
||||
if (IsExactMatch)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ExactValue?.Trim()))
|
||||
throw new ArgumentNullException($"Can not serialize a Property sub-component if the ExactValue is null or empty when the type is Exact Match!");
|
||||
|
||||
data.AddRange(DataTypes.GetString(ExactValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(MinValue?.Trim()) || string.IsNullOrEmpty(MaxValue?.Trim()))
|
||||
throw new ArgumentNullException($"Can not serialize a Property sub-component if the MinValue or MaxValue is null or empty when the type is not Exact Match!");
|
||||
|
||||
data.AddRange(DataTypes.GetString(MinValue));
|
||||
data.AddRange(DataTypes.GetString(MaxValue));
|
||||
}
|
||||
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
|
||||
|
||||
public class SubComponents
|
||||
{
|
||||
public const string BlockPredicate = "BlockPredicate";
|
||||
public const string BlockSet = "BlockSet";
|
||||
public const string Property = "Property";
|
||||
public const string Attribute = "Attribute";
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components;
|
||||
|
||||
public class TestComponent(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public int TestInt { get; set; }
|
||||
public string TestString { get; set; } = null!;
|
||||
|
||||
public TestSubComonent TestSubComonent { get; set; } = null!;
|
||||
|
||||
public override void Parse(Queue<byte> data)
|
||||
{
|
||||
TestInt = dataTypes.ReadNextVarInt(data);
|
||||
TestString = dataTypes.ReadNextString(data);
|
||||
TestSubComonent = (SubComponentRegistry.ParseSubComponent("TestSubComponent", data) as TestSubComonent)!;
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetVarInt(TestInt));
|
||||
data.AddRange(DataTypes.GetString(TestString));
|
||||
data.AddRange(TestSubComonent.Serialize());
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,10 +2,11 @@ using System.Collections.Generic;
|
|||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
public abstract class SubComponent(DataTypes dataTypes)
|
||||
public abstract class SubComponent(DataTypes dataTypes, SubComponentRegistry subComponentRegistry)
|
||||
{
|
||||
protected DataTypes DataTypes { get; private set; } = dataTypes;
|
||||
protected SubComponentRegistry SubComponentRegistry { get; private set; } = subComponentRegistry;
|
||||
|
||||
public abstract void Parse(Queue<byte> data);
|
||||
protected abstract void Parse(Queue<byte> data);
|
||||
public abstract Queue<byte> Serialize();
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
|
|
@ -20,10 +21,15 @@ public abstract class SubComponentRegistry(DataTypes dataTypes)
|
|||
if(!_subComponentParsers.TryGetValue(name, out var subComponentParserType))
|
||||
throw new Exception($"Sub component {name} not registered!");
|
||||
|
||||
var instance= Activator.CreateInstance(subComponentParserType, dataTypes) as SubComponent ??
|
||||
var instance= Activator.CreateInstance(subComponentParserType, dataTypes, this) as SubComponent ??
|
||||
throw new InvalidOperationException($"Could not create instance of a sub component parser type: {subComponentParserType.Name}");
|
||||
|
||||
instance.Parse(data);
|
||||
var parseMethod = instance.GetType().GetMethod("Parse", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
|
||||
if (parseMethod == null)
|
||||
throw new InvalidOperationException($"Sub component parser type {subComponentParserType.Name} does not have a Parse method.");
|
||||
|
||||
parseMethod.Invoke(instance, new object[] { data });
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Registries;
|
||||
|
|
@ -8,6 +8,21 @@ public class StructuredComponentsRegistry1206 : StructuredComponentRegistry
|
|||
public StructuredComponentsRegistry1206(SubComponentRegistry subComponentRegistry, DataTypes dataTypes) : base(
|
||||
subComponentRegistry, dataTypes)
|
||||
{
|
||||
RegisterComponent<TestComponent>(0, "minecraft:test");
|
||||
RegisterComponent<CustomDataComponent1206>(0, "minecraft:custom_data");
|
||||
RegisterComponent<MaxStackSizeComponent1206>(1, "minecraft:max_stack_size");
|
||||
RegisterComponent<MaxDamageComponent1206>(2, "minecraft:max_damage");
|
||||
RegisterComponent<DamageComponent1206>(3, "minecraft:damage");
|
||||
RegisterComponent<UnbrekableComponent1206>(4, "minecraft:unbreakable");
|
||||
RegisterComponent<CustomNameComponent1206>(5, "minecraft:custom_name");
|
||||
RegisterComponent<ItemNameComponent1206>(6, "minecraft:item_name");
|
||||
RegisterComponent<LoreNameComponent1206>(7, "minecraft:lore");
|
||||
RegisterComponent<RarityComponent1206>(8, "minecraft:rarity");
|
||||
RegisterComponent<EnchantmentsComponent1206>(9, "minecraft:enchantments");
|
||||
RegisterComponent<CanPlaceOnComponent1206>(10, "minecraft:can_place_on");
|
||||
RegisterComponent<CanBreakComponent1206>(11, "minecraft:can_break");
|
||||
RegisterComponent<AttributeModifiersComponent1206>(12, "minecraft:attribute_modifiers");
|
||||
RegisterComponent<CustomModelDataComponent1206>(13, "minecraft:custom_model_data");
|
||||
RegisterComponent<HideAdditionalTooltipComponent1206>(14, "minecraft:hide_additional_tooltip");
|
||||
RegisterComponent<HideTooltipComponent1206>(15, "minecraft:hide_tooltip");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_20_6;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Registries.Subcomponents;
|
||||
|
||||
public class SubComponentRegistry1206 : SubComponentRegistry
|
||||
{
|
||||
public SubComponentRegistry1206(DataTypes dataTypes) : base(dataTypes)
|
||||
{
|
||||
RegisterSubComponent<BlockPredicateSubcomponent1206>(SubComponents.BlockPredicate);
|
||||
RegisterSubComponent<BlockSetSubcomponent1206>(SubComponents.BlockSet);
|
||||
RegisterSubComponent<PropertySubComponent1206>(SubComponents.Property);
|
||||
RegisterSubComponent<AttributeSubComponent1206>(SubComponents.Attribute);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Registries.Subcomponents;
|
||||
|
||||
public class TestSubComponentRegistry : SubComponentRegistry
|
||||
{
|
||||
public TestSubComponentRegistry(DataTypes dataTypes) : base(dataTypes)
|
||||
{
|
||||
RegisterSubComponent<TestSubComonent>("TestSubcomponent");
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ public class StructuredComponentsHandler
|
|||
// Get the appropriate subcomponent registry type based on the protocol version and then instantiate it
|
||||
var subcomponentRegistryType = protocolVersion switch
|
||||
{
|
||||
Protocol18Handler.MC_1_20_6_Version => typeof(TestSubComponentRegistry),
|
||||
Protocol18Handler.MC_1_20_6_Version => typeof(SubComponentRegistry1206),
|
||||
_ => throw new NotSupportedException($"Protocol version {protocolVersion} is not supported for subcomponent registries!")
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue