I don't know why so many players say this isn't possible. In fact, it is simple!
Just enter this command into a command block:
/summon Wolf ~ ~1 ~ {Owner:Notch}
Of course, the name Notch
could be replaced with the player's name that you wanted to have it tamed to. @p
does not work! (The command will generate a tamed wolf one block above the command block, tamed to the person of your liking.)
I assume this entire question comes down to "how to print NBT tags A and B of multiple entities like {A1,B1},{A2,B2},{A3,B3}
instead of A1,A2,A3,B1,B2,B3
". The best way I know to do that is to copy the data over somewhere else in a way that already groups it. Previously you needed a dummy item, because they allow any data in their tag
tag. But since 1.15 there is a feature called "storage" that is made specifically for storing custom NBT. So you could create an array of compounds in there.
Unlike the old answer with dummy items, this method requires no preparation at all.
You need to iterate over the horses and create new entries in the array, then fill them (this is also where you can apply sorting, for example by distance). For each horse, do this (until you're out of tagged horses, you can for example do this in a recursive function):
/execute if entity @e[type=horse,tag=!copied] run data modify storage horses HorseAttributes append value {Health:0d,Speed:0d,Jump:0d}
/execute as @e[type=horse,tag=!copied,sort=nearest,limit=1] store result storage horses HorseAttributes[-1].Health double 0.0000005 run data get entity @s Attributes[{Name:"generic.maxHealth"}].Base 2000000
/execute as @e[type=horse,tag=!copied,sort=nearest,limit=1] store result storage horses HorseAttributes[-1].Speed double 0.0000005 run data get entity @s Attributes[{Name:"generic.movementSpeed"}].Base 2000000
/execute as @e[type=horse,tag=!copied,sort=nearest,limit=1] store result storage horses HorseAttributes[-1].Jump double 0.000000001 run data get entity @s Attributes[{Name:"horse.jumpStrength"}].Base 1000000000
/tag @e[type=horse,tag=!copied,sort=nearest,limit=1] add copied
The reason for first scaling the values up and then down again when copying is that for some reason they only get handled as integers. But if you multiply them with a high value first and later divide them by the same number, you get more precision (jumpStrength
for example rounds down to 0 almost every time otherwise). The numbers are chosen to give as much accuracy as possible without ever overflowing (different attributes have different maximum values, that's why they differ).
The array index -1
targets the last compound in the list, the one that was just created.
Now, finally, the output:
/tellraw @s {"storage":"horses","nbt":"HorseAttributes"}
The output can for example look like this:
[{Speed:0.2102355d,Health:21.0d,Jump:0.682921423d},{Speed:0.28055749999999996d,Health:24.0d,Jump:0.819681399d},{Speed:0.2159845d,Health:20.0d,Jump:0.653335773d},{Speed:0.2855935d,Health:25.0d,Jump:0.681110673d},{Speed:0.1827385d,Health:17.0d,Jump:0.750580213d}]
Best Answer
You're confusing NBT and JSON. They have pretty similar syntax, but they are applied in different areas and with different "keys" and "values".
To my knowledge it is impossible to select all wolves of a specific player, because the wolf stores
UUIDLeast
andUUIDMost
of the player, while the player entity storesUUID
. Those can be converted, but not with commands, becauseUUID
is a string.The best you can do is saving all wolves tamed in the future by using the advancement trigger
tame_animal
](https://minecraft.gamepedia.com/Advancements/List_of_triggers#minecraft:tame_animal) (archive).