[feature] NBT API for ItemStack
as the title
I put an enchanted_book in the first slot of slot.hotbar. I use the"print(str(self.server.get_player(sender.name).inventory.get_item(0)))" and the console returns: ItemStack(minecraft:enchanted_book x 1) whitout any nbt. but when I use"self.server.get_player(sender.name).inventory.add_item(self.server.get_player(sender.name).inventory.get_item(0))" I find that the enchanted_book is successfully copied with nbt. WHERE WAS THE NBT STORAGED?
The NBT data is stored internally within the handle to the ItemStack hence it is preserved during operations like copying. However, currently, there is no way to directly access or modify the NBT data.
I am planning to introduce a (very basic) NBT API in the next version which will allow you to interact with the NBT data of ItemStack objects directly.
The NBT data is stored internally within the handle to the
ItemStackhence it is preserved during operations like copying. However, currently, there is no way to directly access or modify the NBT data.I am planning to introduce a (very basic) NBT API in the next version which will allow you to interact with the NBT data of ItemStack objects directly.
There are also player nbt, physical nbt, creature nbt, block nbt
This issue has been automatically marked as stale because it did not have recent activity. It will be closed in 15 days if no further activity occurs. If you wish not to mark it as stale, please leave a comment in this issue.
1
This issue has been automatically marked as stale because it did not have recent activity. It will be closed in 15 days if no further activity occurs. If you wish not to mark it as stale, please leave a comment in this issue.
1
I wonder vincent if you are going to implement nbt serializing/deserializing yourself or going to use an already written library, reasons I'm asking to keep this issue opened and also curious of what you planning
@programminglaboratorys Most item metadata can already be accessed and modified via the ItemMeta API. We’re still evaluating whether it’s necessary to expose a low-level NBT API.
For storing custom data, a Persistent Data Container (PDC) API would be safer and more appropriate. With the PDC API, we can eliminate the need to support every NBT type - users can pass a Python dict directly instead of writing wrappers for each NBT tag.
For example, with a PDC API, one may write:
item.custom_data = {
'font': 'Roboto',
'size': 14,
'items': ['apple', 'banana', 'orange'],
'flag': True,
}
Instead of:
from endstone.nbt import ByteTag, CompoundTag, IntTag, ListTag, StringTag
item.nbt['custom_data'] = CompoundTag({
'font': StringTag('Roboto'),
'size': IntTag(14),
'items': ListTag(StringTag('apple'), StringTag('banana'), StringTag('orange')),
'flag': ByteTag(1)
})
Direct binary NBT operations aren’t under consideration at this stage, due to uncertainty like endianness, varint encoding, and the risk of corrupting item data with malformed payloads.
I would say that probably dictionary is the better way for this
This issue has been automatically marked as stale because it did not have recent activity. It will be closed in 15 days if no further activity occurs. If you wish not to mark it as stale, please leave a comment in this issue.
clearly want to keep this open till further updates
This issue has been automatically marked as stale because it did not have recent activity. It will be closed in 15 days if no further activity occurs. If you wish not to mark it as stale, please leave a comment in this issue.
This issue has been automatically marked as stale because it did not have recent activity. It will be closed in 15 days if no further activity occurs. If you wish not to mark it as stale, please leave a comment in this issue.
guh
Two methods will be added to ItemStack class since v0.11, ItemStack::fromNbt and ItemStack::toNbt.