22declare(strict_types=1);
35 protected array $chunks = [];
37 public function __construct(
43 if($this->
isInWorld($x, $y, $z) && ($chunk = $this->getChunk($x >>
Chunk::COORD_BIT_SIZE, $z >>
Chunk::COORD_BIT_SIZE)) !== null){
44 return RuntimeBlockStateRegistry::getInstance()->fromStateId($chunk->getBlockStateId($x & Chunk::COORD_MASK, $y, $z & Chunk::COORD_MASK));
46 return VanillaBlocks::AIR();
50 if(($chunk = $this->getChunk($x >>
Chunk::COORD_BIT_SIZE, $z >>
Chunk::COORD_BIT_SIZE)) !== null){
51 $chunk->setBlockStateId($x & Chunk::COORD_MASK, $y, $z & Chunk::COORD_MASK, $block->getStateId());
53 throw new \InvalidArgumentException(
"Cannot set block at coordinates x=$x,y=$y,z=$z, terrain is not loaded or out of bounds");
57 public function getChunk(
int $chunkX,
int $chunkZ) : ?Chunk{
58 return $this->chunks[World::chunkHash($chunkX, $chunkZ)] ?? null;
61 public function setChunk(
int $chunkX,
int $chunkZ, Chunk $chunk) : void{
62 $this->chunks[World::chunkHash($chunkX, $chunkZ)] = $chunk;
65 public function cleanChunks() : void{
77 public function isInWorld(
int $x,
int $y,
int $z) : bool{
80 $y < $this->maxY && $y >= $this->minY &&
isInWorld(int $x, int $y, int $z)
setBlockAt(int $x, int $y, int $z, Block $block)
getBlockAt(int $x, int $y, int $z)