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
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue