#saving inventory
1 messages · Page 1 of 1 (latest)
inventory has no coordinates and tags
where do you want to save these values?
uhh idk in some dynamicproperty i just need like 2 functions
save and load
player.setDynamicProperty("propertyName", JSON.stringify(object)) // Save
let data = JSON.parse(player.getDynamicProperty("propertyName")) // Load
but i do i put items in the inventory(with properties)
what items? You first say that you need to save the inventory location, then you need the player location and then some items
the whole invitenory with items
do you need to save inventory to dynamic properties?
If you want to actually save the items with their data and properties (shulker boxes, books, etc) then you need to copy or move them from the player's inventory into a block with an inventory and then save that as a structure and remove it from the world. You can store the structure IDs in a dynamic property.
How do you get them in a structure block?
If I use getItem() won’t it lose their data?
all data will be saved
get an item via getItem, spawn it in the world, save it in the structure, delete it from the world
How do I spawn an item?
Ty
so ive been trying for a while and i have a question, when i use getEntitiesAtBlockLocation() to get the structure i then use the 'item' component, ```js
const itemFromEntity = entity.getComponent('item').itemStack;
entity.remove();
this doesnt seem to save the entity data when i then use the itemstack from this entity, is this normal?
There's something wrong with saving item entities. It doesn't seem to work for me like 90% of the time.
I find that the only reliable way is to create a barrel and put items inside it, then save that block as a structure. Because there's no way to actually check if an entity was saved as a structure