1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Random block spawn

Discussion in 'Development' started by #A6543, Feb 19, 2017.

  1. #A6543

    #A6543 Zombie

    Messages:
    267
    How can I randomly set/spawn blocks in my world (and remove)? I want to spawn stone blocks all over the world (only over trees and grass...)
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    This is a tricky question. There are many ways to do it, but the method that won't affect the server's performance at all would be to override the generator, which can be done easily.
    However, there's a problem you'll be facing..
     
  3. kaliiks

    kaliiks Zombie

    Messages:
    250
    PHP:
    $level $this->getServer()->getLevelByName("Your Level");
    $x =mt_ rand(0255);
    $z mt_rand(0255);
    $y mt_rand($level->getHighestBlockAt($x$z), 127);
    $pos = new Vector3($x$y$z);
    $block 5;
    $level->setBlock($pos$block);
    This may help you it spawn random block but idk how over tree and grass
     
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    $block should be Block::get(5)
     
  5. #A6543

    #A6543 Zombie

    Messages:
    267
    And how can I remove all blocks with that id from the level?

    *Your code isn't working (I already added a space to the =)
    Code:
     "syntax error, unexpected 'rand' (
     
    Last edited: Feb 19, 2017
  6. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    change
    PHP:
    $x =mt_ rand(0255);
    to

    PHP:
    $x mt_rand(0255);
     
  7. #A6543

    #A6543 Zombie

    Messages:
    267
    I already did that...
     
  8. #A6543

    #A6543 Zombie

    Messages:
    267
    But this code now only spawns one block. How can I spawn then in spaces all over the world?
     
  9. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    PHP dosent care about whatever code style you use

    PS you should store the vector so to be removed latter
     
  10. #A6543

    #A6543 Zombie

    Messages:
    267
    How can I spawn the blocks in spaces all over the world?
     
  11. #A6543

    #A6543 Zombie

    Messages:
    267
    Or ist there another way?
     
  12. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    As I've already said, a custom generator is your only choice. That's gonna lag your server hard^
     
    Sandertv likes this.
  13. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    you still need some way to figure out where the heck these blocks you spawned went/are
     
  14. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
     
  15. #A6543

    #A6543 Zombie

    Messages:
    267
    But how can I do that? And is there a way to add
     
  16. #A6543

    #A6543 Zombie

    Messages:
    267
    I can't use a generator, because I need to spawn and despawen the blocks in a Minigame. What I the best method?
     
  17. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.