fixed trees on chunk borders, bumped pmf ver to 2

This commit is contained in:
GameHerobrine 2023-11-21 17:31:45 +03:00
parent d70d207317
commit e1368ce4a1
5 changed files with 49 additions and 14 deletions

View file

@ -1,10 +1,13 @@
<?php <?php
define("PMF_CURRENT_LEVEL_VERSION", 0x01); define("PMF_CURRENT_LEVEL_VERSION", 0x02);
class PMFLevel extends PMF{ class PMFLevel extends PMF{
public $isLoaded = true; public $isLoaded = true;
/**
* @var $level Level
*/
public $level; public $level;
public $levelData = []; public $levelData = [];
private $locationTable = []; private $locationTable = [];
@ -13,8 +16,8 @@ class PMFLevel extends PMF{
private $chunks = []; private $chunks = [];
private $chunkChange = []; private $chunkChange = [];
public $chunkInfo = []; public $chunkInfo = [];
public $placeBlocksOnNextGen = []; public $populated = [];
public $fakeLoaded = [];
public function __construct($file, $blank = false){ public function __construct($file, $blank = false){
if(is_array($blank)){ if(is_array($blank)){
$this->create($file, 0); $this->create($file, 0);
@ -37,6 +40,10 @@ class PMFLevel extends PMF{
} }
} }
public function setPopulated($X, $Z, $bool = true){
$this->populated[self::getIndex($X, $Z)] = $bool;
}
private function createBlank(){ private function createBlank(){
$this->saveData(false); $this->saveData(false);
$this->locationTable = []; $this->locationTable = [];
@ -119,7 +126,9 @@ class PMFLevel extends PMF{
} }
$this->seek(5); $this->seek(5);
$this->levelData["version"] = ord($this->read(1)); $this->levelData["version"] = ord($this->read(1));
if($this->levelData["version"] > PMF_CURRENT_LEVEL_VERSION){ //TODO old worlds support if($this->levelData["version"] != PMF_CURRENT_LEVEL_VERSION){ //TODO old worlds support
$cv = PMF_CURRENT_LEVEL_VERSION;
ConsoleAPI::warn("The level version does not match current. ({$this->levelData["version"]} != {$cv})");
return false; return false;
} }
$this->levelData["name"] = $this->read(Utils::readShort($this->read(2), false)); $this->levelData["name"] = $this->read(Utils::readShort($this->read(2), false));
@ -275,7 +284,8 @@ class PMFLevel extends PMF{
for($Y = 0; $Y < 8; ++$Y){ for($Y = 0; $Y < 8; ++$Y){
$bitmap |= ($this->chunks[$index][$Y] !== false and ((isset($this->chunkChange[$index][$Y]) and $this->chunkChange[$index][$Y] === 0) or !$this->isMiniChunkEmpty($X, $Z, $Y))) << $Y; $bitmap |= ($this->chunks[$index][$Y] !== false and ((isset($this->chunkChange[$index][$Y]) and $this->chunkChange[$index][$Y] === 0) or !$this->isMiniChunkEmpty($X, $Z, $Y))) << $Y;
} }
gzwrite($chunk, Utils::writeShort($bitmap), 2); //2 bytes locmap gzwrite($chunk, Utils::writeShort($bitmap), 2); //2 bytes locmap(actually it should be only 1)
gzwrite($chunk, chr($this->populated[$index]), 1); //isPopulated
$biomedata = $this->chunkInfo[$index][0]; $biomedata = $this->chunkInfo[$index][0];
if(strlen($biomedata) < 256){ if(strlen($biomedata) < 256){
$biomedata = str_repeat("\x01", 256); $biomedata = str_repeat("\x01", 256);
@ -335,7 +345,7 @@ class PMFLevel extends PMF{
} }
} }
public function loadChunk($X, $Z){ public function loadChunk($X, $Z, $populate = false){
$index = $this->getIndex($X, $Z); $index = $this->getIndex($X, $Z);
@ -359,6 +369,8 @@ class PMFLevel extends PMF{
if(strlen($chunk) === 0) return false; if(strlen($chunk) === 0) return false;
$info = [0 => Utils::readShort(substr($chunk, $offset, 2))]; $info = [0 => Utils::readShort(substr($chunk, $offset, 2))];
$offset+=2; $offset+=2;
$populated = ord($chunk[$offset]) > 0;
++$offset;
$this->chunks[$index] = []; $this->chunks[$index] = [];
$this->chunkChange[$index] = [-1 => false]; $this->chunkChange[$index] = [-1 => false];
$this->chunkInfo[$index][0] = substr($chunk, $offset, 256); //Biome data $this->chunkInfo[$index][0] = substr($chunk, $offset, 256); //Biome data
@ -376,6 +388,10 @@ class PMFLevel extends PMF{
$this->chunks[$index][$Y] = false; $this->chunks[$index][$Y] = false;
} }
} }
$this->setPopulated($X, $Z, $populated);
if($populate && !$populated){
$this->level->generator->populateChunk($X, $Z);
}
return true; return true;
} }
@ -420,6 +436,7 @@ class PMFLevel extends PMF{
0 => str_repeat("\x00", 256) 0 => str_repeat("\x00", 256)
); );
$this->locationTable[$index] = array(0); $this->locationTable[$index] = array(0);
$this->setPopulated($X, $Z, false);
} }
} }
public function setMiniChunk($X, $Z, $Y, $data){ public function setMiniChunk($X, $Z, $Y, $data){
@ -589,6 +606,12 @@ class PMFLevel extends PMF{
return [$b, $m]; return [$b, $m];
} }
public function createUnpopulatedChunk($X, $Z){
$this->initCleanChunk($X, $Z);
$this->level->generator->generateChunk($X, $Z);
$this->fakeLoaded[self::getIndex($X, $Z)] = "$X.$Z"; //TODO do not use string
}
public function setBlock($x, $y, $z, $block, $meta = 0){ public function setBlock($x, $y, $z, $block, $meta = 0){
$X = $x >> 4; $X = $x >> 4;
$Z = $z >> 4; $Z = $z >> 4;
@ -598,12 +621,14 @@ class PMFLevel extends PMF{
if($Y >= 128 or $y < 0){ if($Y >= 128 or $y < 0){
return false; return false;
} }
$loaded = false;
$index = $this->getIndex($X, $Z); $index = $this->getIndex($X, $Z);
if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){ if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){
if($this->loadChunk($X, $Z) === false){ if($this->loadChunk($X, $Z, false) === false){
return false; $this->createUnpopulatedChunk($X, $Z);
} }
}else $loaded = true;
}
if($this->chunks[$index][$Y] === false){ if($this->chunks[$index][$Y] === false){
$this->fillMiniChunk($X, $Z, $Y); $this->fillMiniChunk($X, $Z, $Y);
} }

View file

@ -21,7 +21,7 @@ class Level{
public $tiles, $blockUpdates, $nextSave, $players = [], $level, $mobSpawner; public $tiles, $blockUpdates, $nextSave, $players = [], $level, $mobSpawner;
public $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $stopTime; public $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $stopTime;
private $generator; public $generator;
public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){ public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
$this->level = $level; $this->level = $level;
@ -140,7 +140,7 @@ class Level{
$tileEntities = ""; $tileEntities = "";
if($gen) $this->level->generateChunk($X, $Z, $this->generator); if($gen) $this->level->generateChunk($X, $Z, $this->generator);
if(!$this->level->isChunkLoaded($X, $Z)){ if(!$this->level->isChunkLoaded($X, $Z)){
$this->level->loadChunk($X, $Z); $this->level->loadChunk($X, $Z, true);
} }
$miniChunks = []; $miniChunks = [];
@ -433,6 +433,13 @@ class Level{
} }
} }
foreach($this->level->fakeLoaded as $ind => $val){
$xz = explode(".", $val);
$this->level->unloadChunk($xz[0], $xz[1]);
ConsoleAPI::info("unloading feke chunk: {$xz[0]} {$xz[1]}");
unset($this->level->fakeLoaded[$ind]);
}
} }
public function setBlock(Vector3 $pos, Block $block, $update = true, $tiles = false, $direct = false){ public function setBlock(Vector3 $pos, Block $block, $update = true, $tiles = false, $direct = false){

View file

@ -172,6 +172,7 @@ class ExperimentalGenerator implements NewLevelGenerator{
} }
public function populateChunk($chunkX, $chunkZ){ public function populateChunk($chunkX, $chunkZ){
$this->level->level->setPopulated($chunkX, $chunkZ, true);
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->level->getSeed()); $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->level->getSeed());
foreach($this->populators as $populator){ foreach($this->populators as $populator){
$populator->populate($this->level, $chunkX, $chunkZ, $this->random); $populator->populate($this->level, $chunkX, $chunkZ, $this->random);

View file

@ -1,6 +1,6 @@
<?php <?php
//from HellGenerator for PocketMine mcpe 0.11 by ж<EFBFBD>џдє‘ //from HellGenerator for PocketMine mcpe 0.11 by Р¶пїЅСџРґС”вЂ<EFBFBD>
class HellGenerator implements NewLevelGenerator{ class HellGenerator implements NewLevelGenerator{
@ -121,6 +121,7 @@ class HellGenerator implements NewLevelGenerator{
} }
public function populateChunk($chunkX, $chunkZ){ public function populateChunk($chunkX, $chunkZ){
$this->level->level->setPopulated($chunkX, $chunkZ, true);
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
foreach($this->populators as $populator){ foreach($this->populators as $populator){
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());

View file

@ -138,6 +138,7 @@ class NormalGenerator implements NewLevelGenerator{
} }
public function populateChunk($chunkX, $chunkZ){ public function populateChunk($chunkX, $chunkZ){
$this->level->level->setPopulated($chunkX, $chunkZ, true);
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
foreach($this->populators as $populator){ foreach($this->populators as $populator){
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());