We've split up the commands, scripting and mods, and add ons category! Please be sure you get your thread in the right place.

5

Let "/spreadplayers under maxHeight" use tilde notation

2 Comments

Please sign in to leave a comment.

Sorted by oldest
  • 1
    Registered User commented
    Comment actions Permalink

    For now you can attach a chain command block onto the end of the impulse / repeating with the command "execute as @s(The same as the selector in the original command) run tp @s ~ (Y) ~" or execute @s(The same as the selector in the original command) ~~~ tp @s ~ (Y) ~

  • 0
    Registered User commented
    Comment actions Permalink

    BEMZlabs

    That works in some cases, but I'm using /spreadplayers because it automatically finds valid positions for entities to be placed that aren't in walls or over lava, which you can't be sure of if you just /tp them.

    I'd like to be able to randomly place an entity at a similar height to a player, but the player's height varies. When I say you'd have to check the caller's height and run different commands on a case-by-case basis, I mean having a bunch of different /spreadplayers for each range of heights. This is what I've done:

    /execute as @s[y=0,dy=16] run spreadplayers ~ ~ 0.0 10 under 16 @e[name=bar]

    /execute as @s[y=16,dy=16] run spreadplayers ~ ~ 0.0 10 under 32 @e[name=bar]

    /execute as @s[y=32,dy=16] run spreadplayers ~ ~ 0.0 10 under 48 @e[name=bar]

    etc, all the way to y256.

    This will place "bar" at a position no more than 16 blocks higher from the chosen player, and usually not much lower (for the most part).

    As far as I can tell, there's no simpler way to do this currently. If I don't include under <maxHeight>, it'll place "bar" at the highest y value possible. But I want to be running this command in the nether, so  "bar" will end up on top of the nether roof. If I use under 128, "bar" could end up in some nether caves up at y100 while the player is mining for netherite at y16. I'd prefer to place "bar" somewhere close, if possible. So I have the check for every 16 blocks.

    If <maxHeight> could take tilde notation, all those commands could be reduced to just one.