mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
Fix for thrown EmptyChunkSection modification exception
This commit is contained in:
parent
6d77b0883e
commit
2330f363bd
@ -80,6 +80,13 @@ interface LevelProvider{
|
||||
*/
|
||||
public function getChunk($X, $Z, $create = false);
|
||||
|
||||
/**
|
||||
* @param $Y 0-7
|
||||
*
|
||||
* @return ChunkSection
|
||||
*/
|
||||
public function createChunkSection($Y);
|
||||
|
||||
public function saveChunks();
|
||||
|
||||
/**
|
||||
|
@ -223,6 +223,16 @@ class Anvil extends BaseLevelProvider{
|
||||
}
|
||||
}
|
||||
|
||||
public function createChunkSection($Y){
|
||||
return new ChunkSection(new Compound(null, [
|
||||
"Y" => new Byte("Y", $Y),
|
||||
"Blocks" => new ByteArray("Blocks", str_repeat("\xff", 4096)),
|
||||
"Data" => new ByteArray("Data", str_repeat("\xff", 2048)),
|
||||
"SkyLight" => new ByteArray("SkyLight", str_repeat("\xff", 2048)), //TODO
|
||||
"BlockLight" => new ByteArray("BlockLight", str_repeat("\x00", 2048)) //TODO
|
||||
]));
|
||||
}
|
||||
|
||||
public function isChunkGenerated($chunkX, $chunkZ){
|
||||
if(($region = $this->getRegion($chunkX >> 5, $chunkZ >> 5)) instanceof RegionLoader){
|
||||
return $region->chunkExists($chunkX - $region->getX() * 32, $chunkZ - $region->getZ() * 32);
|
||||
|
@ -160,7 +160,12 @@ abstract class BaseChunk implements Chunk{
|
||||
}
|
||||
|
||||
public function setBlock($x, $y, $z, $blockId = null, $meta = null){
|
||||
return $this->sections[$y >> 4]->setBlock($x, $y & 0x0f, $z, $blockId & 0xff, $meta & 0x0f);
|
||||
try{
|
||||
return $this->sections[$y >> 4]->setBlock($x, $y & 0x0f, $z, $blockId & 0xff, $meta & 0x0f);
|
||||
}catch(\Exception $e){
|
||||
$this->setSection($Y = $y >> 4, $this->getLevel()->createChunkSection($Y));
|
||||
return $this->setBlock($x, $y, $z, $blockId, $meta);
|
||||
}
|
||||
}
|
||||
|
||||
public function getBlockId($x, $y, $z){
|
||||
@ -168,7 +173,12 @@ abstract class BaseChunk implements Chunk{
|
||||
}
|
||||
|
||||
public function setBlockId($x, $y, $z, $id){
|
||||
$this->sections[$y >> 4]->setBlockId($x, $y & 0x0f, $z, $id);
|
||||
try{
|
||||
$this->sections[$y >> 4]->setBlockId($x, $y & 0x0f, $z, $id);
|
||||
}catch(\Exception $e){
|
||||
$this->setSection($Y = $y >> 4, $this->getLevel()->createChunkSection($Y));
|
||||
$this->setBlockId($x, $y, $z, $id);
|
||||
}
|
||||
}
|
||||
|
||||
public function getBlockData($x, $y, $z){
|
||||
@ -176,7 +186,12 @@ abstract class BaseChunk implements Chunk{
|
||||
}
|
||||
|
||||
public function setBlockData($x, $y, $z, $data){
|
||||
$this->sections[$y >> 4]->setBlockData($x, $y & 0x0f, $z, $data);
|
||||
try{
|
||||
$this->sections[$y >> 4]->setBlockData($x, $y & 0x0f, $z, $data);
|
||||
}catch(\Exception $e){
|
||||
$this->setSection($Y = $y >> 4, $this->getLevel()->createChunkSection($Y));
|
||||
$this->setBlockData($x, $y, $z, $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function getBlockSkyLight($x, $y, $z){
|
||||
@ -184,7 +199,12 @@ abstract class BaseChunk implements Chunk{
|
||||
}
|
||||
|
||||
public function setBlockSkyLight($x, $y, $z, $data){
|
||||
$this->sections[$y >> 4]->getBlockSkyLight($x, $y & 0x0f, $z, $data);
|
||||
try{
|
||||
$this->sections[$y >> 4]->getBlockSkyLight($x, $y & 0x0f, $z, $data);
|
||||
}catch(\Exception $e){
|
||||
$this->setSection($Y = $y >> 4, $this->getLevel()->createChunkSection($Y));
|
||||
$this->setBlockSkyLight($x, $y, $z, $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function getBlockLight($x, $y, $z){
|
||||
@ -192,7 +212,12 @@ abstract class BaseChunk implements Chunk{
|
||||
}
|
||||
|
||||
public function setBlockLight($x, $y, $z, $data){
|
||||
$this->sections[$y >> 4]->getBlockSkyLight($x, $y & 0x0f, $z, $data);
|
||||
try{
|
||||
$this->sections[$y >> 4]->getBlockSkyLight($x, $y & 0x0f, $z, $data);
|
||||
}catch(\Exception $e){
|
||||
$this->setSection($Y = $y >> 4, $this->getLevel()->createChunkSection($Y));
|
||||
$this->setBlockLight($x, $y, $z, $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function getBiomeId($x, $z){
|
||||
|
Loading…
x
Reference in New Issue
Block a user