mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 09:19:42 +00:00
Cleaned up SubChunk implementation
This commit is contained in:
parent
938452bfe9
commit
e11f1e94e9
@ -54,7 +54,7 @@ class Chunk{
|
|||||||
|
|
||||||
protected $height = Chunk::MAX_SUBCHUNKS;
|
protected $height = Chunk::MAX_SUBCHUNKS;
|
||||||
|
|
||||||
/** @var SubChunk[] */
|
/** @var SubChunkInterface[] */
|
||||||
protected $subChunks = [];
|
protected $subChunks = [];
|
||||||
|
|
||||||
/** @var EmptySubChunk */
|
/** @var EmptySubChunk */
|
||||||
@ -82,13 +82,13 @@ class Chunk{
|
|||||||
protected $NBTentities = [];
|
protected $NBTentities = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $chunkX
|
* @param int $chunkX
|
||||||
* @param int $chunkZ
|
* @param int $chunkZ
|
||||||
* @param SubChunk[] $subChunks
|
* @param SubChunkInterface[] $subChunks
|
||||||
* @param CompoundTag[] $entities
|
* @param CompoundTag[] $entities
|
||||||
* @param CompoundTag[] $tiles
|
* @param CompoundTag[] $tiles
|
||||||
* @param string $biomeIds
|
* @param string $biomeIds
|
||||||
* @param int[] $heightMap
|
* @param int[] $heightMap
|
||||||
*/
|
*/
|
||||||
public function __construct(int $chunkX, int $chunkZ, array $subChunks = [], array $entities = [], array $tiles = [], string $biomeIds = "", array $heightMap = []){
|
public function __construct(int $chunkX, int $chunkZ, array $subChunks = [], array $entities = [], array $tiles = [], string $biomeIds = "", array $heightMap = []){
|
||||||
$this->x = $chunkX;
|
$this->x = $chunkX;
|
||||||
@ -514,7 +514,7 @@ class Chunk{
|
|||||||
public function getBlockSkyLightColumn(int $x, int $z) : string{
|
public function getBlockSkyLightColumn(int $x, int $z) : string{
|
||||||
$result = "";
|
$result = "";
|
||||||
foreach($this->subChunks as $subChunk){
|
foreach($this->subChunks as $subChunk){
|
||||||
$result .= $subChunk->getSkyLightColumn($x, $z);
|
$result .= $subChunk->getBlockSkyLightColumn($x, $z);
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@ -797,9 +797,9 @@ class Chunk{
|
|||||||
* @param int $y
|
* @param int $y
|
||||||
* @param bool $generateNew Whether to create a new, modifiable subchunk if there is not one in place
|
* @param bool $generateNew Whether to create a new, modifiable subchunk if there is not one in place
|
||||||
*
|
*
|
||||||
* @return SubChunk|EmptySubChunk
|
* @return SubChunkInterface
|
||||||
*/
|
*/
|
||||||
public function getSubChunk(int $y, bool $generateNew = false) : SubChunk{
|
public function getSubChunk(int $y, bool $generateNew = false) : SubChunkInterface{
|
||||||
if($y < 0 or $y >= $this->height){
|
if($y < 0 or $y >= $this->height){
|
||||||
return $this->emptySubChunk;
|
return $this->emptySubChunk;
|
||||||
}elseif($generateNew and $this->subChunks[$y] instanceof EmptySubChunk){
|
}elseif($generateNew and $this->subChunks[$y] instanceof EmptySubChunk){
|
||||||
@ -811,13 +811,14 @@ class Chunk{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a subchunk in the chunk index
|
* Sets a subchunk in the chunk index
|
||||||
* @param int $y
|
*
|
||||||
* @param SubChunk|null $subChunk
|
* @param int $y
|
||||||
* @param bool $allowEmpty Whether to check if the chunk is empty, and if so replace it with an empty stub
|
* @param SubChunkInterface|null $subChunk
|
||||||
|
* @param bool $allowEmpty Whether to check if the chunk is empty, and if so replace it with an empty stub
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function setSubChunk(int $y, SubChunk $subChunk = null, bool $allowEmpty = false) : bool{
|
public function setSubChunk(int $y, SubChunkInterface $subChunk = null, bool $allowEmpty = false) : bool{
|
||||||
if($y < 0 or $y >= $this->height){
|
if($y < 0 or $y >= $this->height){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\level\format;
|
namespace pocketmine\level\format;
|
||||||
|
|
||||||
class EmptySubChunk extends SubChunk{
|
class EmptySubChunk implements SubChunkInterface{
|
||||||
|
|
||||||
public function __construct(){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isEmpty() : bool{
|
public function isEmpty() : bool{
|
||||||
return true;
|
return true;
|
||||||
@ -73,6 +69,10 @@ class EmptySubChunk extends SubChunk{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getHighestBlockAt(int $x, int $z) : int{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
public function getBlockIdColumn(int $x, int $z) : string{
|
public function getBlockIdColumn(int $x, int $z) : string{
|
||||||
return "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
return "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ class EmptySubChunk extends SubChunk{
|
|||||||
return "\x00\x00\x00\x00\x00\x00\x00\x00";
|
return "\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSkyLightColumn(int $x, int $z) : string{
|
public function getBlockSkyLightColumn(int $x, int $z) : string{
|
||||||
return "\xff\xff\xff\xff\xff\xff\xff\xff";
|
return "\xff\xff\xff\xff\xff\xff\xff\xff";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ class EmptySubChunk extends SubChunk{
|
|||||||
return str_repeat("\x00", 2048);
|
return str_repeat("\x00", 2048);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSkyLightArray() : string{
|
public function getBlockSkyLightArray() : string{
|
||||||
return str_repeat("\xff", 2048);
|
return str_repeat("\xff", 2048);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\level\format;
|
namespace pocketmine\level\format;
|
||||||
|
|
||||||
class SubChunk{
|
class SubChunk implements SubChunkInterface{
|
||||||
|
|
||||||
protected $ids;
|
protected $ids;
|
||||||
protected $data;
|
protected $data;
|
||||||
@ -182,7 +182,7 @@ class SubChunk{
|
|||||||
return substr($this->blockLight, (($x << 7) | ($z << 3)), 8);
|
return substr($this->blockLight, (($x << 7) | ($z << 3)), 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSkyLightColumn(int $x, int $z) : string{
|
public function getBlockSkyLightColumn(int $x, int $z) : string{
|
||||||
return substr($this->skyLight, (($x << 7) | ($z << 3)), 8);
|
return substr($this->skyLight, (($x << 7) | ($z << 3)), 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ class SubChunk{
|
|||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSkyLightArray() : string{
|
public function getBlockSkyLightArray() : string{
|
||||||
assert(strlen($this->skyLight) === 2048, "Wrong length of skylight array, expecting 2048 bytes, got " . strlen($this->skyLight));
|
assert(strlen($this->skyLight) === 2048, "Wrong length of skylight array, expecting 2048 bytes, got " . strlen($this->skyLight));
|
||||||
return $this->skyLight;
|
return $this->skyLight;
|
||||||
}
|
}
|
||||||
|
198
src/pocketmine/level/format/SubChunkInterface.php
Normal file
198
src/pocketmine/level/format/SubChunkInterface.php
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
<?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/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace pocketmine\level\format;
|
||||||
|
|
||||||
|
interface SubChunkInterface{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isEmpty() : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x
|
||||||
|
* @param int $y
|
||||||
|
* @param int $z
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getBlockId(int $x, int $y, int $z) : int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x
|
||||||
|
* @param int $y
|
||||||
|
* @param int $z
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function setBlockId(int $x, int $y, int $z, int $id) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x
|
||||||
|
* @param int $y
|
||||||
|
* @param int $z
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getBlockData(int $x, int $y, int $z) : int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x
|
||||||
|
* @param int $y
|
||||||
|
* @param int $z
|
||||||
|
* @param int $data
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function setBlockData(int $x, int $y, int $z, int $data) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x
|
||||||
|
* @param int $y
|
||||||
|
* @param int $z
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getFullBlock(int $x, int $y, int $z) : int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x
|
||||||
|
* @param int $y
|
||||||
|
* @param int $z
|
||||||
|
* @param int|null $id
|
||||||
|
* @param int|null $data
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function setBlock(int $x, int $y, int $z, $id = null, $data = null) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x
|
||||||
|
* @param int $y
|
||||||
|
* @param int $z
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getBlockLight(int $x, int $y, int $z) : int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x
|
||||||
|
* @param int $y
|
||||||
|
* @param int $z
|
||||||
|
* @param int $level
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function setBlockLight(int $x, int $y, int $z, int $level) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x
|
||||||
|
* @param int $y
|
||||||
|
* @param int $z
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getBlockSkyLight(int $x, int $y, int $z) : int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x
|
||||||
|
* @param int $y
|
||||||
|
* @param int $z
|
||||||
|
* @param int $level
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function setBlockSkyLight(int $x, int $y, int $z, int $level) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x
|
||||||
|
* @param int $z
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getHighestBlockAt(int $x, int $z) : int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x
|
||||||
|
* @param int $z
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBlockIdColumn(int $x, int $z) : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x
|
||||||
|
* @param int $z
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBlockDataColumn(int $x, int $z) : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x
|
||||||
|
* @param int $z
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBlockLightColumn(int $x, int $z) : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x
|
||||||
|
* @param int $z
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBlockSkyLightColumn(int $x, int $z) : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBlockIdArray() : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBlockDataArray() : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBlockSkyLightArray() : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBlockLightArray() : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function networkSerialize() : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function fastSerialize() : string;
|
||||||
|
}
|
@ -437,7 +437,7 @@ class LevelDB extends BaseLevelProvider{
|
|||||||
"\x00" . //Subchunk version byte
|
"\x00" . //Subchunk version byte
|
||||||
$subChunks[$y]->getBlockIdArray() .
|
$subChunks[$y]->getBlockIdArray() .
|
||||||
$subChunks[$y]->getBlockDataArray() .
|
$subChunks[$y]->getBlockDataArray() .
|
||||||
$subChunks[$y]->getSkyLightArray() .
|
$subChunks[$y]->getBlockSkyLightArray() .
|
||||||
$subChunks[$y]->getBlockLightArray()
|
$subChunks[$y]->getBlockLightArray()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ class Anvil extends McRegion{
|
|||||||
"Y" => new ByteTag("Y", $y),
|
"Y" => new ByteTag("Y", $y),
|
||||||
"Blocks" => new ByteArrayTag("Blocks", ChunkUtils::reorderByteArray($subChunk->getBlockIdArray())), //Generic in-memory chunks are currently always XZY
|
"Blocks" => new ByteArrayTag("Blocks", ChunkUtils::reorderByteArray($subChunk->getBlockIdArray())), //Generic in-memory chunks are currently always XZY
|
||||||
"Data" => new ByteArrayTag("Data", ChunkUtils::reorderNibbleArray($subChunk->getBlockDataArray())),
|
"Data" => new ByteArrayTag("Data", ChunkUtils::reorderNibbleArray($subChunk->getBlockDataArray())),
|
||||||
"SkyLight" => new ByteArrayTag("SkyLight", ChunkUtils::reorderNibbleArray($subChunk->getSkyLightArray(), "\xff")),
|
"SkyLight" => new ByteArrayTag("SkyLight", ChunkUtils::reorderNibbleArray($subChunk->getBlockSkyLightArray(), "\xff")),
|
||||||
"BlockLight" => new ByteArrayTag("BlockLight", ChunkUtils::reorderNibbleArray($subChunk->getBlockLightArray()))
|
"BlockLight" => new ByteArrayTag("BlockLight", ChunkUtils::reorderNibbleArray($subChunk->getBlockLightArray()))
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ class McRegion extends BaseLevelProvider{
|
|||||||
$subChunk = $subChunks[$y];
|
$subChunk = $subChunks[$y];
|
||||||
$ids .= $subChunk->getBlockIdColumn($x, $z);
|
$ids .= $subChunk->getBlockIdColumn($x, $z);
|
||||||
$data .= $subChunk->getBlockDataColumn($x, $z);
|
$data .= $subChunk->getBlockDataColumn($x, $z);
|
||||||
$skyLight .= $subChunk->getSkyLightColumn($x, $z);
|
$skyLight .= $subChunk->getBlockSkyLightColumn($x, $z);
|
||||||
$blockLight .= $subChunk->getBlockLightColumn($x, $z);
|
$blockLight .= $subChunk->getBlockLightColumn($x, $z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ class PMAnvil extends Anvil{
|
|||||||
"Y" => new ByteTag("Y", $y),
|
"Y" => new ByteTag("Y", $y),
|
||||||
"Blocks" => new ByteArrayTag("Blocks", $subChunk->getBlockIdArray()),
|
"Blocks" => new ByteArrayTag("Blocks", $subChunk->getBlockIdArray()),
|
||||||
"Data" => new ByteArrayTag("Data", $subChunk->getBlockDataArray()),
|
"Data" => new ByteArrayTag("Data", $subChunk->getBlockDataArray()),
|
||||||
"SkyLight" => new ByteArrayTag("SkyLight", $subChunk->getSkyLightArray()),
|
"SkyLight" => new ByteArrayTag("SkyLight", $subChunk->getBlockSkyLightArray()),
|
||||||
"BlockLight" => new ByteArrayTag("BlockLight", $subChunk->getBlockLightArray())
|
"BlockLight" => new ByteArrayTag("BlockLight", $subChunk->getBlockLightArray())
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user