First look at 3D biome support

This commit is contained in:
Dylan K. Taylor
2023-01-17 21:41:30 +00:00
parent 3a13f5cf5f
commit 7abfc46567
19 changed files with 319 additions and 243 deletions

View File

@ -2241,23 +2241,23 @@ class World implements ChunkManager{
return ($chunk = $this->loadChunk($x >> Chunk::COORD_BIT_SIZE, $z >> Chunk::COORD_BIT_SIZE)) !== null ? $chunk->getTile($x & Chunk::COORD_MASK, $y, $z & Chunk::COORD_MASK) : null;
}
public function getBiomeId(int $x, int $z) : int{
public function getBiomeId(int $x, int $y, int $z) : int{
if(($chunk = $this->loadChunk($x >> Chunk::COORD_BIT_SIZE, $z >> Chunk::COORD_BIT_SIZE)) !== null){
return $chunk->getBiomeId($x & Chunk::COORD_MASK, $z & Chunk::COORD_MASK);
return $chunk->getBiomeId($x & Chunk::COORD_MASK, $y & Chunk::COORD_MASK, $z & Chunk::COORD_MASK);
}
return BiomeIds::OCEAN; //TODO: this should probably throw instead (terrain not generated yet)
}
public function getBiome(int $x, int $z) : Biome{
return BiomeRegistry::getInstance()->getBiome($this->getBiomeId($x, $z));
public function getBiome(int $x, int $y, int $z) : Biome{
return BiomeRegistry::getInstance()->getBiome($this->getBiomeId($x, $y, $z));
}
public function setBiomeId(int $x, int $z, int $biomeId) : void{
public function setBiomeId(int $x, int $y, int $z, int $biomeId) : void{
$chunkX = $x >> Chunk::COORD_BIT_SIZE;
$chunkZ = $z >> Chunk::COORD_BIT_SIZE;
$this->unlockChunk($chunkX, $chunkZ, null);
if(($chunk = $this->loadChunk($chunkX, $chunkZ)) !== null){
$chunk->setBiomeId($x & Chunk::COORD_MASK, $z & Chunk::COORD_MASK, $biomeId);
$chunk->setBiomeId($x & Chunk::COORD_MASK, $y & Chunk::COORD_MASK, $z & Chunk::COORD_MASK, $biomeId);
}else{
//if we allowed this, the modifications would be lost when the chunk is created
throw new WorldException("Cannot set biome in a non-generated chunk");