Is it possible to use target selectors in the name of an item? If so, is it possible to concatenate this with some other text? For example giving a sword named "Sword of <@p>"
This is a common question, and here is why this can't be done directly. With /tellraw, you can print out a player's name in chat like this:
/tellraw @s {"selector":"@s"}
as you can see, there is a statement which tells the game that it should concatenate the name of the player into the output and then print it. This works because the arguments are parsed before they are printed out. Now let's try to do the same with an item's name:
Im working on a datapack, the player drops an iron_ingot and experience_bottle both items are merge into a especial iron_ingot with a custom tags, the question is how can i get the item lore the exact name of the player that drops the items?
Change "@p" to whatever you want the selector to be for the name displayed on the ingot (you could tag people based on if they dropped the items and then use something like "@a[tag=dropped]" or you could use predicates)
Then spawn the iron ingot with the /loot command whenever and wherever you want it to spawn
If you have questions about anything feel free to ask and i'll go more in depth
Is it possible to use target selectors in the name of an item? If so, is it possible to concatenate this with some other text? For example giving a sword named "Sword of <@p>"
This is a common question, and here is why this can't be done directly. With /tellraw, you can print out a player's name in chat like this:
as you can see, there is a statement which tells the game that it should concatenate the name of the player into the output and then print it. This works because the arguments are parsed before they are printed out. Now let's try to do the same with an item's name:
this command will give you a stick named "@s". I think this is because the game doesn't parse this part as it does with /tellraw.
So here is the workaround. You can place a sign (because signs are parsed) and use the selector statement to display the player's name on the sign:
and there is your source ^, now you can store that into the item with /data:
^ that's if your item is on the ground. If it's in a chest, use this:
and replace the 0 in Items[0] with the index of the chest stlot your item is in.
Command block engineer // Developer // #TeamTrees
Im working on a datapack, the player drops an iron_ingot and experience_bottle both items are merge into a especial iron_ingot with a custom tags, the question is how can i get the item lore the exact name of the player that drops the items?
The pack_format is 7 for Minecraft 1.17x
Is there a way to do this with SkullOwner as well? When I try this method it's just a long json file that I can't get through because it's in a string
Use loot tables to set the lore or name
Change "@p" to whatever you want the selector to be for the name displayed on the ingot (you could tag people based on if they dropped the items and then use something like "@a[tag=dropped]" or you could use predicates)
Then spawn the iron ingot with the /loot command whenever and wherever you want it to spawn
If you have questions about anything feel free to ask and i'll go more in depth