Added more components + added item palette reference

This commit is contained in:
Anon 2024-09-11 20:35:23 +02:00
parent 76e873ed54
commit 49319fe781
44 changed files with 667 additions and 29 deletions

View file

@ -1,11 +1,13 @@
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
public abstract class StructuredComponent(DataTypes dataTypes, SubComponentRegistry subComponentRegistry)
public abstract class StructuredComponent(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
{
protected DataTypes DataTypes { get; private set; } = dataTypes;
protected SubComponentRegistry SubComponentRegistry { get; private set; } = subComponentRegistry;
protected ItemPalette ItemPalette { get; private set; } = itemPalette;
public abstract void Parse(Queue<byte> data);
public abstract Queue<byte> Serialize();

View file

@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
public abstract class StructuredComponentRegistry(SubComponentRegistry subComponentRegistry, DataTypes dataTypes)
public abstract class StructuredComponentRegistry(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
{
private Dictionary<string, Type> ComponentParsers { get; } = new();
private Dictionary<int, string> IdToComponent { get; } = new();
@ -32,7 +33,7 @@ public abstract class StructuredComponentRegistry(SubComponentRegistry subCompon
if (ComponentParsers.TryGetValue(name, out var type))
{
var component =
Activator.CreateInstance(type, dataTypes, subComponentRegistry) as StructuredComponent
Activator.CreateInstance(type, dataTypes, itemPalette, subComponentRegistry) as StructuredComponent
?? throw new InvalidOperationException($"Could not instantiate a parser for a structured component type {name}");
component.Parse(data);