Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Spawn random blocks

Comments in 'Plugin Development' started by Angelo Vidrio, Mar 5, 2015.

  1. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    Is it possible to use:
    PHP:
    $x rand(0255);
    $y rand(0127);
    $z rand(0255);
    $pos $this->getServer()->getLevelByName("world")->getSafeSpawn(new Vector3($x$y$z));
    $block 5;
    $this->getServer()->getLevelByName("world")->setBlock($pos$block);
    To spawn blocks in a random place without them spawning underground?
  2. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    I would do the following
    PHP:
    $level $this->getServer()->getLevelByName("world");
    $x rand(0255);
    $z rand(0255);
    $y rand($level->getHighestBlockAt($x$z), 127);
    $pos = new Vector3($x$y$z);
    $block 5;
    $level->setBlock($pos$block);
    Angelo Vidrio likes this.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    mt_rand() is better than rand()

Share This Page

Advertisement