mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-17 11:18:52 +00:00
Merge remote-tracking branch 'origin/master' into Entities
This commit is contained in:
commit
7ea0bf5067
@ -1,7 +1,9 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
|
||||
before_script:
|
||||
- pecl install channel://pecl.php.net/pthreads-0.1.0
|
||||
|
@ -151,6 +151,10 @@ class LevelAPI{
|
||||
$path = DATA_PATH."worlds/".$name."/";
|
||||
console("[INFO] Preparing level \"".$name."\"");
|
||||
$level = new PMFLevel($path."level.pmf");
|
||||
if(!$level->isLoaded){
|
||||
console("[ERROR] Could not load level \"".$name."\"");
|
||||
return false;
|
||||
}
|
||||
$entities = new Config($path."entities.yml", CONFIG_YAML);
|
||||
if(file_exists($path."tileEntities.yml")){
|
||||
@rename($path."tileEntities.yml", $path."tiles.yml");
|
||||
@ -223,20 +227,6 @@ class LevelAPI{
|
||||
return $this->server->spawn;
|
||||
}
|
||||
|
||||
public function loadMap(){
|
||||
if($this->mapName !== false and trim($this->mapName) !== ""){
|
||||
if(!file_exists($this->mapDir."level.pmf")){
|
||||
$level = new LevelImport($this->mapDir);
|
||||
$level->import();
|
||||
}
|
||||
$this->level = new PMFLevel($this->mapDir."level.pmf");
|
||||
console("[INFO] Preparing level \"".$this->level->getData("name")."\"");
|
||||
$this->time = (int) $this->level->getData("time");
|
||||
$this->seed = (int) $this->level->getData("seed");
|
||||
$this->spawn = $this->level->getSpawn();
|
||||
}
|
||||
}
|
||||
|
||||
public function getAll(){
|
||||
return $this->levels;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ class PlayerAPI{
|
||||
$this->server->api->console->register("kill", "<player>", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("gamemode", "<mode> [player]", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("tp", "[target player] <destination player | w:world> OR /tp [target player] <x> <y> <z>", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("spawnpoint", "[player] [x] [y] [z]", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("spawnpoint", "[player | w:world] [x] [y] [z]", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("spawn", "", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("ping", "", array($this, "commandHandler"));
|
||||
$this->server->api->console->alias("lag", "ping");
|
||||
@ -119,31 +119,49 @@ class PlayerAPI{
|
||||
$output = "";
|
||||
switch($cmd){
|
||||
case "spawnpoint":
|
||||
if(!($issuer instanceof Player)){
|
||||
if(count($params) === 0){
|
||||
$output .= "Usage: /$cmd [player | w:world] [x] [y] [z]\n";
|
||||
break;
|
||||
}
|
||||
if(!($issuer instanceof Player) and count($params) < 4){
|
||||
$output .= "Please run this command in-game.\n";
|
||||
break;
|
||||
}
|
||||
|
||||
if(count($params) === 1 or count($params) === 4){
|
||||
$target = $this->server->api->player->get(array_shift($params));
|
||||
$tg = array_shift($params);
|
||||
if(count($params) === 3 and substr($tg, 0, 2) === "w:"){
|
||||
$target = $this->server->api->level->get(substr($tg, 2));
|
||||
}else{
|
||||
$target = $this->server->api->player->get($tg);
|
||||
}
|
||||
}else{
|
||||
$target = $issuer;
|
||||
}
|
||||
|
||||
if(!($target instanceof Player)){
|
||||
if(!($target instanceof Player) and !($target instanceof Level)){
|
||||
$output .= "That player cannot be found.\n";
|
||||
break;
|
||||
}
|
||||
|
||||
if(count($params) === 3){
|
||||
if($target instanceof Level){
|
||||
$spawn = new Vector3(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params)));
|
||||
}else{
|
||||
$spawn = new Position(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params)), $issuer->level);
|
||||
}
|
||||
}else{
|
||||
$spawn = new Position($issuer->entity->x, $issuer->entity->y, $issuer->entity->z, $issuer->entity->level);
|
||||
}
|
||||
|
||||
$target->setSpawn($spawn);
|
||||
|
||||
if($target instanceof Level){
|
||||
$output .= "Spawnpoint of world ".$target->getName()." set correctly!\n";
|
||||
}elseif($target !== $issuer){
|
||||
$output .= "Spawnpoint of ".$target->username." set correctly!\n";
|
||||
}else{
|
||||
$output .= "Spawnpoint set correctly!\n";
|
||||
}
|
||||
break;
|
||||
case "spawn":
|
||||
if(!($issuer instanceof Player)){
|
||||
@ -210,7 +228,7 @@ class PlayerAPI{
|
||||
$name = array_shift($params);
|
||||
$target = implode(" ", $params);
|
||||
}else{
|
||||
$output .= "Usage: /$cmd [target player] <destination player>\n";
|
||||
$output .= "Usage: /$cmd [target player] <destination player | w:world>\n";
|
||||
break;
|
||||
}
|
||||
if($this->teleport($name, $target) !== false){
|
||||
|
@ -147,7 +147,7 @@ class ServerAPI{
|
||||
//Load advanced properties
|
||||
define("DEBUG", $this->getProperty("debug", 1));
|
||||
define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false));
|
||||
define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 8)); //Default rate ~512 kB/s
|
||||
define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 7)); //Default rate ~448 kB/s
|
||||
if(ADVANCED_CACHE == true){
|
||||
console("[INFO] Advanced cache enabled");
|
||||
}
|
||||
|
@ -420,6 +420,11 @@ class PocketMinecraftServer{
|
||||
$dump .= "[".($l + 1)."] ".@$file[$l]."\r\n";
|
||||
}
|
||||
$dump .= "\r\n\r\n";
|
||||
$dump .= "Backtrace: \r\n";
|
||||
foreach(getTrace() as $line){
|
||||
$dump .= "$line\r\n";
|
||||
}
|
||||
$dump .= "\r\n\r\n";
|
||||
$version = new VersionString();
|
||||
$dump .= "PocketMine-MP version: ".$version." #".$version->getNumber()." [Protocol ".ProtocolInfo::CURRENT_PROTOCOL."; API ".CURRENT_API_VERSION."]\r\n";
|
||||
$dump .= "Git commit: ".GIT_COMMIT."\r\n";
|
||||
|
@ -217,6 +217,21 @@ function console($message, $EOL = true, $log = true, $level = 1){
|
||||
}
|
||||
}
|
||||
|
||||
function getTrace($start = 1){
|
||||
$e = new Exception();
|
||||
$trace = $e->getTrace();
|
||||
$messages = array();
|
||||
$j = 0;
|
||||
for($i = (int) $start; isset($trace[$i]); ++$i, ++$j){
|
||||
$params = "";
|
||||
foreach($trace[$i]["args"] as $name => $value){
|
||||
$params .= (is_object($value) ? get_class($value)." ".(method_exists($value, "__toString") ? $value->__toString() : "object"):gettype($value)." ".@strval($value)).", ";
|
||||
}
|
||||
$messages[] = "#$j ".(isset($trace[$i]["file"]) ? $trace[$i]["file"]:"")."(".(isset($trace[$i]["line"]) ? $trace[$i]["line"]:"")."): ".(isset($trace[$i]["class"]) ? $trace[$i]["class"].$trace[$i]["type"]:"").$trace[$i]["function"]."(".substr($params, 0, -2).")";
|
||||
}
|
||||
return $messages;
|
||||
}
|
||||
|
||||
function error_handler($errno, $errstr, $errfile, $errline){
|
||||
if(error_reporting() === 0){ //@ error-control
|
||||
return false;
|
||||
@ -240,6 +255,9 @@ function error_handler($errno, $errstr, $errfile, $errline){
|
||||
);
|
||||
$errno = isset($errorConversion[$errno]) ? $errorConversion[$errno]:$errno;
|
||||
console("[ERROR] A ".$errno." error happened: \"$errstr\" in \"$errfile\" at line $errline", true, true, 0);
|
||||
foreach(getTrace() as $i => $line){
|
||||
console("[TRACE] $line");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -46,13 +46,16 @@ class PMFLevel extends PMF{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function close(){
|
||||
public function closeLevel(){
|
||||
$this->chunks = null;
|
||||
unset($this->chunks, $this->chunkChange, $this->chunkInfo, $this->level);
|
||||
parent::close();
|
||||
$this->close();
|
||||
}
|
||||
|
||||
public function __construct($file, $blank = false){
|
||||
$this->chunks = array();
|
||||
$this->chunkChange = array();
|
||||
$this->chunkInfo = array();
|
||||
if(is_array($blank)){
|
||||
$this->create($file, 0);
|
||||
$this->levelData = $blank;
|
||||
@ -145,8 +148,6 @@ class PMFLevel extends PMF{
|
||||
$X = $index & 0x0F;
|
||||
$Z = $index >> 4;
|
||||
|
||||
$this->chunks[$index] = false;
|
||||
$this->chunkChange[$index] = false;
|
||||
$bitflags = Utils::readShort($this->read(2));
|
||||
$oldPath = dirname($this->file)."/chunks/".$Z.".".$X.".pmc";
|
||||
$chunkOld = gzopen($oldPath, "rb");
|
||||
@ -168,7 +169,7 @@ class PMFLevel extends PMF{
|
||||
}
|
||||
|
||||
public static function getIndex($X, $Z){
|
||||
return ($Z << 16) + $X;
|
||||
return ($Z << 16) | ($X < 0 ? (~--$X & 0x7fff) | 0x1000 : $X & 0xFFFF);
|
||||
}
|
||||
|
||||
public static function getXZ($index, &$X = null, &$Z = null){
|
||||
@ -186,15 +187,36 @@ class PMFLevel extends PMF{
|
||||
if(!file_exists(dirname($path))){
|
||||
@mkdir(dirname($path), 0755);
|
||||
}
|
||||
++$this->isGenerating;
|
||||
$this->initCleanChunk($X, $Z);
|
||||
$ret = $this->level->generateChunk($X, $Z);
|
||||
$ret = $ret and $this->level->populateChunk($X, $Z);
|
||||
$this->saveChunk($X, $Z);
|
||||
--$this->isGenerating;
|
||||
$this->populateChunk($X - 1, $Z);
|
||||
$this->populateChunk($X + 1, $Z);
|
||||
$this->populateChunk($X, $Z - 1);
|
||||
$this->populateChunk($X, $Z + 1);
|
||||
$this->populateChunk($X + 1, $Z + 1);
|
||||
$this->populateChunk($X + 1, $Z - 1);
|
||||
$this->populateChunk($X - 1, $Z - 1);
|
||||
$this->populateChunk($X - 1, $Z + 1);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function populateChunk($X, $Z){
|
||||
if($this->isGenerating === 0 and
|
||||
!$this->isPopulated($X, $Z) and
|
||||
$this->isGenerated($X - 1, $Z) and
|
||||
$this->isGenerated($X, $Z - 1) and
|
||||
$this->isGenerated($X + 1, $Z) and
|
||||
$this->isGenerated($X, $Z + 1) and
|
||||
$this->isGenerated($X + 1, $Z + 1) and
|
||||
$this->isGenerated($X - 1, $Z - 1) and
|
||||
$this->isGenerated($X + 1, $Z - 1) and
|
||||
$this->isGenerated($X - 1, $Z + 1)){
|
||||
$this->level->populateChunk($X, $Z);
|
||||
$this->saveChunk($X, $Z);
|
||||
}
|
||||
}
|
||||
|
||||
public function loadChunk($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
@ -204,20 +226,14 @@ class PMFLevel extends PMF{
|
||||
}
|
||||
$path = $this->getChunkPath($X, $Z);
|
||||
if(!file_exists($path)){
|
||||
if($this->isGenerating > 0){
|
||||
$this->level->generateChunk($X, $Z);
|
||||
$this->saveChunk($X, $Z);
|
||||
}elseif($this->generateChunk($X, $Z) === false){
|
||||
if($this->generateChunk($X, $Z) === false){
|
||||
return false;
|
||||
}elseif($this->isGenerating === 0){
|
||||
$this->populateChunk($X, $Z);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if($this->isGenerating === 0 and !$this->isPopulated($X, $Z)){
|
||||
++$this->isGenerating;
|
||||
$this->level->populateChunk($X, $Z);
|
||||
--$this->isGenerating;
|
||||
}
|
||||
|
||||
$chunk = @gzopen($path, "rb");
|
||||
if($chunk === false){
|
||||
return false;
|
||||
@ -233,7 +249,7 @@ class PMFLevel extends PMF{
|
||||
if(($this->chunkInfo[$index][0] & $t) === $t){
|
||||
// 4096 + 2048 + 2048, Block Data, Meta, Light
|
||||
if(strlen($this->chunks[$index][$Y] = gzread($chunk, 8192)) < 8192){
|
||||
console("[NOTICE] Empty corrupt chunk detected [$X,$Z,:$Y], recovering contents");
|
||||
console("[NOTICE] Empty corrupt chunk detected [$X,$Z,:$Y], recovering contents", true, true, 2);
|
||||
$this->fillMiniChunk($X, $Z, $Y);
|
||||
}
|
||||
}else{
|
||||
@ -241,6 +257,9 @@ class PMFLevel extends PMF{
|
||||
}
|
||||
}
|
||||
@gzclose($chunk);
|
||||
if($this->isGenerating === 0 and !$this->isPopulated($X, $Z)){
|
||||
$this->populateChunk($X, $Z);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -262,15 +281,15 @@ class PMFLevel extends PMF{
|
||||
|
||||
public function isChunkLoaded($X, $Z){
|
||||
$index = self::getIndex($X, $Z);
|
||||
if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){
|
||||
if(!isset($this->chunks[$index])){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function isMiniChunkEmpty($X, $Z, $Y){
|
||||
public function isMiniChunkEmpty($X, $Z, $Y){
|
||||
$index = self::getIndex($X, $Z);
|
||||
if($this->chunks[$index][$Y] !== false){
|
||||
if(isset($this->chunks[$index]) and $this->chunks[$index][$Y] !== false){
|
||||
if(substr_count($this->chunks[$index][$Y], "\x00") < 8192){
|
||||
return false;
|
||||
}
|
||||
@ -291,7 +310,7 @@ class PMFLevel extends PMF{
|
||||
}
|
||||
|
||||
public function getMiniChunk($X, $Z, $Y){
|
||||
if($this->loadChunk($X, $Z) === false){
|
||||
if($this->isChunkLoaded($X, $Z) === false and $this->loadChunk($X, $Z) === false){
|
||||
return str_repeat("\x00", 8192);
|
||||
}
|
||||
$index = self::getIndex($X, $Z);
|
||||
@ -314,7 +333,17 @@ class PMFLevel extends PMF{
|
||||
6 => false,
|
||||
7 => false,
|
||||
);
|
||||
$this->chunkChange[$index] = array(-1 => false);
|
||||
$this->chunkChange[$index] = array(
|
||||
-1 => true,
|
||||
0 => 8192,
|
||||
1 => 8192,
|
||||
2 => 8192,
|
||||
3 => 8192,
|
||||
4 => 8192,
|
||||
5 => 8192,
|
||||
6 => 8192,
|
||||
7 => 8192,
|
||||
);
|
||||
$this->chunkInfo[$index] = array(
|
||||
0 => 0,
|
||||
1 => 0,
|
||||
@ -347,7 +376,7 @@ class PMFLevel extends PMF{
|
||||
$Z = $z >> 4;
|
||||
$Y = $y >> 4;
|
||||
$index = self::getIndex($X, $Z);
|
||||
if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){
|
||||
if(!isset($this->chunks[$index])){
|
||||
return 0;
|
||||
}
|
||||
$aX = $x - ($X << 4);
|
||||
@ -366,7 +395,7 @@ class PMFLevel extends PMF{
|
||||
$Y = $y >> 4;
|
||||
$block &= 0xFF;
|
||||
$index = self::getIndex($X, $Z);
|
||||
if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){
|
||||
if(!isset($this->chunks[$index])){
|
||||
return false;
|
||||
}
|
||||
$aX = $x - ($X << 4);
|
||||
@ -390,7 +419,7 @@ class PMFLevel extends PMF{
|
||||
$Z = $z >> 4;
|
||||
$Y = $y >> 4;
|
||||
$index = self::getIndex($X, $Z);
|
||||
if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){
|
||||
if(!isset($this->chunks[$index])){
|
||||
return 0;
|
||||
}
|
||||
$aX = $x - ($X << 4);
|
||||
@ -414,7 +443,7 @@ class PMFLevel extends PMF{
|
||||
$Y = $y >> 4;
|
||||
$damage &= 0x0F;
|
||||
$index = self::getIndex($X, $Z);
|
||||
if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){
|
||||
if(!isset($this->chunks[$index])){
|
||||
return false;
|
||||
}
|
||||
$aX = $x - ($X << 4);
|
||||
@ -449,10 +478,8 @@ class PMFLevel extends PMF{
|
||||
return array(AIR, 0);
|
||||
}
|
||||
$index = self::getIndex($X, $Z);
|
||||
if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){
|
||||
if($this->loadChunk($X, $Z) === false){
|
||||
if(!isset($this->chunks[$index]) and $this->loadChunk($X, $Z) === false){
|
||||
return array(AIR, 0);
|
||||
}
|
||||
}elseif($this->chunks[$index][$Y] === false){
|
||||
return array(AIR, 0);
|
||||
}
|
||||
@ -479,10 +506,8 @@ class PMFLevel extends PMF{
|
||||
$block &= 0xFF;
|
||||
$meta &= 0x0F;
|
||||
$index = self::getIndex($X, $Z);
|
||||
if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){
|
||||
if($this->loadChunk($X, $Z) === false){
|
||||
if(!isset($this->chunks[$index]) and $this->loadChunk($X, $Z) === false){
|
||||
return false;
|
||||
}
|
||||
}elseif($this->chunks[$index][$Y] === false){
|
||||
$this->fillMiniChunk($X, $Z, $Y);
|
||||
}
|
||||
@ -508,17 +533,6 @@ class PMFLevel extends PMF{
|
||||
++$this->chunkChange[$index][$Y];
|
||||
}
|
||||
$this->chunkChange[$index][-1] = true;
|
||||
if($old_b instanceof LiquidBlock){
|
||||
$pos = new Position($x, $y, $z, $this->level);
|
||||
for($side = 0; $side <= 5; ++$side){
|
||||
$b = $pos->getSide($side);
|
||||
if($b instanceof LavaBlock){
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
|
||||
}else{
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -527,9 +541,7 @@ class PMFLevel extends PMF{
|
||||
public function saveChunk($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
if($this->isGenerating > 0){
|
||||
$this->initCleanChunk($X, $Z);
|
||||
}elseif(!$this->isChunkLoaded($X, $Z)){
|
||||
if(!$this->isChunkLoaded($X, $Z)){
|
||||
return false;
|
||||
}
|
||||
$index = self::getIndex($X, $Z);
|
||||
@ -552,7 +564,7 @@ class PMFLevel extends PMF{
|
||||
}
|
||||
$chunk = @gzopen($path, "wb".PMFLevel::DEFLATE_LEVEL);
|
||||
gzwrite($chunk, chr($bitmap));
|
||||
gzwrite($chunk, Utils::writeInt($this->chunkInfo[$index][0]));
|
||||
gzwrite($chunk, Utils::writeInt($this->chunkInfo[$index][1]));
|
||||
for($Y = 0; $Y < 8; ++$Y){
|
||||
$t = 1 << $Y;
|
||||
if(($bitmap & $t) === $t){
|
||||
@ -589,6 +601,10 @@ class PMFLevel extends PMF{
|
||||
return ($this->chunkInfo[$index][1] & 0b00000000000000000000000000000001) > 0;
|
||||
}
|
||||
|
||||
public function isGenerated($X, $Z){
|
||||
return file_exists($this->getChunkPath($X, $Z));
|
||||
}
|
||||
|
||||
public function doSaveRound(){
|
||||
foreach($this->chunks as $index => $chunk){
|
||||
self::getXZ($index, $X, $Z);
|
||||
|
@ -26,7 +26,6 @@ class Level{
|
||||
public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){
|
||||
$this->server = ServerAPI::request();
|
||||
$this->level = $level;
|
||||
$level->level = $this;
|
||||
$this->level->level = $this;
|
||||
$this->entities = $entities;
|
||||
$this->tiles = $tiles;
|
||||
@ -148,17 +147,22 @@ class Level{
|
||||
}
|
||||
|
||||
public function generateChunk($X, $Z){
|
||||
++$this->level->isGenerating;
|
||||
$this->generator->generateChunk($X, $Z);
|
||||
--$this->level->isGenerating;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function populateChunk($X, $Z){
|
||||
$this->level->setPopulated($X, $Z);
|
||||
$this->generator->populateChunk($X, $Z);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
if(isset($this->level)){
|
||||
$this->save(false, false);
|
||||
$this->level->close();
|
||||
$this->level->closeLevel();
|
||||
unset($this->level);
|
||||
}
|
||||
}
|
||||
|
@ -30,13 +30,10 @@ class NormalGenerator implements LevelGenerator{
|
||||
private $random;
|
||||
private $worldHeight = 65;
|
||||
private $waterHeight = 63;
|
||||
private $noiseHills;
|
||||
private $noisePatches;
|
||||
private $noisePatchesSmall;
|
||||
private $noiseBase;
|
||||
private $noiseGen1;
|
||||
private $noiseGen2;
|
||||
private $noiseGen3;
|
||||
private $noiseGen4;
|
||||
private $noiseGen5;
|
||||
private $noiseGen6;
|
||||
|
||||
public function __construct(array $options = array()){
|
||||
|
||||
@ -50,9 +47,10 @@ class NormalGenerator implements LevelGenerator{
|
||||
$this->level = $level;
|
||||
$this->random = $random;
|
||||
$this->random->setSeed($this->level->getSeed());
|
||||
$this->noiseBase = new NoiseGeneratorSimplex($this->random, 4);
|
||||
$this->noiseGen1 = new NoiseGeneratorPerlin($this->random, 4);
|
||||
$this->noiseGen2 = new NoiseGeneratorPerlin($this->random, 4);
|
||||
$this->noiseHills = new NoiseGeneratorSimplex($this->random, 3);
|
||||
$this->noisePatches = new NoiseGeneratorSimplex($this->random, 2);
|
||||
$this->noisePatchesSmall = new NoiseGeneratorSimplex($this->random, 2);
|
||||
$this->noiseBase = new NoiseGeneratorSimplex($this->random, 16);
|
||||
|
||||
|
||||
$ores = new OrePopulator();
|
||||
@ -67,10 +65,36 @@ 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(0);
|
||||
$this->populators[] = $tallGrass;
|
||||
}
|
||||
|
||||
public function generateChunk($chunkX, $chunkZ){
|
||||
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
|
||||
$hills = array();
|
||||
$patchesSmall = array();
|
||||
$base = array();
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$i = ($z << 4) + $x;
|
||||
$hills[$i] = $this->noiseHills->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.11, 12, true);
|
||||
$patches[$i] = $this->noisePatches->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.03, 16, true);
|
||||
$patchesSmall[$i] = $this->noisePatchesSmall->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.5, 4, true);
|
||||
$base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.7, 16, true);
|
||||
|
||||
if($base[$i] < 0){
|
||||
$base[$i] *= 0.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for($chunkY = 0; $chunkY < 8; ++$chunkY){
|
||||
$chunk = "";
|
||||
@ -78,27 +102,46 @@ class NormalGenerator implements LevelGenerator{
|
||||
$endY = $startY + 16;
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$noise1 = $this->noiseGen1->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.6, 32, true) * 2;
|
||||
$noise2 = $this->noiseGen2->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.35, 64, true) * 15;
|
||||
$noiseBase = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 1/5, 16, true) * 3;
|
||||
$height = (int) ($this->worldHeight + $noise1 + $noise2 + $noiseBase);
|
||||
$i = ($z << 4) + $x;
|
||||
$height = $this->worldHeight + $hills[$i] * 14 + $base[$i] * 7;
|
||||
$height = (int) $height;
|
||||
|
||||
for($y = $startY; $y < $endY; ++$y){
|
||||
$diff = $height - $y;
|
||||
if($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)){
|
||||
$chunk .= "\x07"; //bedrock
|
||||
}elseif($diff > 3){
|
||||
}elseif($diff > 2){
|
||||
$chunk .= "\x01"; //stone
|
||||
}elseif($diff > 0){
|
||||
if($patches[$i] > 0.7){
|
||||
$chunk .= "\x01"; //stone
|
||||
}elseif($patches[$i] < -0.8){
|
||||
$chunk .= "\x0d"; //gravel
|
||||
}else{
|
||||
$chunk .= "\x03"; //dirt
|
||||
}
|
||||
}elseif($y <= $this->waterHeight){
|
||||
if($y === $this->waterHeight and $diff === 0){
|
||||
if(($this->waterHeight - $y) <= 1 and $diff === 0){
|
||||
$chunk .= "\x0c"; //sand
|
||||
}elseif($diff === 0){
|
||||
if($patchesSmall[$i] > 0.3){
|
||||
$chunk .= "\x0d"; //gravel
|
||||
}elseif($patchesSmall[$i] < -0.45){
|
||||
$chunk .= "\x0c"; //sand
|
||||
}else{
|
||||
$chunk .= "\x03"; //dirt
|
||||
}
|
||||
}else{
|
||||
$chunk .= "\x09"; //still_water
|
||||
}
|
||||
}elseif($diff === 0){
|
||||
if($patches[$i] > 0.7){
|
||||
$chunk .= "\x01"; //stone
|
||||
}elseif($patches[$i] < -0.8){
|
||||
$chunk .= "\x0d"; //gravel
|
||||
}else{
|
||||
$chunk .= "\x02"; //grass
|
||||
}
|
||||
}else{
|
||||
$chunk .= "\x00";
|
||||
}
|
||||
@ -112,16 +155,11 @@ class NormalGenerator implements LevelGenerator{
|
||||
}
|
||||
|
||||
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(){
|
||||
|
@ -130,11 +130,10 @@ class SuperflatGenerator implements LevelGenerator{
|
||||
}
|
||||
|
||||
public function populateChunk($chunkX, $chunkZ){
|
||||
foreach($this->populators as $populator){
|
||||
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
|
||||
foreach($this->populators as $populator){
|
||||
$populator->populate($this->level, $chunkX, $chunkZ, $this->random);
|
||||
}
|
||||
$this->level->level->setPopulated($chunkX, $chunkZ);
|
||||
}
|
||||
|
||||
public function populateLevel(){
|
||||
|
@ -46,24 +46,16 @@ class WorldGenerator{
|
||||
}
|
||||
|
||||
public function generate(){
|
||||
++$this->level->level->isGenerating;
|
||||
$this->generator->init($this->level, $this->random);
|
||||
|
||||
for($Z = 7; $Z <= 9; ++$Z){
|
||||
for($X = 7; $X <= 9; ++$X){
|
||||
$this->generator->generateChunk($X, $Z);
|
||||
}
|
||||
}
|
||||
|
||||
for($Z = 7; $Z <= 9; ++$Z){
|
||||
for($X = 7; $X <= 9; ++$X){
|
||||
$this->generator->populateChunk($X, $Z);
|
||||
//Generate 4 chunks for spawning players
|
||||
for($Z = 7; $Z <= 8; ++$Z){
|
||||
for($X = 7; $X <= 8; ++$X){
|
||||
$this->level->level->loadChunk($X, $Z);
|
||||
}
|
||||
}
|
||||
|
||||
$this->level->setSpawn($this->generator->getSpawn());
|
||||
$this->level->save(true, true);
|
||||
--$this->level->level->isGenerating;
|
||||
}
|
||||
|
||||
public function close(){
|
||||
|
@ -23,6 +23,8 @@
|
||||
class TreeObject{
|
||||
public $overridable = array(
|
||||
0 => true,
|
||||
2 => true,
|
||||
3 => true,
|
||||
6 => true,
|
||||
17 => true,
|
||||
18 => true,
|
||||
|
@ -25,9 +25,9 @@ class OrePopulator extends Populator{
|
||||
foreach($this->oreTypes as $type){
|
||||
$ore = new OreObject($random, $type);
|
||||
for($i = 0; $i < $ore->type->clusterCount; ++$i){
|
||||
$x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 16);
|
||||
$x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15);
|
||||
$y = $random->nextRange($ore->type->minHeight, $ore->type->maxHeight);
|
||||
$z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16);
|
||||
$z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15);
|
||||
if($ore->canPlaceObject($level, $x, $y, $z)){
|
||||
$ore->placeObject($level, new Vector3($x, $y, $z));
|
||||
}
|
||||
|
70
src/world/generator/populator/TallGrassPopulator.php
Normal file
70
src/world/generator/populator/TallGrassPopulator.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?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 TallGrassPopulator 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);
|
||||
for($size = 30; $size > 0; --$size){
|
||||
$xx = $x - 7 + $random->nextRange(0, 15);
|
||||
$zz = $z - 7 + $random->nextRange(0, 15);
|
||||
$yy = $this->getHighestWorkableBlock($xx, $zz);
|
||||
$vector = new Vector3($xx, $yy, $zz);
|
||||
if($yy !== -1 and $this->canTallGrassStay($this->level->getBlockRaw($vector))){
|
||||
$this->level->setBlockRaw($vector, new TallGrassBlock(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function canTallGrassStay(Block $block){
|
||||
return $block->getID() === AIR and $block->getSide(0)->getID() === GRASS;
|
||||
}
|
||||
|
||||
private function getHighestWorkableBlock($x, $z){
|
||||
for($y = 128; $y > 0; --$y){
|
||||
$b = $this->level->getBlockRaw(new Vector3($x, $y, $z));
|
||||
if($b->getID() === AIR or $b->getID() === LEAVES){
|
||||
if(--$y <= 0){
|
||||
return -1;
|
||||
}
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ++$y;
|
||||
}
|
||||
}
|
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 = SaplingBlock::BIRCH;
|
||||
}else{
|
||||
$meta = SaplingBlock::OAK;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user