-
-
Notifications
You must be signed in to change notification settings - Fork 53
Generators
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.
This method should return the name of the generator.
public function getName(): string {
return "examplename";
}
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);
}
This method should return the coordinates where the initial chest will spawn.
public function getChestPosition(): Vector3 {
return new Vector3(123, 123, 123);
}
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);
}
}
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);
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);
}
}
Right now, the island generators available are: basic, op, shelly, palm, lost