2

I have the following commands:

data modify block -107 78 -525 Text1 set from entity @e[limit=1,tag=test] CustomName
data modify block -107 78 -525 Text2 set from entity @e[limit=1,tag=test] Health
data modify block -107 78 -525 Text3 set from entity @e[limit=1,tag=test] Attributes[0].Base
data modify block -107 78 -525 Text4 set from entity @e[limit=1,tag=test] HurtTime

Those are just examples but for some reason, only the CustomName works. None of the other commands work, although I have no idea why.

I'm playing on a server and I was using a pig to test this.

1
  • 1
    Because "Custom name" has text value, health has other type of value. But i don't know how to transfer it to text.
    – QmegaMax
    Commented Mar 24, 2021 at 9:37

1 Answer 1

2

As you may or may not know, the text tags of signs are JSON text tags, meaning they have to be entered in a certain format. The only reason the custom name works is because it is also a JSON text tag. The others are not JSON text tags, so they can't be written directly to the sign text tags.

The only alternative is to use the raw JSON text nbt element which tells the JSON text reader to check for NBT and render it. Try this:

data modify block -107 78 -525 Text2 set value '{"nbt":"Health","entity":"@e[limit=1,tag=test]"}'
data modify block -107 78 -525 Text3 set value '{"nbt":"Attributes[0].Base","entity":"@e[limit=1,tag=test]"}'
data modify block -107 78 -525 Text4 set value '{"nbt":"HurtTime","entity":"@e[limit=1,tag=test]"}'

Note that in order to correctly render the nbt element, the system has to convert them into text elements instead with the correct value. This is called component resolution. This resolution can only happen with signs, and some select other areas.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .