mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
feat(inventory): expose NBT/component data in inventory MCP tools
Add a nullable `Nbt` field to `MccInventorySnapshotSlot`, `MccInventorySearchMatch`, and `MccItemStackSnapshot` so that callers can access the full item metadata beyond just material and count. For 1.20.6+ servers the field is a map of component name (e.g. "minecraft:custom_data") to the serialized component object. For legacy servers it is the raw NBT dictionary. The field is omitted entirely for vanilla items that carry no extra data, so there is no noise for plain items like Stone or Dirt. Implementation: - `StructuredComponent`: add `ComponentName` property (set by the registry during parse) and mark both it and `TypeId` with `[JsonIgnore]` so they are excluded from component serialization. - `StructuredComponentRegistry.ParseComponent`: assign `ComponentName` after instantiation. - `MccGameCommon.BuildNbt`: new helper that serializes components by runtime type (fixing the polymorphism issue with System.Text.Json) keyed by component name, falling back to the legacy NBT dictionary. - Snapshot and search query builders updated to call `BuildNbt`.
This commit is contained in:
parent
95031338bf
commit
f34b8ba989
5 changed files with 33 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
using MinecraftClient.Inventory.ItemPalettes;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
|
@ -12,8 +13,15 @@ public abstract class StructuredComponent(DataTypes dataTypes, ItemPalette itemP
|
|||
/// <summary>
|
||||
/// The registry type ID assigned during parsing, used for round-trip serialization.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public int TypeId { get; set; } = -1;
|
||||
|
||||
/// <summary>
|
||||
/// The registry name assigned during parsing (e.g. "minecraft:custom_data"), used for NBT serialization.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
|
||||
public abstract void Parse(Queue<byte> data);
|
||||
public abstract Queue<byte> Serialize();
|
||||
}
|
||||
|
|
@ -37,6 +37,7 @@ public abstract class StructuredComponentRegistry(DataTypes dataTypes, ItemPalet
|
|||
?? throw new InvalidOperationException($"Could not instantiate a parser for a structured component type {name}");
|
||||
|
||||
component.TypeId = id;
|
||||
component.ComponentName = name;
|
||||
component.Parse(data);
|
||||
return component;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue