Minecraft – JSON Text to normal text

minecraft-commandsminecraft-java-edition

For some time now I've been trying to make it so that I can have a slab kind of like an altar. And any player/mob head that gets thrown onto that slab will have the SkullOwner be the custom name of the head in question. I imagine you being able to name your player/mob head anything, then throw it on to the slab and have it change to the head of whatever player it was named after.

I have been experimenting with this for quite some time now and this is the command I've come up with:

/data modify entity @e[type=item, sort=nearest, limit=1] Item.tag.SkullOwner set from entity @e[type=item, sort=nearest, limit=1] Item.tag.display.Name

This however doesn't work because the name is stored like this: {"text":"RandomPlayer"}. How could I make it so only the RandomPlayer gets transferred over?

Best Answer

This is not possible. The only things you can do with strings in Minecraft commands is testing for an exact string, storing an exact string, comparing two strings (equal or not) and transferring it from one place in NBT to another. You can not edit strings.

Another possibility to get player skulls would be a loot table, but that only works with either a player name that you specify in the loot table directly or a selector, so a player that is currently online on the server. So you could for example create skulls of the player who threw the item, but not based on the name of the item.