I am using a datapack and creating a command, but after getting all the entities with @e in tellraw, I want to display the nbt of each entity. In this case I am trying to use the CustomName of that entity. Among the things I have tried are.
"Chat: entityA (hovertext: TEST.A ) "
"Chat: entityB (hovertext: TEST.B ) "
or
"Chat: entityA, entityB (hovertext: TEST.A TEST B )"
and they are displayed together. My ideal would be
"Chat: entityA(hovertext: TEST.A), entityB(hovertext: TEST.B), entityC(hovertext: TEST.C), ..."
Starting from a marker with tag "main", I want the hover text to display the name of that marker and the name of an additional marker with tag "sub" that is near the marker with tag "main". What is not done here is that I want to execute the same process as above for multiple markers.
Since the number of entities is unspecified, I would like to use @e as much as possible to shorten it. Any other suggestions would be appreciated.
Here is the command
/execute at @e[tag=main,type=marker] run tellraw @a {"nbt":"CustomName","entity":"@e[tag=main,type=marker]","interpret":true,"hoverEvent":{"action":"show_text","contents":{"nbt":"CustomName","entity":"@e[tag=sub,type=marker,distance=..1]","interpret":true}}}
The execution location is the location of tag:main. sub's marker is spawned in the same location as main's.
Version is 1.19.2.