Minecraft - Get skull with owner of custom named item
Was wondering if it was possible to do this. I want to make a name tag or other item that, when dropped, will give the player the skull of the player specified in the name of the name tag. Is this possible in any way?
Solution 1:
No, you cannot do that, because item names are stored as a JSON string, not a regular string. So when you name an item Steve
in an anvil, its NBT data actually contains {"text":"Steve"}
. This is useful if you wanted to colour names or do other fancy stuff with it, but in your case it's preventing you from doing what you want. And the game has no ways to manipulate a string (except for some complicated stuff that is not relevant here), not even converting it from JSON to a regular string.
But there are in fact two places where a Survival player can store a regular string: A writeable book page (only before signing, afterwards it becomes JSON) and a written book title (after signing). So you can for example instruct the player to name a book and then throw it.
I assume you probably have some mechanism of determining which item to select as the source of the name, so let's say you have it tagged with "source
". Now you can first summon an item of a default player skull:
/summon item ~ ~ ~ {Item:{id:"player_head",Count:1},Tags:["target"]}
And then you can copy the name over:
/data modify entity @e[type=item,tag=target,limit=1] Item.tag.SkullOwner set from entity @e[type=item,tag=source,limit=1] Item.tag.title
And just in case the item still lies on the ground when the player wants to get another head, you should clean up the tag:
/tag @e[type=item,tag=target,limit=1] remove target
And you probably want to remove the thrown book:
/kill @e[type=item,tag=source]