BiomeArray: added ::fill()

This commit is contained in:
Dylan K. Taylor 2020-10-31 23:22:42 +00:00
parent 05470d0621
commit 59a3e8c096
2 changed files with 7 additions and 2 deletions

View File

@ -25,6 +25,7 @@ namespace pocketmine\world\format;
use function chr;
use function ord;
use function str_repeat;
use function strlen;
final class BiomeArray{
@ -42,6 +43,10 @@ final class BiomeArray{
$this->payload = $payload;
}
public static function fill(int $biomeId) : self{
return new BiomeArray(str_repeat(chr($biomeId), 256));
}
private static function idx(int $x, int $z) : int{
if($x < 0 or $x >= 16 or $z < 0 or $z >= 16){
throw new \InvalidArgumentException("x and z must be in the range 0-15");

View File

@ -35,12 +35,12 @@ 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;
use function array_map;
use function count;
use function str_repeat;
class Chunk{
public const DIRTY_FLAG_TERRAIN = 1 << 0;
@ -106,7 +106,7 @@ class Chunk{
$val = ($this->subChunks->getSize() * 16);
$this->heightMap = $heightMap ?? new HeightArray(array_fill(0, 256, $val));
$this->biomeIds = $biomeIds ?? new BiomeArray(str_repeat("\x00", 256));
$this->biomeIds = $biomeIds ?? BiomeArray::fill(Biome::OCEAN);
$this->NBTtiles = $tiles;
$this->NBTentities = $entities;