22declare(strict_types=1);
32 private array $blocks = [];
38 private array $validators = [];
40 public function __construct(
private ChunkManager $world){
52 return $this->
addBlockAt($pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ(), $state);
61 $this->blocks[$x][$y][$z] = $state;
70 return $this->fetchBlockAt($pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ());
77 return $this->blocks[$x][$y][$z] ?? $this->world->getBlockAt($x, $y, $z);
87 foreach($this->getBlocks() as [$x, $y, $z, $_]){
88 foreach($this->validators as $validator){
89 if(!$validator($this->world, $x, $y, $z)){
95 foreach($this->getBlocks() as [$x, $y, $z, $block]){
96 $oldBlock = $this->world->getBlockAt($x, $y, $z);
97 if(!$oldBlock->isSameState($block)){
98 $this->world->setBlockAt($x, $y, $z, $block);
102 return $changedBlocks !== 0;
110 foreach($this->blocks as $x => $yLine){
111 foreach($yLine as $y => $zLine){
112 foreach($zLine as $z => $block){
113 yield [$x, $y, $z, $block];
127 Utils::validateCallableSignature([$this,
'dummyValidator'], $validator);
128 $this->validators[] = $validator;
addBlock(Vector3 $pos, Block $state)
addBlockAt(int $x, int $y, int $z, Block $state)
dummyValidator(ChunkManager $world, int $x, int $y, int $z)
addValidator(\Closure $validator)
fetchBlockAt(int $x, int $y, int $z)
isInWorld(int $x, int $y, int $z)