My objective is to create a health bar above the mob's head, and I was thinking about storing the data in a sign, and then setting the mob's CustomName to the sign Text1, but this way I would need a sign for each mob of my world.
1 Answer
Edit
/scoreboard
could help.
scoreboard objectives add health health
# Put the following in a repeating command block
execute as @e[tag=track_health] run data merge @s {CustomName:'{"score":{"name":"@s","objective":"health"}}'}
Old answers
data merge entity @e[tag=track_health,limit=1] {CustomName:'{"nbt":"Health","entity":"@e[tag=track_health,limit=1]"}'
setblock ~ ~ ~ minecraft:sign{Text1:'{"nbt":"Health","entity":"@e[tag=track_health,limit=1]"}'}
-
The /data merge didn't work, I will write exactly what I did: /summon zombie ~ ~ ~ {NoAI:1b,Silent:1b,CustomNameVisible:1b,Tags:[test]} Then, in an Always active Repeating command block I wrote: /data merge entity @e[tag=test,limit=1] {CustomName:'{"nbt":"Health","entity":"@e[tag=test,limit=1]"}'} btw I am playing in 1.16.4– AruBrJun 4, 2021 at 23:25
-
1
-
Yes, that is the problem.
Tags:[test]
is invalid NBT syntax. Also, the repeating command block isn't needed as with the raw JSON text it will automatically update the name– MakonedeJun 5, 2021 at 17:16 -
-
I tried to replace "entity" with "selector", and now his name is @e[tag=test,limit=1]. While doing this, I found out that if I type random words instead of "entity", it has the same result, looks like "entity" is not valid. I remember that in a video the guy explained that you can't do this with entities, so I think I have to use this command in a sign, and then, another command that takes from the sign and gives to the mob. But with this metod, I would need a sign for each mob.– AruBrJun 5, 2021 at 18:16