diff --git a/src/Server.php b/src/Server.php index 459ac1f63c..b517bf1505 100644 --- a/src/Server.php +++ b/src/Server.php @@ -90,7 +90,6 @@ use pocketmine\utils\Terminal; use pocketmine\utils\TextFormat; use pocketmine\utils\Utils; use pocketmine\uuid\UUID; -use pocketmine\world\biome\Biome; use pocketmine\world\format\io\WorldProviderManager; use pocketmine\world\format\io\WritableWorldProvider; use pocketmine\world\generator\Generator; @@ -936,8 +935,6 @@ class Server{ $this->commandMap = new SimpleCommandMap($this); - Biome::init(); - $this->craftingManager = CraftingManagerFromDataHelper::make(\pocketmine\RESOURCE_PATH . '/vanilla/recipes.json'); $this->resourceManager = new ResourcePackManager($this->getDataPath() . "resource_packs" . DIRECTORY_SEPARATOR, $this->logger); diff --git a/src/world/World.php b/src/world/World.php index 58b2cddb64..9a4c2522d2 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -64,6 +64,7 @@ use pocketmine\timings\Timings; use pocketmine\utils\Limits; use pocketmine\utils\ReversePriorityQueue; use pocketmine\world\biome\Biome; +use pocketmine\world\biome\BiomeRegistry; use pocketmine\world\format\Chunk; use pocketmine\world\format\io\exception\CorruptedChunkException; use pocketmine\world\format\io\WritableWorldProvider; @@ -1879,7 +1880,7 @@ class World implements ChunkManager{ } public function getBiome(int $x, int $z) : Biome{ - return Biome::getBiome($this->getBiomeId($x, $z)); + return BiomeRegistry::getInstance()->getBiome($this->getBiomeId($x, $z)); } public function setBiomeId(int $x, int $z, int $biomeId) : void{ diff --git a/src/world/biome/Biome.php b/src/world/biome/Biome.php index c605658366..0c644bf543 100644 --- a/src/world/biome/Biome.php +++ b/src/world/biome/Biome.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace pocketmine\world\biome; use pocketmine\block\Block; -use pocketmine\block\utils\TreeType; use pocketmine\utils\Random; use pocketmine\world\ChunkManager; use pocketmine\world\generator\populator\Populator; @@ -50,12 +49,6 @@ abstract class Biome{ public const MAX_BIOMES = 256; - /** - * @var Biome[]|\SplFixedArray - * @phpstan-var \SplFixedArray - */ - private static $biomes; - /** @var int */ private $id; /** @var bool */ @@ -77,37 +70,6 @@ abstract class Biome{ /** @var float */ protected $temperature = 0.5; - protected static function register(int $id, Biome $biome) : void{ - self::$biomes[$id] = $biome; - $biome->setId($id); - } - - public static function init() : void{ - self::$biomes = new \SplFixedArray(self::MAX_BIOMES); - - self::register(self::OCEAN, new OceanBiome()); - self::register(self::PLAINS, new PlainBiome()); - self::register(self::DESERT, new DesertBiome()); - self::register(self::MOUNTAINS, new MountainsBiome()); - self::register(self::FOREST, new ForestBiome()); - self::register(self::TAIGA, new TaigaBiome()); - self::register(self::SWAMP, new SwampBiome()); - self::register(self::RIVER, new RiverBiome()); - - self::register(self::ICE_PLAINS, new IcePlainsBiome()); - - self::register(self::SMALL_MOUNTAINS, new SmallMountainsBiome()); - - self::register(self::BIRCH_FOREST, new ForestBiome(TreeType::BIRCH())); - } - - public static function getBiome(int $id) : Biome{ - if(self::$biomes[$id] === null){ - self::register($id, new UnknownBiome()); - } - return self::$biomes[$id]; - } - public function clearPopulators() : void{ $this->populators = []; } diff --git a/src/world/generator/GeneratorRegisterTask.php b/src/world/generator/GeneratorRegisterTask.php index e4782eb6c8..31b038791e 100644 --- a/src/world/generator/GeneratorRegisterTask.php +++ b/src/world/generator/GeneratorRegisterTask.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace pocketmine\world\generator; use pocketmine\scheduler\AsyncTask; -use pocketmine\world\biome\Biome; use pocketmine\world\SimpleChunkManager; use pocketmine\world\World; use function igbinary_serialize; @@ -60,7 +59,6 @@ class GeneratorRegisterTask extends AsyncTask{ } public function onRun() : void{ - Biome::init(); $manager = new SimpleChunkManager($this->worldHeight); $this->worker->saveToThreadStore("generation.world{$this->worldId}.manager", $manager); diff --git a/src/world/generator/biome/BiomeSelector.php b/src/world/generator/biome/BiomeSelector.php index 6b53dfaf94..903673e5fc 100644 --- a/src/world/generator/biome/BiomeSelector.php +++ b/src/world/generator/biome/BiomeSelector.php @@ -25,6 +25,7 @@ namespace pocketmine\world\generator\biome; use pocketmine\utils\Random; use pocketmine\world\biome\Biome; +use pocketmine\world\biome\BiomeRegistry; use pocketmine\world\biome\UnknownBiome; use pocketmine\world\generator\noise\Simplex; @@ -55,9 +56,10 @@ abstract class BiomeSelector{ public function recalculate() : void{ $this->map = new \SplFixedArray(64 * 64); + $biomeRegistry = BiomeRegistry::getInstance(); for($i = 0; $i < 64; ++$i){ for($j = 0; $j < 64; ++$j){ - $biome = Biome::getBiome($this->lookup($i / 63, $j / 63)); + $biome = $biomeRegistry->getBiome($this->lookup($i / 63, $j / 63)); if($biome instanceof UnknownBiome){ throw new \RuntimeException("Unknown biome returned by selector with ID " . $biome->getId()); } diff --git a/src/world/generator/hell/Nether.php b/src/world/generator/hell/Nether.php index 4fe82c0014..4c60dcbbba 100644 --- a/src/world/generator/hell/Nether.php +++ b/src/world/generator/hell/Nether.php @@ -25,6 +25,7 @@ namespace pocketmine\world\generator\hell; use pocketmine\block\VanillaBlocks; use pocketmine\world\biome\Biome; +use pocketmine\world\biome\BiomeRegistry; use pocketmine\world\ChunkManager; use pocketmine\world\generator\Generator; use pocketmine\world\generator\InvalidGeneratorOptionsException; @@ -84,9 +85,7 @@ class Nether extends Generator{ for($x = 0; $x < 16; ++$x){ for($z = 0; $z < 16; ++$z){ - - $biome = Biome::getBiome(Biome::HELL); - $chunk->setBiomeId($x, $z, $biome->getId()); + $chunk->setBiomeId($x, $z, Biome::HELL); for($y = 0; $y < 128; ++$y){ if($y === 0 or $y === 127){ @@ -117,7 +116,7 @@ class Nether extends Generator{ } $chunk = $world->getChunk($chunkX, $chunkZ); - $biome = Biome::getBiome($chunk->getBiomeId(7, 7)); + $biome = BiomeRegistry::getInstance()->getBiome($chunk->getBiomeId(7, 7)); $biome->populateChunk($world, $chunkX, $chunkZ, $this->random); } } diff --git a/src/world/generator/normal/Normal.php b/src/world/generator/normal/Normal.php index d677d3eed5..5c814bcf6f 100644 --- a/src/world/generator/normal/Normal.php +++ b/src/world/generator/normal/Normal.php @@ -25,6 +25,7 @@ namespace pocketmine\world\generator\normal; use pocketmine\block\VanillaBlocks; use pocketmine\world\biome\Biome; +use pocketmine\world\biome\BiomeRegistry; use pocketmine\world\ChunkManager; use pocketmine\world\generator\biome\BiomeSelector; use pocketmine\world\generator\Gaussian; @@ -227,7 +228,7 @@ class Normal extends Generator{ } $chunk = $world->getChunk($chunkX, $chunkZ); - $biome = Biome::getBiome($chunk->getBiomeId(7, 7)); + $biome = BiomeRegistry::getInstance()->getBiome($chunk->getBiomeId(7, 7)); $biome->populateChunk($world, $chunkX, $chunkZ, $this->random); } } diff --git a/src/world/generator/populator/GroundCover.php b/src/world/generator/populator/GroundCover.php index 98bb73faec..718f2cd39d 100644 --- a/src/world/generator/populator/GroundCover.php +++ b/src/world/generator/populator/GroundCover.php @@ -27,7 +27,7 @@ use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; use pocketmine\block\Liquid; use pocketmine\utils\Random; -use pocketmine\world\biome\Biome; +use pocketmine\world\biome\BiomeRegistry; use pocketmine\world\ChunkManager; use function count; use function min; @@ -37,9 +37,10 @@ class GroundCover extends Populator{ public function populate(ChunkManager $world, int $chunkX, int $chunkZ, Random $random) : void{ $chunk = $world->getChunk($chunkX, $chunkZ); $factory = BlockFactory::getInstance(); + $biomeRegistry = BiomeRegistry::getInstance(); for($x = 0; $x < 16; ++$x){ for($z = 0; $z < 16; ++$z){ - $biome = Biome::getBiome($chunk->getBiomeId($x, $z)); + $biome = $biomeRegistry->getBiome($chunk->getBiomeId($x, $z)); $cover = $biome->getGroundCover(); if(count($cover) > 0){ $diffY = 0;