mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-15 07:55:31 +00:00
Merge branch 'release/3.3' into release/3.4
This commit is contained in:
commit
af1227f154
@ -887,20 +887,31 @@ class Chunk{
|
|||||||
$stream = new BinaryStream();
|
$stream = new BinaryStream();
|
||||||
$stream->putInt($this->x);
|
$stream->putInt($this->x);
|
||||||
$stream->putInt($this->z);
|
$stream->putInt($this->z);
|
||||||
$count = 0;
|
$stream->putByte(($this->lightPopulated ? 4 : 0) | ($this->terrainPopulated ? 2 : 0) | ($this->terrainGenerated ? 1 : 0));
|
||||||
$subChunks = "";
|
if($this->terrainGenerated){
|
||||||
foreach($this->subChunks as $y => $subChunk){
|
//subchunks
|
||||||
if($subChunk instanceof EmptySubChunk){
|
$count = 0;
|
||||||
continue;
|
$subChunks = "";
|
||||||
|
foreach($this->subChunks as $y => $subChunk){
|
||||||
|
if($subChunk instanceof EmptySubChunk){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
++$count;
|
||||||
|
$subChunks .= chr($y) . $subChunk->getBlockIdArray() . $subChunk->getBlockDataArray();
|
||||||
|
if($this->lightPopulated){
|
||||||
|
$subChunks .= $subChunk->getBlockSkyLightArray() . $subChunk->getBlockLightArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$stream->putByte($count);
|
||||||
|
$stream->put($subChunks);
|
||||||
|
|
||||||
|
//biomes
|
||||||
|
$stream->put($this->biomeIds);
|
||||||
|
if($this->lightPopulated){
|
||||||
|
$stream->put(pack("v*", ...$this->heightMap));
|
||||||
}
|
}
|
||||||
++$count;
|
|
||||||
$subChunks .= chr($y) . $subChunk->fastSerialize();
|
|
||||||
}
|
}
|
||||||
$stream->putByte($count);
|
|
||||||
$stream->put($subChunks);
|
|
||||||
$stream->put(pack("v*", ...$this->heightMap) .
|
|
||||||
$this->biomeIds .
|
|
||||||
chr(($this->lightPopulated ? 4 : 0) | ($this->terrainPopulated ? 2 : 0) | ($this->terrainGenerated ? 1 : 0)));
|
|
||||||
return $stream->getBuffer();
|
return $stream->getBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -916,19 +927,36 @@ class Chunk{
|
|||||||
|
|
||||||
$x = $stream->getInt();
|
$x = $stream->getInt();
|
||||||
$z = $stream->getInt();
|
$z = $stream->getInt();
|
||||||
|
$flags = $stream->getByte();
|
||||||
|
$lightPopulated = (bool) ($flags & 4);
|
||||||
|
$terrainPopulated = (bool) ($flags & 2);
|
||||||
|
$terrainGenerated = (bool) ($flags & 1);
|
||||||
|
|
||||||
$subChunks = [];
|
$subChunks = [];
|
||||||
$count = $stream->getByte();
|
$biomeIds = "";
|
||||||
for($y = 0; $y < $count; ++$y){
|
$heightMap = [];
|
||||||
$subChunks[$stream->getByte()] = SubChunk::fastDeserialize($stream->get(10240));
|
if($terrainGenerated){
|
||||||
|
$count = $stream->getByte();
|
||||||
|
for($y = 0; $y < $count; ++$y){
|
||||||
|
$subChunks[$stream->getByte()] = new SubChunk(
|
||||||
|
$stream->get(4096), //blockids
|
||||||
|
$stream->get(2048), //blockdata
|
||||||
|
$lightPopulated ? $stream->get(2048) : "", //skylight
|
||||||
|
$lightPopulated ? $stream->get(2048) : "" //blocklight
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$biomeIds = $stream->get(256);
|
||||||
|
if($lightPopulated){
|
||||||
|
$heightMap = array_values(unpack("v*", $stream->get(512)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$heightMap = array_values(unpack("v*", $stream->get(512)));
|
|
||||||
$biomeIds = $stream->get(256);
|
|
||||||
|
|
||||||
$chunk = new Chunk($x, $z, $subChunks, [], [], $biomeIds, $heightMap);
|
$chunk = new Chunk($x, $z, $subChunks, [], [], $biomeIds, $heightMap);
|
||||||
$flags = $stream->getByte();
|
$chunk->setGenerated($terrainGenerated);
|
||||||
$chunk->lightPopulated = (bool) ($flags & 4);
|
$chunk->setPopulated($terrainPopulated);
|
||||||
$chunk->terrainPopulated = (bool) ($flags & 2);
|
$chunk->setLightPopulated($lightPopulated);
|
||||||
$chunk->terrainGenerated = (bool) ($flags & 1);
|
|
||||||
return $chunk;
|
return $chunk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,8 +126,4 @@ class EmptySubChunk implements SubChunkInterface{
|
|||||||
public function networkSerialize() : string{
|
public function networkSerialize() : string{
|
||||||
return "\x00" . str_repeat("\x00", 6144);
|
return "\x00" . str_repeat("\x00", 6144);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fastSerialize() : string{
|
|
||||||
throw new \BadMethodCallException("Should not try to serialize empty subchunks");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -200,23 +200,6 @@ class SubChunk implements SubChunkInterface{
|
|||||||
return "\x00" . $this->ids . $this->data;
|
return "\x00" . $this->ids . $this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fastSerialize() : string{
|
|
||||||
return
|
|
||||||
$this->ids .
|
|
||||||
$this->data .
|
|
||||||
$this->skyLight .
|
|
||||||
$this->blockLight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function fastDeserialize(string $data) : SubChunk{
|
|
||||||
return new SubChunk(
|
|
||||||
substr($data, 0, 4096), //ids
|
|
||||||
substr($data, 4096, 2048), //data
|
|
||||||
substr($data, 6144, 2048), //sky light
|
|
||||||
substr($data, 8192, 2048) //block light
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __debugInfo(){
|
public function __debugInfo(){
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -202,9 +202,4 @@ interface SubChunkInterface{
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function networkSerialize() : string;
|
public function networkSerialize() : string;
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function fastSerialize() : string;
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user