added skylight and light into chunk data, revert if any major problems will occur

This commit is contained in:
GameHerobrine 2023-03-07 10:58:47 +03:00
parent fc154cf903
commit b6da664236
5 changed files with 41 additions and 34 deletions

View file

@ -28,7 +28,7 @@ class GrassBlock extends SolidBlock{
else $player->setSlot($player->slot, $item, true);
}
$this->level->setBlock($this, new FarmlandBlock());
$this->seedsDrop();
//$this->seedsDrop();
return true;
}
return false;
@ -53,4 +53,4 @@ class GrassBlock extends SolidBlock{
}
return BLOCK_UPDATE_RANDOM;
}
}
}

View file

@ -248,7 +248,7 @@ class PMFLevel extends PMF{
protected function isMiniChunkEmpty($X, $Z, $Y){
$index = $this->getIndex($X, $Z);
if($this->chunks[$index][$Y] !== false){
if(substr_count($this->chunks[$index][$Y], "\x00") < 8192){
if(substr_count($this->chunks[$index][$Y], "\x00") < 16384){
return false;
}
}
@ -257,11 +257,11 @@ class PMFLevel extends PMF{
public function getMiniChunk($X, $Z, $Y){
if($this->loadChunk($X, $Z) === false){
return str_repeat("\x00", 8192);
return str_repeat("\x00", 16384);
}
$index = $this->getIndex($X, $Z);
if(!isset($this->chunks[$index][$Y]) or $this->chunks[$index][$Y] === false){
return str_repeat("\x00", 8192);
return str_repeat("\x00", 16384);
}
return $this->chunks[$index][$Y];
}
@ -307,7 +307,7 @@ class PMFLevel extends PMF{
$t = 1 << $Y;
if(($info[0] & $t) === $t){
// 4096 + 2048 + 2048, Block Data, Meta, Light
if(strlen($this->chunks[$index][$Y] = gzread($chunk, 8192)) < 8192){
if(strlen($this->chunks[$index][$Y] = gzread($chunk, 16384)) < 16384){
console("[NOTICE] Empty corrupt chunk detected [$X,$Z,:$Y], recovering contents", true, true, 2);
$this->fillMiniChunk($X, $Z, $Y);
}
@ -325,9 +325,9 @@ class PMFLevel extends PMF{
}
$index = $this->getIndex($X, $Z);
$this->chunks[$index][$Y] = str_repeat("\x00", 8192);
$this->chunks[$index][$Y] = str_repeat("\x00", 16384);
$this->chunkChange[$index][-1] = true;
$this->chunkChange[$index][$Y] = 8192;
$this->chunkChange[$index][$Y] = 16384;
$this->locationTable[$index][0] |= 1 << $Y;
return true;
}
@ -346,14 +346,14 @@ class PMFLevel extends PMF{
);
$this->chunkChange[$index] = array(
-1 => true,
0 => 8192,
1 => 8192,
2 => 8192,
3 => 8192,
4 => 8192,
5 => 8192,
6 => 8192,
7 => 8192,
0 => 16384,
1 => 16384,
2 => 16384,
3 => 16384,
4 => 16384,
5 => 16384,
6 => 16384,
7 => 16384,
);
$this->chunkInfo[$index] = array(
0 => 0,
@ -366,13 +366,13 @@ class PMFLevel extends PMF{
if($this->isChunkLoaded($X, $Z) === false){
$this->loadChunk($X, $Z);
}
if(strlen($data) !== 8192){
if(strlen($data) !== 16384){
return false;
}
$index = $this->getIndex($X, $Z);
$this->chunks[$index][$Y] = (string) $data;
$this->chunkChange[$index][-1] = true;
$this->chunkChange[$index][$Y] = 8192;
$this->chunkChange[$index][$Y] = 16384;
$this->locationTable[$index][0] |= 1 << $Y;
return true;
}
@ -394,7 +394,7 @@ class PMFLevel extends PMF{
$aY = $y & 0xf;
if(is_array($this->chunks) && isset($this->chunks[$index]) && is_array($this->chunks[$index]) && isset($this->chunks[$index][$Y]) && is_string($this->chunks[$index][$Y])){
$b = ord($this->chunks[$index][$Y][($aY + ($aX << 5) + ($aZ << 9))]);
$b = ord($this->chunks[$index][$Y][($aY + ($aX << 6) + ($aZ << 10))]);
}else{ //php8 fix
$b = 0;
}
@ -417,7 +417,7 @@ class PMFLevel extends PMF{
$aX = $x & 0xf;
$aZ = $z & 0xf;
$aY = $y & 0xf;
$this->chunks[$index][$Y][(int) ($aY + ($aX << 5) + ($aZ << 9))] = chr($block);
$this->chunks[$index][$Y][(int) ($aY + ($aX << 6) + ($aZ << 10))] = chr($block);
if(!isset($this->chunkChange[$index][$Y])){
$this->chunkChange[$index][$Y] = 1;
}else{
@ -439,7 +439,7 @@ class PMFLevel extends PMF{
$aZ = $z & 0xf;
$aY = $y & 0xf;
if(is_array($this->chunks) && isset($this->chunks[$index]) && is_array($this->chunks[$index]) && isset($this->chunks[$index][$Y]) && is_string($this->chunks[$index][$Y])){
$m = ord($this->chunks[$index][$Y][(int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]);
$m = ord($this->chunks[$index][$Y][(int) (($aY >> 1) + 16 + ($aX << 6) + ($aZ << 10))]);
}else{ //php8 fix
$m = 0;
}
@ -464,7 +464,7 @@ class PMFLevel extends PMF{
$aX = $x & 0xf;
$aZ = $z & 0xf;
$aY = $y & 0xf;
$mindex = (int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9));
$mindex = (int) (($aY >> 1) + 16 + ($aX << 6) + ($aZ << 10));
$old_m = ord($this->chunks[$index][$Y][$mindex]);
if(($y & 1) === 0){
$m = ($old_m & 0xF0) | $damage;
@ -505,8 +505,8 @@ class PMFLevel extends PMF{
$aY = $y & 0xf;
#Need to fix. But idk how.
if(is_array($this->chunks) && is_array($this->chunks[$index]) && is_string($this->chunks[$index][$Y])){ //PHP8 warn fix
$b = ord($this->chunks[$index][$Y][($aY + ($aX << 5) + ($aZ << 9))]);
$m = ord($this->chunks[$index][$Y][(($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]);
$b = ord($this->chunks[$index][$Y][($aY + ($aX << 6) + ($aZ << 10))]);
$m = ord($this->chunks[$index][$Y][(($aY >> 1) + 16 + ($aX << 6) + ($aZ << 10))]);
}else{
$b = 0;
$m = 0;
@ -540,8 +540,8 @@ class PMFLevel extends PMF{
$aX = $x - ($X << 4);
$aZ = $z - ($Z << 4);
$aY = $y - ($Y << 4);
$bindex = (int) ($aY + ($aX << 5) + ($aZ << 9));
$mindex = (int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9));
$bindex = (int) ($aY + ($aX << 6) + ($aZ << 10));
$mindex = (int) (($aY >> 1) + 16 + ($aX << 6) + ($aZ << 10));
$old_b = ord($this->chunks[$index][$Y][$bindex]);
$old_m = ord($this->chunks[$index][$Y][$mindex]);
if(($y & 1) === 0){

View file

@ -110,9 +110,9 @@ class Level{
$gen = $this->generatorType === 1 || !($X > 15 || $X < 0 || $Z > 15 || $Z < 0);
$orderedIds = "";
$orderedData = "";
$orderedSkyLight = str_repeat("\x00", 16*16*64);
$orderedLight = str_repeat("\x00", 16*16*64);
$orderedBiomeIds = str_repeat("\x01", 16*16); //all plains, according to PocketMine 1.4 source
$orderedSkyLight = ""; //str_repeat("\xff", 16*16*64);
$orderedLight = ""; //str_repeat("\xff", 16*16*64);
$orderedBiomeIds = str_repeat("\x0f", 16*16); //all plains, according to PocketMine 1.4 source
$orderedBiomeColors = str_repeat("\x00\x85\xb2\x4a", 256); // also PM 1.4
$tileEntities = "";
if($gen)$this->level->generateChunk($X, $Z, $this->generator);
@ -128,16 +128,17 @@ class Level{
for ($i = 0; $i < 16; $i++){
for ($j = 0; $j < 16; $j++){
$bIndex = ($i << 5) + ($j << 9);
$bIndex = ($i << 6) + ($j << 10);
foreach($miniChunks as $chunk){
$orderedIds .= substr($chunk, $bIndex, 16);
$orderedData .= substr($chunk, $bIndex + 16, 8);
$orderedLight .= substr($chunk, $bIndex + 32, 8);
$orderedSkyLight .= substr($chunk, $bIndex + 48, 8);
}
}
}
$chunkTiles = [];
console(strlen($orderedLight));
$tiles = $this->server->query("SELECT ID FROM tiles WHERE spawnable = 1 AND level = '".$this->getName()."' AND x >= ".($X * 16 - 1)." AND x < ".($X * 16 + 17)." AND z >= ".($Z * 16 - 1)." AND z < ".($Z * 16 + 17).";");
if($tiles !== false and $tiles !== true){
while(($tile = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){
@ -149,7 +150,7 @@ class Level{
}
$nbt = new NBT_new(NBT_new::LITTLE_ENDIAN);
foreach($chunkTiles as $tile){
foreach($chunkTiles as $tile){
switch($tile->class){
case "Sign":
$text = $tile->getText();

View file

@ -143,6 +143,10 @@ class ExperimentalGenerator implements NewLevelGenerator{
}
}
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
//$chunk .= str_repeat("\xff", 16);
//$chunk .= str_repeat("\xff", 16);
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
}
}
$this->level->setMiniChunk($chunkX, $chunkZ, $chunkY, $chunk);

View file

@ -130,7 +130,9 @@ class NormalGenerator implements NewLevelGenerator{
$chunk .= "\x00";
}
}
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; //meta
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; //light/skylight
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; //skylight/light
}
}
$this->level->setMiniChunk($chunkX, $chunkZ, $chunkY, $chunk);