mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
Automatic population on side loading
This commit is contained in:
@ -65,10 +65,16 @@ class NormalGenerator implements LevelGenerator{
|
||||
new OreType(new GravelBlock(), 10, 16, 0, 128),
|
||||
));
|
||||
$this->populators[] = $ores;
|
||||
|
||||
$trees = new TreePopulator();
|
||||
$trees->setBaseAmount(3);
|
||||
$trees->setRandomAmount(0);
|
||||
$this->populators[] = $trees;
|
||||
|
||||
$tallGrass = new TallGrassPopulator();
|
||||
$tallGrass->setBaseAmount(5);
|
||||
$tallGrass->setRandomAmount(1);
|
||||
$this->populators[] = $tallGrass;
|
||||
$tallGrass->setRandomAmount(0);
|
||||
$this->populators[] = $tallGrass;
|
||||
}
|
||||
|
||||
public function generateChunk($chunkX, $chunkZ){
|
||||
@ -89,11 +95,11 @@ class NormalGenerator implements LevelGenerator{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for($chunkY = 0; $chunkY < 8; ++$chunkY){
|
||||
$chunk = "";
|
||||
$startY = $chunkY << 4;
|
||||
$endY = $startY + 16;
|
||||
$endY = $startY + 16;
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$i = ($z << 4) + $x;
|
||||
@ -120,7 +126,7 @@ class NormalGenerator implements LevelGenerator{
|
||||
}elseif($diff === 0){
|
||||
if($patchesSmall[$i] > 0.3){
|
||||
$chunk .= "\x0d"; //gravel
|
||||
}elseif($patches[$i] < -0.45){
|
||||
}elseif($patchesSmall[$i] < -0.45){
|
||||
$chunk .= "\x0c"; //sand
|
||||
}else{
|
||||
$chunk .= "\x03"; //dirt
|
||||
@ -148,17 +154,12 @@ class NormalGenerator implements LevelGenerator{
|
||||
|
||||
}
|
||||
|
||||
public function populateChunk($chunkX, $chunkZ){
|
||||
public function populateChunk($chunkX, $chunkZ){
|
||||
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
|
||||
foreach($this->populators as $populator){
|
||||
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
|
||||
$populator->populate($this->level, $chunkX, $chunkZ, $this->random);
|
||||
}
|
||||
|
||||
$this->level->level->setPopulated($chunkX, $chunkZ);
|
||||
}
|
||||
|
||||
public function populateLevel(){
|
||||
|
||||
}
|
||||
|
||||
public function getSpawn(){
|
||||
|
@ -129,12 +129,11 @@ class SuperflatGenerator implements LevelGenerator{
|
||||
}
|
||||
}
|
||||
|
||||
public function populateChunk($chunkX, $chunkZ){
|
||||
public function populateChunk($chunkX, $chunkZ){
|
||||
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
|
||||
foreach($this->populators as $populator){
|
||||
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
|
||||
$populator->populate($this->level, $chunkX, $chunkZ, $this->random);
|
||||
}
|
||||
$this->level->level->setPopulated($chunkX, $chunkZ);
|
||||
}
|
||||
|
||||
public function populateLevel(){
|
||||
|
@ -46,25 +46,17 @@ class WorldGenerator{
|
||||
}
|
||||
|
||||
public function generate(){
|
||||
++$this->level->level->isGenerating;
|
||||
$this->generator->init($this->level, $this->random);
|
||||
|
||||
//Generate 4 chunks for spawning players
|
||||
for($Z = 7; $Z <= 8; ++$Z){
|
||||
for($X = 7; $X <= 8; ++$X){
|
||||
$this->generator->generateChunk($X, $Z);
|
||||
}
|
||||
}
|
||||
|
||||
for($Z = 7; $Z <= 8; ++$Z){
|
||||
for($X = 7; $X <= 8; ++$X){
|
||||
$this->generator->populateChunk($X, $Z);
|
||||
$this->level->level->generateChunk($X, $Z);
|
||||
}
|
||||
}
|
||||
|
||||
$this->level->setSpawn($this->generator->getSpawn());
|
||||
$this->level->save(true, true);
|
||||
--$this->level->level->isGenerating;
|
||||
}
|
||||
|
||||
public function close(){
|
||||
|
67
src/world/generator/populator/TreePopulator.php
Normal file
67
src/world/generator/populator/TreePopulator.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class TreePopulator extends Populator{
|
||||
private $level;
|
||||
private $randomAmount;
|
||||
private $baseAmount;
|
||||
|
||||
public function setRandomAmount($amount){
|
||||
$this->randomAmount = $amount;
|
||||
}
|
||||
|
||||
public function setBaseAmount($amount){
|
||||
$this->baseAmount = $amount;
|
||||
}
|
||||
|
||||
public function populate(Level $level, $chunkX, $chunkZ, Random $random){
|
||||
$this->level = $level;
|
||||
$amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount;
|
||||
for($i = 0; $i < $amount; ++$i){
|
||||
$x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15);
|
||||
$z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15);
|
||||
$y = $this->getHighestWorkableBlock($x, $z);
|
||||
if($y === -1){
|
||||
continue;
|
||||
}
|
||||
if($random->nextFloat() > 0.75){
|
||||
$meta = 1;
|
||||
}else{
|
||||
$meta = 0;
|
||||
}
|
||||
TreeObject::growTree($this->level, new Vector3($x, $y, $z), $random, $meta);
|
||||
}
|
||||
}
|
||||
|
||||
private function getHighestWorkableBlock($x, $z){
|
||||
for($y = 128; $y > 0; --$y){
|
||||
$b = $this->level->getBlockRaw(new Vector3($x, $y, $z));
|
||||
if($b->getID() !== DIRT and $b->getID() !== GRASS){
|
||||
if(--$y <= 0){
|
||||
return -1;
|
||||
}
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ++$y;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user