1

Selecting Random Entities with Command Blocks?

Caribik's Avatar Caribik8/8/18 7:32 pm history
1 emeralds 485 3
8/19/2018 11:07 am
ShelLuser's Avatar ShelLuser
I'm trying to select random entities with command blocks, but sadly I cannot come up with a way to do so. Previously I could easily select a random entity by just doing @r[type=ENTITY], but it looks like this cannot be done anymore in 1.12. if anyone can tell me how i could do it, it would be much appreciated.


Nvm, I also dont know how to remove this post lol
Posted by Caribik's Avatar
Caribik
Level 54 : Grandmaster Creeper Hugger
14

Create an account or sign in to comment.

3

1
08/19/2018 11:07 am
Level 57 : Grandmaster Engineer
ShelLuser
ShelLuser's Avatar
You mentioned 1.12 but re-reading the post I think you meant 1.13. If you found the solution then it's much nicer to share it so that other players can also benefit from it.

Anyway, guess it's up to me then.

While you can't specify a type using @r in 1.13 you can do so using @e. This still leaves you with the problem of getting a random entity, that's where sort= and limit= come into play. You can use a random selection ('sort') and then limit it to 1 entity:

execute as @e[type=ENTITY,sort=random,limit=1] run say I am randomized :)

If you need to run the command at the entities location (for example: because you want to perform tests, like checking the block below it) then you can extend on this using: at @s.
1
08/11/2018 12:23 am
Level 57 : Grandmaster Engineer
ShelLuser
ShelLuser's Avatar
What makes you think this doesn't work in 1.12? Works just fine for me.

Are you sure you used the right entity type?
1
08/08/2018 7:42 pm
Level 53 : Grandmaster Lego Builder
CGBrothers
CGBrothers's Avatar
Are you on 1.13? The change is worth it. Gives us a sort parameter which is neat
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome