mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Move block registration to its own class
This commit is contained in:
@ -29,6 +29,7 @@ namespace pocketmine\level;
|
||||
use pocketmine\block\Air;
|
||||
use pocketmine\block\Beetroot;
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\BrownMushroom;
|
||||
use pocketmine\block\Cactus;
|
||||
use pocketmine\block\Carrot;
|
||||
@ -313,7 +314,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct(Server $server, string $name, string $path, string $provider){
|
||||
$this->blockStates = Block::$fullList;
|
||||
$this->blockStates = BlockFactory::$fullList;
|
||||
$this->levelId = static::$levelIdCounter++;
|
||||
$this->blockMetadata = new BlockMetadataStore($this);
|
||||
$this->server = $server;
|
||||
@ -915,7 +916,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
}
|
||||
|
||||
public function addRandomTickedBlock(int $id){
|
||||
$this->randomTickBlocks[$id] = get_class(Block::$list[$id]);
|
||||
$this->randomTickBlocks[$id] = get_class(BlockFactory::$list[$id]);
|
||||
}
|
||||
|
||||
public function removeRandomTickedBlock(int $id){
|
||||
@ -1392,7 +1393,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
if($yPlusOne === $oldHeightMap){ //Block changed directly beneath the heightmap. Check if a block was removed or changed to a different light-filter.
|
||||
$newHeightMap = $this->getChunk($x >> 4, $z >> 4)->recalculateHeightMapColumn($x & 0x0f, $z & 0x0f);
|
||||
}elseif($yPlusOne > $oldHeightMap){ //Block changed above the heightmap.
|
||||
if(Block::$lightFilter[$sourceId] > 1 or Block::$diffusesSkyLight[$sourceId]){
|
||||
if(BlockFactory::$lightFilter[$sourceId] > 1 or BlockFactory::$diffusesSkyLight[$sourceId]){
|
||||
$this->setHeightMap($x, $z, $yPlusOne);
|
||||
$newHeightMap = $yPlusOne;
|
||||
}else{ //Block changed which has no effect on direct sky light, for example placing or removing glass.
|
||||
@ -1414,7 +1415,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
$update->setAndUpdateLight($x, $i, $z, 15);
|
||||
}
|
||||
}else{ //No heightmap change, block changed "underground"
|
||||
$update->setAndUpdateLight($x, $y, $z, max(0, $this->getHighestAdjacentBlockSkyLight($x, $y, $z) - Block::$lightFilter[$sourceId]));
|
||||
$update->setAndUpdateLight($x, $y, $z, max(0, $this->getHighestAdjacentBlockSkyLight($x, $y, $z) - BlockFactory::$lightFilter[$sourceId]));
|
||||
}
|
||||
|
||||
$update->execute();
|
||||
@ -1446,7 +1447,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
$this->timings->doBlockLightUpdates->startTiming();
|
||||
|
||||
$id = $this->getBlockIdAt($x, $y, $z);
|
||||
$newLevel = max(Block::$light[$id], $this->getHighestAdjacentBlockLight($x, $y, $z) - Block::$lightFilter[$id]);
|
||||
$newLevel = max(BlockFactory::$light[$id], $this->getHighestAdjacentBlockLight($x, $y, $z) - BlockFactory::$lightFilter[$id]);
|
||||
|
||||
$update = new BlockLightUpdate($this);
|
||||
$update->setAndUpdateLight($x, $y, $z, $newLevel);
|
||||
@ -1656,7 +1657,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
$above = $this->getBlock(new Vector3($target->x, $target->y + 1, $target->z));
|
||||
if($above !== null){
|
||||
if($above->getId() === Item::FIRE){
|
||||
$this->setBlock($above, Block::get(Block::AIR), true);
|
||||
$this->setBlock($above, BlockFactory::get(Block::AIR), true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2686,7 +2687,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
$wasAir = ($chunk->getBlockId($x, $y - 1, $z) === 0);
|
||||
for(; $y > 0; --$y){
|
||||
$b = $chunk->getFullBlock($x, $y, $z);
|
||||
$block = Block::get($b >> 4, $b & 0x0f);
|
||||
$block = BlockFactory::get($b >> 4, $b & 0x0f);
|
||||
if($this->isFullBlock($block)){
|
||||
if($wasAir){
|
||||
$y++;
|
||||
@ -2699,10 +2700,10 @@ class Level implements ChunkManager, Metadatable{
|
||||
|
||||
for(; $y >= 0 and $y < $max; ++$y){
|
||||
$b = $chunk->getFullBlock($x, $y + 1, $z);
|
||||
$block = Block::get($b >> 4, $b & 0x0f);
|
||||
$block = BlockFactory::get($b >> 4, $b & 0x0f);
|
||||
if(!$this->isFullBlock($block)){
|
||||
$b = $chunk->getFullBlock($x, $y, $z);
|
||||
$block = Block::get($b >> 4, $b & 0x0f);
|
||||
$block = BlockFactory::get($b >> 4, $b & 0x0f);
|
||||
if(!$this->isFullBlock($block)){
|
||||
return new Position($spawn->x, $y === (int) $spawn->y ? $spawn->y : $y, $spawn->z, $this);
|
||||
}
|
||||
|
Reference in New Issue
Block a user