mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 14:05:35 +00:00
Level Generation API updated
This commit is contained in:
parent
c408ee07b1
commit
7297f8d2c0
@ -27,12 +27,14 @@ the Free Software Foundation, either version 3 of the License, or
|
|||||||
|
|
||||||
interface LevelGenerator{
|
interface LevelGenerator{
|
||||||
public function __construct(array $options = array());
|
public function __construct(array $options = array());
|
||||||
|
|
||||||
|
public function init(Level $level, Random $random);
|
||||||
|
|
||||||
public function generateChunk(Level $level, $chunkX, $chunkY, $chunkZ, Random $random);
|
public function generateChunk($chunkX, $chunkY, $chunkZ);
|
||||||
|
|
||||||
public function populateChunk(Level $level, $chunkX, $chunkY, $chunkZ, Random $random);
|
public function populateChunk($chunkX, $chunkY, $chunkZ);
|
||||||
|
|
||||||
public function populateLevel(Level $level, Random $random);
|
public function populateLevel();
|
||||||
|
|
||||||
public function getSpawn(Random $random);
|
public function getSpawn();
|
||||||
}
|
}
|
@ -30,7 +30,7 @@ require_once("LevelGenerator.php");
|
|||||||
/***REM_END***/
|
/***REM_END***/
|
||||||
|
|
||||||
class SuperflatGenerator implements LevelGenerator{
|
class SuperflatGenerator implements LevelGenerator{
|
||||||
private $config, $structure, $chunks, $options, $floorLevel;
|
private $level, $random, $structure, $chunks, $options, $floorLevel;
|
||||||
|
|
||||||
public function __construct(array $options = array()){
|
public function __construct(array $options = array()){
|
||||||
$this->preset = "2;7,2x3,2;1;spawn(radius=10 block=24)";
|
$this->preset = "2;7,2x3,2;1;spawn(radius=10 block=24)";
|
||||||
@ -101,16 +101,21 @@ class SuperflatGenerator implements LevelGenerator{
|
|||||||
$this->options[$option] = $params;
|
$this->options[$option] = $params;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function init(Level $level, Random $random){
|
||||||
|
$this->level = $level;
|
||||||
|
$this->random = $random;
|
||||||
|
}
|
||||||
|
|
||||||
public function generateChunk(Level $level, $chunkX, $chunkY, $chunkZ, Random $random){
|
public function generateChunk($chunkX, $chunkY, $chunkZ){
|
||||||
$level->setMiniChunk($chunkX, $chunkZ, $chunkY, $this->chunks[$chunkY]);
|
$this->level->setMiniChunk($chunkX, $chunkZ, $chunkY, $this->chunks[$chunkY]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function populateChunk(Level $level, $chunkX, $chunkY, $chunkZ, Random $random){
|
public function populateChunk($chunkX, $chunkY, $chunkZ){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function populateLevel(Level $level, Random $random){
|
public function populateLevel(){
|
||||||
if(isset($this->options["spawn"])){
|
if(isset($this->options["spawn"])){
|
||||||
$spawn = array(10, new SandstoneBlock());
|
$spawn = array(10, new SandstoneBlock());
|
||||||
if(isset($this->options["spawn"]["radius"])){
|
if(isset($this->options["spawn"]["radius"])){
|
||||||
@ -128,7 +133,7 @@ class SuperflatGenerator implements LevelGenerator{
|
|||||||
for($x = $start; $x <= $end; ++$x){
|
for($x = $start; $x <= $end; ++$x){
|
||||||
for($z = $start; $z <= $end; ++$z){
|
for($z = $start; $z <= $end; ++$z){
|
||||||
if(floor(sqrt(pow($x - 128, 2) + pow($z - 128, 2))) <= $spawn[0]){
|
if(floor(sqrt(pow($x - 128, 2) + pow($z - 128, 2))) <= $spawn[0]){
|
||||||
$level->setBlockRaw(new Vector3($x, $this->floorLevel - 1, $z), $spawn[1]);
|
$this->level->setBlockRaw(new Vector3($x, $this->floorLevel - 1, $z), $spawn[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,14 +145,14 @@ class SuperflatGenerator implements LevelGenerator{
|
|||||||
$treecount = intval($this->options["spawn"]["treecount"]);
|
$treecount = intval($this->options["spawn"]["treecount"]);
|
||||||
}
|
}
|
||||||
for($t = 0; $t < $treecount; ++$t){
|
for($t = 0; $t < $treecount; ++$t){
|
||||||
$centerX = $random->nextRange(0, 256);
|
$centerX = $this->random->nextRange(0, 256);
|
||||||
$centerZ = $random->nextRange(0, 256);
|
$centerZ = $this->random->nextRange(0, 256);
|
||||||
TreeObject::growTree($level, new Vector3($centerX, $this->floorLevel, $centerZ), $random->nextRange(0,3));
|
TreeObject::growTree($this->level, new Vector3($centerX, $this->floorLevel, $centerZ), $this->random->nextRange(0,3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSpawn(Random $random){
|
public function getSpawn(){
|
||||||
return new Vector3(128, $this->floorLevel, 128);
|
return new Vector3(128, $this->floorLevel, 128);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -51,17 +51,18 @@ class WorldGenerator{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function generate(){
|
public function generate(){
|
||||||
|
$this->generator->init($this->level, $this->random);
|
||||||
for($Z = 0; $Z < $this->width; ++$Z){
|
for($Z = 0; $Z < $this->width; ++$Z){
|
||||||
for($X = 0; $X < $this->width; ++$X){
|
for($X = 0; $X < $this->width; ++$X){
|
||||||
for($Y = 0; $Y < $this->height; ++$Y){
|
for($Y = 0; $Y < $this->height; ++$Y){
|
||||||
$this->generator->generateChunk($this->level, $X, $Y, $Z, $this->random);
|
$this->generator->generateChunk($X, $Y, $Z);
|
||||||
$this->generator->populateChunk($this->level, $X, $Y, $Z, $this->random);
|
$this->generator->populateChunk($X, $Y, $Z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console("[NOTICE] Generating level ".ceil((($Z + 1)/$this->width) * 100)."%");
|
console("[NOTICE] Generating level ".ceil((($Z + 1)/$this->width) * 100)."%");
|
||||||
}
|
}
|
||||||
$this->generator->populateLevel($this->level, $this->random);
|
$this->generator->populateLevel();
|
||||||
$this->level->setSpawn($this->generator->getSpawn($this->random));
|
$this->level->setSpawn($this->generator->getSpawn());
|
||||||
$this->level->save(true);
|
$this->level->save(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user