Biome: Added UnknownBiome class to avoid astonishing behaviour on unknown biomes

This commit is contained in:
Dylan K. Taylor 2018-06-08 10:09:03 +01:00
parent 8c6161a4f2
commit 4e3e807741
2 changed files with 38 additions and 1 deletions

View File

@ -107,7 +107,10 @@ abstract class Biome{
* @return Biome
*/
public static function getBiome(int $id) : Biome{
return self::$biomes[$id] ?? self::$biomes[self::OCEAN];
if(self::$biomes[$id] === null){
self::register($id, new UnknownBiome());
}
return self::$biomes[$id];
}
public function clearPopulators(){

View File

@ -0,0 +1,34 @@
<?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\biome;
/**
* Polyfill class for biomes that are unknown to PocketMine-MP
*/
class UnknownBiome extends Biome{
public function getName() : string{
return "Unknown";
}
}