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

Creating a Skyblock Island generator, setBlock() wont work as it should be!

Discussion in 'Plugin Help' started by PapaTulac, May 28, 2020.

  1. PapaTulac

    PapaTulac Spider

    Messages:
    6
    GitHub:
    papatulac
    everything works fine except for the setBlock()'s, here is my code:

    PHP:
    public function generateIsland(Player $player) {
        
    $name $player->getName();
        
    $this->getServer()->loadLevel($name);
        if(
    $this->getServer()->getLevelByName($name) instanceof Level) {
            
    $player->sendMessage(TF::BOLD TF::GRAY "[" TF::GOLD "ML" TF::WHITE "BE" TF::GRAY "]" TF::RESET .  TF::RED " You already made an Island!");
            return;
        }
        
    $this->getServer()->generateLevel($namenull"pocketmine\level\generator\Flat", ["preset" => "2;0;1"]);
        
    $level $this->getServer()->getLevelByName($name);
        
    $grass Block::get(2);
        
    $dirt Block::get(3);
        
    $stone Block::get(1);
        
        for(
    $x 251$x <= 261$x++) {
            
    $z 251;
            while(
    $z <= 261) {
                
    $level->setBlock(new Vector3($x60$z), $grass);
                
    $level->setBlock(new Vector3($x59$z), $dirt);
                
    $level->setBlock(new Vector3($x58$z), $dirt);
                
    $level->setBlock(new Vector3($x58$z), $dirt);
                
    $level->setBlock(new Vector3($x57$z), $stone);
                
    $z++;
            }
        }
        
    $player->sendMessage(TF::BOLD TF::GRAY "[" TF::GOLD "ML" TF::WHITE "BE" TF::GRAY "]" TF::RESET " Your island has been made!");
    }
     
  2. KingOfTurkey38

    KingOfTurkey38 Spider

    Messages:
    7
    Be sure that the chunks are loaded before you setBlock
     
  3. PapaTulac

    PapaTulac Spider

    Messages:
    6
    GitHub:
    papatulac
    ow well, how would I do that?
     
  4. KingOfTurkey38

    KingOfTurkey38 Spider

    Messages:
    7
    Level->loadChunk($x, $z)
     
  5. PapaTulac

    PapaTulac Spider

    Messages:
    6
    GitHub:
    papatulac
    ok thx imma try that
     
  6. PapaTulac

    PapaTulac Spider

    Messages:
    6
    GitHub:
    papatulac
    now im having errors:
    Code:
    [Server thread/CRITICAL]: Error: "Call to a member function loadChunk() on null" (EXCEPTION) in "plugins/MLBESkyblock/src/mlbe/skyblock/Core" at line 49
    I just put the code you gave me here:

    PHP:
    for($x 251$x <= 261$x++) {
        
    $z 251;
        while(
    $z <= 261) {
            
    $level->loadChunk($x$z);
            
    $level->setBlock(new Vector3($x60$z), $grass);
            
    $level->setBlock(new Vector3($x59$z), $dirt);
            
    $level->setBlock(new Vector3($x58$z), $dirt);
            
    $level->setBlock(new Vector3($x58$z), $dirt);
            
    $level->setBlock(new Vector3($x57$z), $stone);
            
    $z++;
        }
    }
     
  7. KingOfTurkey38

    KingOfTurkey38 Spider

    Messages:
    7
    $level is a null variable getLevelByName probably returned null
     
  8. PapaTulac

    PapaTulac Spider

    Messages:
    6
    GitHub:
    papatulac
    wut if there isnt any block to load? how will I put blocks?
     
  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.