feat(inventory): expose NBT/component data in inventory MCP tools#3163
Merged
Conversation
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`.
Member
|
Thank you for your contribution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Right now the inventory tools only return item type and count, which makes it impossible to distinguish a renamed item from a plain one, read server-specific metadata (custom_data), or check enchantments and potion contents. The material name alone isn't enough for most real automation tasks.
This adds a nullable
Nbtfield toMccInventorySnapshotSlot,MccInventorySearchMatch, andMccItemStackSnapshot:"minecraft:custom_data","minecraft:enchantments","minecraft:custom_name"To make this work,
StructuredComponentnow stores the registry name it was parsed under (ComponentName), set inParseComponent()alongside the existingTypeId. Both are marked[JsonIgnore]so they don't appear in the serialized output.BuildNbtusesc.GetType()when callingJsonSerializer.SerializeToElement- necessary because the list elements are typed as the abstract base class and the default serializer would otherwise produce empty objects.Tested against a 1.21.11 server with a mix of custom items (custom_data, enchantments, block_entity_data) and vanilla items.