mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 20:49:43 +00:00
inf world should generate, generated chunks are not currently saved anywhere
This commit is contained in:
parent
197e0c63bd
commit
63ef7c628c
2 changed files with 69 additions and 25 deletions
|
|
@ -97,9 +97,9 @@ class PMFLevel extends PMF{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getXZ($index, &$X = null, &$Z = null){
|
public function getXZ($index, &$X = null, &$Z = null){
|
||||||
$X = $index >> $this->log;
|
$Z = $index >> 16;
|
||||||
$Z = $index & (pow($this->log, 2) - 1);
|
$X = ($index & 0x8000) === 0x8000 ? -($index & 0x7fff) : $index & 0x7fff;
|
||||||
return [$X, $Z];
|
return array($X, $Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getChunkPath($X, $Z){
|
private function getChunkPath($X, $Z){
|
||||||
|
|
@ -205,9 +205,7 @@ class PMFLevel extends PMF{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIndex($X, $Z){
|
public function getIndex($X, $Z){
|
||||||
$X = (int) $X;
|
return ($Z << 16) | ($X < 0 ? (~--$X & 0x7fff) | 0x8000 : $X & 0x7fff);
|
||||||
$Z = (int) $Z;
|
|
||||||
return ($Z << $this->log) + $X;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveChunk($X, $Z){
|
public function saveChunk($X, $Z){
|
||||||
|
|
@ -259,7 +257,24 @@ class PMFLevel extends PMF{
|
||||||
}
|
}
|
||||||
return $this->chunks[$index][$Y];
|
return $this->chunks[$index][$Y];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function generateChunk($X, $Z, LevelGenerator $generator){
|
||||||
|
$index = $this->getIndex($X, $Z);
|
||||||
|
if(isset($this->locationTable[$index])){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->initCleanChunk($X, $Z);
|
||||||
|
$this->fillFullChunk($X, $Z);
|
||||||
|
$generator->generateChunk($X, $Z);
|
||||||
|
$generator->populateChunk($X, $Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fillFullChunk($X, $Z){
|
||||||
|
for($Y = 0; $Y < 16; ++$Y){
|
||||||
|
$this->fillMiniChunk($X, $Z, $Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function loadChunk($X, $Z){
|
public function loadChunk($X, $Z){
|
||||||
|
|
||||||
$index = self::getIndex($X, $Z);
|
$index = self::getIndex($X, $Z);
|
||||||
|
|
@ -301,13 +316,44 @@ class PMFLevel extends PMF{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$index = $this->getIndex($X, $Z);
|
$index = $this->getIndex($X, $Z);
|
||||||
|
|
||||||
$this->chunks[$index][$Y] = str_repeat("\x00", 8192);
|
$this->chunks[$index][$Y] = str_repeat("\x00", 8192);
|
||||||
$this->chunkChange[$index][-1] = true;
|
$this->chunkChange[$index][-1] = true;
|
||||||
$this->chunkChange[$index][$Y] = 8192;
|
$this->chunkChange[$index][$Y] = 8192;
|
||||||
$this->locationTable[$index][0] |= 1 << $Y;
|
$this->locationTable[$index][0] |= 1 << $Y;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
public function initCleanChunk($X, $Z){
|
||||||
|
$index = self::getIndex($X, $Z);
|
||||||
|
if(!isset($this->chunks[$index])){
|
||||||
|
$this->chunks[$index] = array(
|
||||||
|
0 => false,
|
||||||
|
1 => false,
|
||||||
|
2 => false,
|
||||||
|
3 => false,
|
||||||
|
4 => false,
|
||||||
|
5 => false,
|
||||||
|
6 => false,
|
||||||
|
7 => 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,
|
||||||
|
);
|
||||||
|
$this->locationTable[$index] = array(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
public function setMiniChunk($X, $Z, $Y, $data){
|
public function setMiniChunk($X, $Z, $Y, $data){
|
||||||
if($this->isChunkLoaded($X, $Z) === false){
|
if($this->isChunkLoaded($X, $Z) === false){
|
||||||
$this->loadChunk($X, $Z);
|
$this->loadChunk($X, $Z);
|
||||||
|
|
@ -328,7 +374,7 @@ class PMFLevel extends PMF{
|
||||||
console("[NOTICE] If you see this message, you should send the log with error to the devs.");
|
console("[NOTICE] If you see this message, you should send the log with error to the devs.");
|
||||||
}
|
}
|
||||||
public function getBlockID($x, $y, $z){
|
public function getBlockID($x, $y, $z){
|
||||||
if($y > 127 or $y < 0 or $x < 0 or $z < 0 or $x > 255 or $z > 255){
|
if($y > 127 or $y < 0){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
$X = $x >> 4;
|
$X = $x >> 4;
|
||||||
|
|
@ -349,16 +395,16 @@ class PMFLevel extends PMF{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBlockID($x, $y, $z, $block){
|
public function setBlockID($x, $y, $z, $block){
|
||||||
if($y > 127 or $y < 0 or $x < 0 or $z < 0 or $x > 255 or $z > 255){
|
if($y >= 128 or $y < 0){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if($y > 127 or $y < 0){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$X = $x >> 4;
|
$X = $x >> 4;
|
||||||
$Z = $z >> 4;
|
$Z = $z >> 4;
|
||||||
$Y = $y >> 4;
|
$Y = $y >> 4;
|
||||||
$block &= 0xFF;
|
$block &= 0xFF;
|
||||||
if($X >= 32 or $Z >= 32 or $Y >= $this->levelData["height"] or $y < 0){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$index = $this->getIndex($X, $Z);
|
$index = $this->getIndex($X, $Z);
|
||||||
$aX = $x & 0xf;
|
$aX = $x & 0xf;
|
||||||
$aZ = $z & 0xf;
|
$aZ = $z & 0xf;
|
||||||
|
|
@ -374,7 +420,7 @@ class PMFLevel extends PMF{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBlockDamage($x, $y, $z){
|
public function getBlockDamage($x, $y, $z){
|
||||||
if($y > 127 or $y < 0 or $x < 0 or $z < 0 or $x > 255 or $z > 255){
|
if($y > 127 or $y < 0){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
$X = $x >> 4;
|
$X = $x >> 4;
|
||||||
|
|
@ -399,16 +445,13 @@ class PMFLevel extends PMF{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBlockDamage($x, $y, $z, $damage){
|
public function setBlockDamage($x, $y, $z, $damage){
|
||||||
if($y > 127 or $y < 0 or $x < 0 or $z < 0 or $x > 255 or $z > 255){
|
if($y > 127 or $y < 0){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$X = $x >> 4;
|
$X = $x >> 4;
|
||||||
$Z = $z >> 4;
|
$Z = $z >> 4;
|
||||||
$Y = $y >> 4;
|
$Y = $y >> 4;
|
||||||
$damage &= 0x0F;
|
$damage &= 0x0F;
|
||||||
if($X >= 32 or $Z >= 32 or $Y >= $this->levelData["height"] or $y < 0){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$index = $this->getIndex($X, $Z);
|
$index = $this->getIndex($X, $Z);
|
||||||
$aX = $x & 0xf;
|
$aX = $x & 0xf;
|
||||||
$aZ = $z & 0xf;
|
$aZ = $z & 0xf;
|
||||||
|
|
@ -438,7 +481,7 @@ class PMFLevel extends PMF{
|
||||||
$X = $x >> 4;
|
$X = $x >> 4;
|
||||||
$Z = $z >> 4;
|
$Z = $z >> 4;
|
||||||
$Y = $y >> 4;
|
$Y = $y >> 4;
|
||||||
if($x < 0 or $z < 0 or $X >= $this->levelData["width"] or $Z >= $this->levelData["width"] or $Y >= $this->levelData["height"] or $y < 0){
|
if($y >= 128 or $y < 0){
|
||||||
return [AIR, 0];
|
return [AIR, 0];
|
||||||
}
|
}
|
||||||
$index = $this->getIndex($X, $Z);
|
$index = $this->getIndex($X, $Z);
|
||||||
|
|
@ -475,7 +518,7 @@ class PMFLevel extends PMF{
|
||||||
$Y = $y >> 4;
|
$Y = $y >> 4;
|
||||||
$block &= 0xFF;
|
$block &= 0xFF;
|
||||||
$meta &= 0x0F;
|
$meta &= 0x0F;
|
||||||
if($X >= 32 or $Z >= 32 or $Y >= $this->levelData["height"] or $y < 0){
|
if($Y >= 128 or $y < 0){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$index = $this->getIndex($X, $Z);
|
$index = $this->getIndex($X, $Z);
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ class Level{
|
||||||
$this->mobSpawner = new MobSpawner($this);
|
$this->mobSpawner = new MobSpawner($this);
|
||||||
$gen = $this->level->levelData["generator"];
|
$gen = $this->level->levelData["generator"];
|
||||||
$this->generator = new $gen([]);
|
$this->generator = new $gen([]);
|
||||||
|
$this->generator->init($this, new Random($this->getSeed()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(){
|
public function close(){
|
||||||
|
|
@ -98,7 +99,7 @@ class Level{
|
||||||
return $cache;
|
return $cache;
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
$gen = !($X > 15 || $X < 0 || $Z > 15 || $Z < 0); //TODO inf Worlds
|
$gen = true;//!($X > 15 || $X < 0 || $Z > 15 || $Z < 0); //TODO inf Worlds
|
||||||
$orderedIds = "";
|
$orderedIds = "";
|
||||||
$orderedData = "";
|
$orderedData = "";
|
||||||
$orderedSkyLight = str_repeat("\x00", 16*16*64);
|
$orderedSkyLight = str_repeat("\x00", 16*16*64);
|
||||||
|
|
@ -106,8 +107,8 @@ class Level{
|
||||||
$orderedBiomeIds = str_repeat("\x01", 16*16); //all plains, according to PocketMine 1.4 source
|
$orderedBiomeIds = str_repeat("\x01", 16*16); //all plains, according to PocketMine 1.4 source
|
||||||
$orderedBiomeColors = str_repeat("\x00\x85\xb2\x4a", 256); // also PM 1.4
|
$orderedBiomeColors = str_repeat("\x00\x85\xb2\x4a", 256); // also PM 1.4
|
||||||
$tileEntities = "";
|
$tileEntities = "";
|
||||||
|
$this->level->generateChunk($X, $Z, $this->generator);
|
||||||
if($gen){
|
if(!$this->level->isChunkLoaded($X, $Z)){
|
||||||
$this->level->loadChunk($X, $Z);
|
$this->level->loadChunk($X, $Z);
|
||||||
}
|
}
|
||||||
$miniChunks = [];
|
$miniChunks = [];
|
||||||
|
|
@ -237,7 +238,7 @@ class Level{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function useChunk($X, $Z, Player $player){
|
public function useChunk($X, $Z, Player $player){
|
||||||
if($X > 15 || $X < 0 || $Z > 15 || $Z < 0) return; //TODO inf worlds
|
//if($X > 15 || $X < 0 || $Z > 15 || $Z < 0) return; //TODO inf worlds
|
||||||
if(!isset($this->usedChunks[$X . "." . $Z])){
|
if(!isset($this->usedChunks[$X . "." . $Z])){
|
||||||
$this->usedChunks[$X . "." . $Z] = [];
|
$this->usedChunks[$X . "." . $Z] = [];
|
||||||
}
|
}
|
||||||
|
|
@ -384,7 +385,7 @@ class Level{
|
||||||
}
|
}
|
||||||
|
|
||||||
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){
|
||||||
if(!isset($this->level) or (($pos instanceof Position) and $pos->level !== $this) or $pos->x < 0 or $pos->y < 0 or $pos->z < 0){
|
if(!isset($this->level) or (($pos instanceof Position) and $pos->level !== $this) or $pos->y < 0){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata());
|
$ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue