Relocate biome ID constants to pocketmine\data\bedrock package

This commit is contained in:
Dylan K. Taylor 2020-11-01 16:53:06 +00:00
parent b176f4c12f
commit 4231bfdc7e
7 changed files with 79 additions and 45 deletions

View File

@ -0,0 +1,48 @@
<?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\data\bedrock;
final class BiomeIds{
private function __construct(){
//NOOP
}
public const OCEAN = 0;
public const PLAINS = 1;
public const DESERT = 2;
public const MOUNTAINS = 3;
public const FOREST = 4;
public const TAIGA = 5;
public const SWAMP = 6;
public const RIVER = 7;
public const HELL = 8;
public const ICE_PLAINS = 12;
public const SMALL_MOUNTAINS = 20;
public const BIRCH_FOREST = 27;
}

View File

@ -34,6 +34,7 @@ use pocketmine\block\tile\Spawnable;
use pocketmine\block\tile\Tile;
use pocketmine\block\UnknownBlock;
use pocketmine\block\VanillaBlocks;
use pocketmine\data\bedrock\BiomeIds;
use pocketmine\entity\Entity;
use pocketmine\entity\Location;
use pocketmine\entity\object\ExperienceOrb;
@ -1876,7 +1877,7 @@ class World implements ChunkManager{
if(($chunk = $this->getOrLoadChunk($x >> 4, $z >> 4, false)) !== null){
return $chunk->getBiomeId($x & 0x0f, $z & 0x0f);
}
return Biome::OCEAN; //TODO: this should probably throw instead (terrain not generated yet)
return BiomeIds::OCEAN; //TODO: this should probably throw instead (terrain not generated yet)
}
public function getBiome(int $x, int $z) : Biome{

View File

@ -30,23 +30,6 @@ use pocketmine\world\generator\populator\Populator;
abstract class Biome{
public const OCEAN = 0;
public const PLAINS = 1;
public const DESERT = 2;
public const MOUNTAINS = 3;
public const FOREST = 4;
public const TAIGA = 5;
public const SWAMP = 6;
public const RIVER = 7;
public const HELL = 8;
public const ICE_PLAINS = 12;
public const SMALL_MOUNTAINS = 20;
public const BIRCH_FOREST = 27;
public const MAX_BIOMES = 256;
/** @var int */

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\world\biome;
use pocketmine\block\utils\TreeType;
use pocketmine\data\bedrock\BiomeIds;
use pocketmine\utils\SingletonTrait;
final class BiomeRegistry{
@ -38,20 +39,20 @@ final class BiomeRegistry{
public function __construct(){
$this->biomes = new \SplFixedArray(Biome::MAX_BIOMES);
$this->register(Biome::OCEAN, new OceanBiome());
$this->register(Biome::PLAINS, new PlainBiome());
$this->register(Biome::DESERT, new DesertBiome());
$this->register(Biome::MOUNTAINS, new MountainsBiome());
$this->register(Biome::FOREST, new ForestBiome());
$this->register(Biome::TAIGA, new TaigaBiome());
$this->register(Biome::SWAMP, new SwampBiome());
$this->register(Biome::RIVER, new RiverBiome());
$this->register(BiomeIds::OCEAN, new OceanBiome());
$this->register(BiomeIds::PLAINS, new PlainBiome());
$this->register(BiomeIds::DESERT, new DesertBiome());
$this->register(BiomeIds::MOUNTAINS, new MountainsBiome());
$this->register(BiomeIds::FOREST, new ForestBiome());
$this->register(BiomeIds::TAIGA, new TaigaBiome());
$this->register(BiomeIds::SWAMP, new SwampBiome());
$this->register(BiomeIds::RIVER, new RiverBiome());
$this->register(Biome::ICE_PLAINS, new IcePlainsBiome());
$this->register(BiomeIds::ICE_PLAINS, new IcePlainsBiome());
$this->register(Biome::SMALL_MOUNTAINS, new SmallMountainsBiome());
$this->register(BiomeIds::SMALL_MOUNTAINS, new SmallMountainsBiome());
$this->register(Biome::BIRCH_FOREST, new ForestBiome(TreeType::BIRCH()));
$this->register(BiomeIds::BIRCH_FOREST, new ForestBiome(TreeType::BIRCH()));
}
public function register(int $id, Biome $biome) : void{

View File

@ -29,13 +29,13 @@ namespace pocketmine\world\format;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\tile\Tile;
use pocketmine\block\tile\TileFactory;
use pocketmine\data\bedrock\BiomeIds;
use pocketmine\entity\Entity;
use pocketmine\entity\EntityFactory;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\player\Player;
use pocketmine\world\biome\Biome;
use pocketmine\world\World;
use function array_fill;
use function array_filter;
@ -106,7 +106,7 @@ class Chunk{
$val = ($this->subChunks->getSize() * 16);
$this->heightMap = $heightMap ?? new HeightArray(array_fill(0, 256, $val));
$this->biomeIds = $biomeIds ?? BiomeArray::fill(Biome::OCEAN);
$this->biomeIds = $biomeIds ?? BiomeArray::fill(BiomeIds::OCEAN);
$this->NBTtiles = $tiles;
$this->NBTentities = $entities;

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\world\generator\hell;
use pocketmine\block\VanillaBlocks;
use pocketmine\world\biome\Biome;
use pocketmine\data\bedrock\BiomeIds;
use pocketmine\world\biome\BiomeRegistry;
use pocketmine\world\ChunkManager;
use pocketmine\world\generator\Generator;
@ -85,7 +85,7 @@ class Nether extends Generator{
for($x = 0; $x < 16; ++$x){
for($z = 0; $z < 16; ++$z){
$chunk->setBiomeId($x, $z, Biome::HELL);
$chunk->setBiomeId($x, $z, BiomeIds::HELL);
for($y = 0; $y < 128; ++$y){
if($y === 0 or $y === 127){

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\world\generator\normal;
use pocketmine\block\VanillaBlocks;
use pocketmine\data\bedrock\BiomeIds;
use pocketmine\world\biome\Biome;
use pocketmine\world\biome\BiomeRegistry;
use pocketmine\world\ChunkManager;
@ -74,38 +75,38 @@ class Normal extends Generator{
protected function lookup(float $temperature, float $rainfall) : int{
if($rainfall < 0.25){
if($temperature < 0.7){
return Biome::OCEAN;
return BiomeIds::OCEAN;
}elseif($temperature < 0.85){
return Biome::RIVER;
return BiomeIds::RIVER;
}else{
return Biome::SWAMP;
return BiomeIds::SWAMP;
}
}elseif($rainfall < 0.60){
if($temperature < 0.25){
return Biome::ICE_PLAINS;
return BiomeIds::ICE_PLAINS;
}elseif($temperature < 0.75){
return Biome::PLAINS;
return BiomeIds::PLAINS;
}else{
return Biome::DESERT;
return BiomeIds::DESERT;
}
}elseif($rainfall < 0.80){
if($temperature < 0.25){
return Biome::TAIGA;
return BiomeIds::TAIGA;
}elseif($temperature < 0.75){
return Biome::FOREST;
return BiomeIds::FOREST;
}else{
return Biome::BIRCH_FOREST;
return BiomeIds::BIRCH_FOREST;
}
}else{
//FIXME: This will always cause River to be used since the rainfall is always greater than 0.8 if we
//reached this branch. However I don't think that substituting temperature for rainfall is correct given
//that mountain biomes are supposed to be pretty cold.
if($rainfall < 0.25){
return Biome::MOUNTAINS;
return BiomeIds::MOUNTAINS;
}elseif($rainfall < 0.70){
return Biome::SMALL_MOUNTAINS;
return BiomeIds::SMALL_MOUNTAINS;
}else{
return Biome::RIVER;
return BiomeIds::RIVER;
}
}
}