How to get a command block to say the name of a named mob

How to get a command block to say the name of a named mob - White Concrete Stone on Green Grass

I'm making a horse racing track and I want the game to say "[name of horse] has finished the race!" when a horse crosses the finish line. I can get it to say the name of every horse in the area, but not just the one that activates the block.



Best Answer

If you're activating the command block with a pressure plate you could use the @e selector combined with sort=nearest and limit=1 like this:

/tellraw @a ["",{"selector":"@e[sort=nearest,limit=1]"},
{"text":" has finished the race!"}]

If players are riding the horses you could also add type=horse in the selector:

/tellraw @a ["",{"selector":"@e[sort=nearest,limit=1,type=horse]"},
{"text":" has finished the race!"}]



Pictures about "How to get a command block to say the name of a named mob"

How to get a command block to say the name of a named mob - White visiting card with empty space for data placed on light pink background
How to get a command block to say the name of a named mob - Crop unrecognizable person with toy aircraft near multicolored decorative world map with continents attached on white background in light studio
How to get a command block to say the name of a named mob - Table setting with elegant tableware and personalized napkin ring



How do you get a command block to say something with a name?

How to Enter the Command
  • Open the Chat Window. The easiest way to run a command in Minecraft is within the chat window.
  • Type the Command. In this example, we are going to summon a cow named Daisy in Minecraft Java Edition (PC/Mac) 1.18 with the following command: /summon cow ~ ~ ~ {CustomName:"\\"Daisy\\""}


  • How do you give a command block a mob name?

    Steps to Use a Name Tag
  • Place the Anvil. Once you have the required materials, add the anvil to your hotbar so that it is an item that you can use. ...
  • Use the Anvil. To use the anvil, you need to stand in front of it. ...
  • Add the Name to the Name Tag. ...
  • Move the Name Tag to Inventory. ...
  • Put the Name Tag on the Mob.




  • How to Make Mobs Named Dinnerbone Fly | 1.17.1 Command Blocks Java




    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: RODNAE Productions, Angela Roma, Monstera, Tara Winstead