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 ) "


"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.

  • what's going on with the markers? I don't understand what they have to do with this command? Do you want the name of the main marker in chat and then the name of the closest sub marker as the hover text? what is TEST.A?
    – Plagiatus
    Jan 27 at 11:17
  • OK, I was a little short on the wording, so I fixed it. You want to run at markers tagged "main" and have the hover text display the name of the marker tagged "sub" near each of the main markers. TEST.A and TEST.B indicate the name of the sub marker. "Chat: entityA(hovertext: TEST.A), entityB(hovertext: TEST.B), entityC(hovertext: TEST.C), ..." This means that we want to display two entities side by side in the execution process: a marker with a MAIN tag and a marker for hovertext with a SUBTAG near it. There will be more than one entity after entityC as the number is unspecified.
    – wood
    Jan 27 at 14:07
  • alright, that makes sense now. posted the answer below. :)
    – Plagiatus
    Jan 30 at 6:55

1 Answer 1


You might be able to do some string concatenation trickery to get to your ideal result, but the easiest one to achieve would be

"Chat: entityA (hovertext: TEST.A ) "
"Chat: entityB (hovertext: TEST.B ) "

The command you're using is already close to achieving that, but it needs a few adjustments.

First of all, we'll want to execute both as and at the main markers. That way we can access them using @s and the location is also changed to their position.

execute as @e[type=marker,tag=main] at @s ...

now onto the tellraw command. For the first set of NBT, we can refer to @s, as that is the marker entity we just selected in the execute.

{"nbt":"CustomName","entity":"@s", ... }

now comes the hover text, where we want to make sure we select the one sub marker that is closest to the executing main marker.


So all in all the full command should look like this:

execute as @e[type=marker,tag=main] at @s run tellraw @a {"nbt":"CustomName","entity":"@s","hoverEvent":{"action":"show_text","contents":[{"nbt":"CustomName","entity":"@e[type=marker,tag=sub,sort=nearest,limit=1,distance=..1]"}]}}

You must log in to answer this question.

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