First Version of Structured Components

This commit is contained in:
Anon 2024-09-01 20:42:39 +02:00
parent 5a6fd577e5
commit 63b027d84a
11 changed files with 314 additions and 26 deletions

View file

@ -0,0 +1,19 @@
using System.Collections.Generic;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
public class TestSubComonent(DataTypes dataTypes) : SubComponent(dataTypes)
{
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();
}
}

View file

@ -0,0 +1,29 @@
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);
}
}