Convert BlockFactory to singleton

This commit is contained in:
Dylan K. Taylor
2020-04-23 23:45:13 +01:00
parent accc0da0cb
commit 13d784cd0c
24 changed files with 1121 additions and 1121 deletions

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace pocketmine\world\generator;
use pocketmine\block\BlockFactory;
use pocketmine\scheduler\AsyncTask;
use pocketmine\world\biome\Biome;
use pocketmine\world\World;
@ -56,7 +55,6 @@ class GeneratorRegisterTask extends AsyncTask{
}
public function onRun() : void{
BlockFactory::init();
Biome::init();
$manager = new GeneratorChunkManager($this->worldHeight);
$this->worker->saveToThreadStore("generation.world{$this->worldId}.manager", $manager);

View File

@ -119,8 +119,9 @@ class PopulationTask extends AsyncTask{
$chunk = $manager->getChunk($chunk->getX(), $chunk->getZ());
$chunk->setPopulated();
$chunk->recalculateHeightMap(BlockFactory::$lightFilter, BlockFactory::$diffusesSkyLight);
$chunk->populateSkyLight(BlockFactory::$lightFilter);
$blockFactory = BlockFactory::getInstance();
$chunk->recalculateHeightMap($blockFactory->lightFilter, $blockFactory->diffusesSkyLight);
$chunk->populateSkyLight($blockFactory->lightFilter);
$chunk->setLightPopulated();
$this->chunk = FastChunkSerializer::serialize($chunk);

View File

@ -36,6 +36,7 @@ class GroundCover extends Populator{
public function populate(ChunkManager $world, int $chunkX, int $chunkZ, Random $random) : void{
$chunk = $world->getChunk($chunkX, $chunkZ);
$factory = BlockFactory::getInstance();
for($x = 0; $x < 16; ++$x){
for($z = 0; $z < 16; ++$z){
$biome = Biome::getBiome($chunk->getBiomeId($x, $z));
@ -48,7 +49,7 @@ class GroundCover extends Populator{
$startY = 127;
for(; $startY > 0; --$startY){
if(!BlockFactory::fromFullBlock($chunk->getFullBlock($x, $startY, $z))->isTransparent()){
if(!$factory->fromFullBlock($chunk->getFullBlock($x, $startY, $z))->isTransparent()){
break;
}
}
@ -56,7 +57,7 @@ class GroundCover extends Populator{
$endY = $startY - count($cover);
for($y = $startY; $y > $endY and $y >= 0; --$y){
$b = $cover[$startY - $y];
$id = BlockFactory::fromFullBlock($chunk->getFullBlock($x, $y, $z));
$id = $factory->fromFullBlock($chunk->getFullBlock($x, $y, $z));
if($id->getId() === BlockLegacyIds::AIR and $b->isSolid()){
break;
}