2
Hi, this is a complicated issue but I want to store an entity's UUID in an item's tags.
I've tried something that looks a little like this (I don't have Minecraft open right now, so forgive any inaccuracies in the syntax, this is purely for illustrative exampling):
Even when doing a similar thing but to a dropped item, it said that the data was successfully modified, but when I checked it, there was no change.
How can I do this? Is it even possible?
I've tried something that looks a little like this (I don't have Minecraft open right now, so forgive any inaccuracies in the syntax, this is purely for illustrative exampling):
/give @s book{UUID:[I;0,0,0,0]}
/data modify entity @s SelectedItem.tags.UUID set from entity <wanted entity> UUID
However, this and several other variants always return an error, either stating that it was "expecting an object but got <value> instead" or "unable to modify player's data".Even when doing a similar thing but to a dropped item, it said that the data was successfully modified, but when I checked it, there was no change.
How can I do this? Is it even possible?
Create an account or sign in to comment.
6
Alr, so i did what you wanted:
First, give the item:
Then throw it on the ground and execute:
now you have ur uuid in the items fuuid array.
If you want to do that in the inventory:
you need to use item modifiers - would look something like this:
You do need to store the uuid of the player in the storage first, tho, then execute the item modifier
I havent tested the Item Modifier thing ingame, since i have to create a datapack for that. The data modify thingy works tho ^^
If u have any questions feel free to add me on disc, and we can have a look ^^
First, give the item:
/give @s dropper{fuuid:[1,2,3,4]} 1
Then throw it on the ground and execute:
/data modify entity @e[type=minecraft:item,limit=1,sort=nearest] Item.tag.fuuid set from entity @s UUID
now you have ur uuid in the items fuuid array.
If you want to do that in the inventory:
you need to use item modifiers - would look something like this:
[
{
"function": "minecraft:copy_nbt",
"source": {
"type": "minecraft:storage",
"source": "minecraft:Stroage_path"
},
"ops": [
{
"source": "strorage_source",
"target": "Item.tag.fuuid",
"op": "replace"
}
]
}
]
You do need to store the uuid of the player in the storage first, tho, then execute the item modifier
I havent tested the Item Modifier thing ingame, since i have to create a datapack for that. The data modify thingy works tho ^^
If u have any questions feel free to add me on disc, and we can have a look ^^
Wow! That's actually pretty much perfect as far as I can tell, thanks
UUID is too large to store as a numeric in NBT format. You can't modify NBT data of players. And two entities can't share the same UUID.
But entities can have scores in vanilla, and the setting can be re-enabled on multiplayer servers running spigot/paper forks that disable the behavior in the settings files.
With this in mind, you can create a scoreboard for unique individualized IDs and then assign each single player (@p) a score to represent this ID, then increment a fake player score value (ie: $system) so that on the next loop it assigns a different ID score to a different player. You can then use the execute store command to store the player's ID score as an entity's score.
on load
on tick/recursive scheduled loop
assign function
But entities can have scores in vanilla, and the setting can be re-enabled on multiplayer servers running spigot/paper forks that disable the behavior in the settings files.
With this in mind, you can create a scoreboard for unique individualized IDs and then assign each single player (@p) a score to represent this ID, then increment a fake player score value (ie: $system) so that on the next loop it assigns a different ID score to a different player. You can then use the execute store command to store the player's ID score as an entity's score.
on load
scoreboard objectives add my.uuid dummy
scoreboard objectives set $system my.uuid -2147483648
(-2147483648 is the lowest value that can be stored in the scoreboard, using this ensures we likely never run out of numbers to assign as a UUID value)on tick/recursive scheduled loop
execute as @p unless score @s my.uuid = @s my.uuid run function namespace:assign
(we have to be sure to use @p and not @a because we don't want this to execute as every player at once, giving them potentially conflicting uuid scores)assign function
execute store result score @s my.uuid run scoreboard players get $system my.uuid
scoreboard players add $system my.uuid 1
I appreciate the help, but there are some issues with your solution.
First of all, I know that two entities can't share the same UUID, that's not what I was doing. Storing any value in an item that isn't its ID or its stack would then be moved to the `tag` NBT, like {id:"minecraft:book",Count:1b,tag:{UUID:[I;0,0,0,0]}}. Additionally, the UUID of an entity is stored in its NBT data, so I'm pretty sure it can fit.
Furthermore, this solution is not at all what I need. I'm trying to get some way to attach an item to a specific entity, and the only way I can think of doing that is by storing their UUID (or possibly a partial segment of the four-part array that is the UUID NBT tag) in the item's data.
Thanks anyways.
First of all, I know that two entities can't share the same UUID, that's not what I was doing. Storing any value in an item that isn't its ID or its stack would then be moved to the `tag` NBT, like {id:"minecraft:book",Count:1b,tag:{UUID:[I;0,0,0,0]}}. Additionally, the UUID of an entity is stored in its NBT data, so I'm pretty sure it can fit.
Furthermore, this solution is not at all what I need. I'm trying to get some way to attach an item to a specific entity, and the only way I can think of doing that is by storing their UUID (or possibly a partial segment of the four-part array that is the UUID NBT tag) in the item's data.
Thanks anyways.
Additionally, the UUID of an entity is stored in its NBT data, so I'm pretty sure it can fit.
Yes, as an array object. UUID[0], UUID[1], UUID[2], and UUID[3] respectively for each of the 4 parts. You can't store the entire array as a single numeric value which is what I previously stated.
Furthermore, this solution is not at all what I need. I'm trying to get some way to attach an item to a specific entity, and the only way I can think of doing that is by storing their UUID (or possibly a partial segment of the four-part array that is the UUID NBT tag) in the item's data.To modify an item the player is holding you have to use the /item command, but this doesn't allow you the same scope of operation that the /data command does which unfortunately isn't able to modify players in any scope. Likewise, unless you plan on storing all 4 parts of the UUID and matching them then you need to create an independent ID system so that there's no potential overlap.
(EDIT: It's important to note that there can be overlapping if you only try to match 1 portion of the UUID because its conversion to 32-bit integer format from a 128-bit long number can and often does result in entities sometimes having the same numbers as part of their overall UUID)
My line of thinking was that if one of your players dropped one of these special items that have yet to receive a specialized ID you would need to manipulate it in entity form once it is dropped and then attach the identifier and then perform the functions to retrieve it, but it seems you have a better idea of ways to go about that.
Anywho, good luck! 🙏
thanks