Skip to content

Generators

GiantQuartz edited this page Mar 27, 2020 · 1 revision

Adding a custom generator

Creating the generator

This is one of the questions that I have received the most since I created this project. First, you must create a class that extends the class IslandGenerator, it will require you to implement a few methods.

getName()

This method should return the name of the generator.

public function getName(): string {
   return "examplename";
}

getWorldSpawn()

This method should return the coordinates where the player will initially spawn on the island.

public function getWorldSpawn(): Vector3 {
   return new Vector3(123, 123, 123);
}

getChestPosition()

This method should return the coordinates where the initial chest will spawn.

public function getChestPosition(): Vector3 {
   return new Vector3(123, 123, 123);
}

generateChunk($chunkX, $chunkY)

This is where the action occurs. Here you have to indicate how each chunk is going to be generated and with which blocks. Most islands don't need more than one chunk, if that's your case, you could do something like this:

public function generateChunk($chunkX, $chunkY): void {
   $chunk = $this->level->getChunk($chunkX, $chunkZ);
   $chunk->setGenerated();

   if($chunkX == 0 && $chunkZ == 0) {
      $chunk->setBlock(1, 62, 2, Block::DIRT); // This generator only places one block of dirt
      $this->level->setChunk($chunkX, $chunkZ, $chunk);
   }
}

Importing the generator to SkyBlock

You have to use the generator manager for this.

// $skyblock must be an instance of SkyBlock
// $name must be the name of the generator
// TheGeneratorClass must be the class of your generator
$skyblock->getGeneratorManager()->registerGenerator($name, TheGeneratorClass::class);

Full example

MyCustomGenerator extends IslandGenerator {

    public function getName(): string {
        return "Custom";
    }

    public function generateChunk(int $chunkX, int $chunkZ): void {
        $chunk = $this->level->getChunk($chunkX, $chunkZ);
        $chunk->setGenerated();
        if($chunkX == 0 && $chunkZ == 0) {
            $chunk->setBlock(11, 34, 9, Block::GRASS);
        }
    }

    public static function getWorldSpawn(): Vector3 {
        return new Vector3(8, 35, 10);
    }

    public static function getChestPosition(): Vector3 {
        return new Vector3(6, 35, 8);
    }

}

Generators available

Right now, the island generators available are: basic, op, shelly, palm, lost