Minecraft – Command block questions using the execute command

minecraft-commandsminecraft-java-edition

What I want to do is use the execute command to randomly pick a custom named mob or entity. I already have this command:

execute @r[type=Boat] ~ ~ ~ setblock ~ ~-2 ~ redstone_block

which I am using to place a redstone block and select one of five categories, but then if I want to use the same command on a sheep, for example, I want it to select from the ones I summon and not randomly find one in the wild (which I figure that's what it's doing, because it was saying that the command was executed properly). The problem is that I have no idea how to go about making that work. I've tried a couple of things, but it either came back with an error or executed it on a random mob in the wild.

Best Answer

You could summon the sheep with something like a custom name or scoreboard tag, then specify that name/tag in your selector:

summon Sheep ~ ~ ~ {Tags:["Summoned"]}

Then:

execute @r[type=Sheep,tag=Summoned] ~ ~ ~ setblock ~ ~-2 ~ redstone_block
Related Topic