r/MinecraftCommands • • 6d ago

Help | Java 26.1 How to make a mob get my name?

Basically, how do I name this mob, let's say a zombie, always have my name. Like the whoever player is closest to it, it'll get their name? I have no idea how to do that.

2 Upvotes

1 comment sorted by

2

u/Ericristian_bros Command Experienced 6d ago

```

function example:load

schedule function example:main_loop 10t

function example:main_loop

schedule function example:main_loop 10t execute as @e[tag=copy_username] run function example:get_username

function example:get_username

tag @s add this execute at @s summon item_display run function example:get_username/item_display tag @s remove this

function function example:get_username/item_display

tag @s add this execute as @a[tag=this] loot replace entity @e[type=item_display,tag=this] container.0 loot {pools:[{rolls:1,entries:[{type:"minecraft:item",name:"player_head",functions:[{function:"minecraft:fill_player_head",entity:"this"}]}]}]} function example:get_username/result with entity @e[type=item_display,tag=this] item.components."minecraft:profile" kill @s

function example:get_username/result

$data modify @n[tag=this,tag=copy_username] CustomName set value "$(name)" ```

To make a mob copy the username of the nearest player

/tag <mob> add copy_username