diff --git a/src/material/block/solid/Dirt.php b/src/material/block/solid/Dirt.php index 72f4a667..2b93c7c2 100644 --- a/src/material/block/solid/Dirt.php +++ b/src/material/block/solid/Dirt.php @@ -42,7 +42,7 @@ class DirtBlock extends SolidBlock{ if($type === BLOCK_UPDATE_RANDOM){ if(mt_rand(0, 3) == 0){ if($this->getSide(1)->isTransparent === false) return false; - if($this->getRadiusGrass() > 0){ + if($this->getGrassInRadius() == true){ $this->level->setBlock($this, BlockAPI::get(GRASS, 0), true, false, true); return BLOCK_UPDATE_RANDOM; } @@ -51,130 +51,44 @@ class DirtBlock extends SolidBlock{ return false; } - public function getRadiusGrass(){ - $grass = 0; + public function getBlockID($x, $y, $z){ + return $this->level->getBlock(new Vector3($x, $y, $z))->getID(); + } + + public function getGrassInRadius(){ $x = $this->x; $y = $this->y; $z = $this->z; - $x0 = ++$x; - $x2 = --$x; - for($i = 0; $i < 9; ++$i){//x+1 + if($this->getBlockID($x+1, $y, $z+1) == 2) return true; + if($this->getBlockID($x+1, $y, $z) == 2) return true; + if($this->getBlockID($x+1, $y, $z-1) == 2) return true; + if($this->getBlockID($x, $y, $z+1) == 2) return true; + if($this->getBlockID($x, $y, $z-1) == 2) return true; + if($this->getBlockID($x-1, $y, $z+1) == 2) return true; + if($this->getBlockID($x-1, $y, $z) == 2) return true; + if($this->getBlockID($x-1, $y, $z-1) == 2) return true; - if($i < 3){//0,1,2 - $z0 = $z; - $y0 = $y; - for(++$y0;;){ - if($i == 0) ++$z0; - if($i == 2) --$z0; + if($this->getBlockID($x+1, $y-1, $z+1) == 2) return true; + if($this->getBlockID($x+1, $y-1, $z) == 2) return true; + if($this->getBlockID($x+1, $y-1, $z-1) == 2) return true; + if($this->getBlockID($x, $y-1, $z+1) == 2) return true; + if($this->getBlockID($x, $y-1, $z) == 2) return true; + if($this->getBlockID($x, $y-1, $z-1) == 2) return true; + if($this->getBlockID($x-1, $y-1, $z+1) == 2) return true; + if($this->getBlockID($x-1, $y-1, $z) == 2) return true; + if($this->getBlockID($x-1, $y-1, $z-1) == 2) return true; - $b = $this->level->getBlock(new Vector3($x0, $y0, $z0)); - if ($b->getID() === GRASS) ++$grass; - break 1; - } - } - elseif($i > 2 and $i < 6){ - $z1 = $z; - for(;;){ - if($i == 3) ++$z1; - if($i == 5) --$z1; + if($this->getBlockID($x+1, $y+1, $z+1) == 2) return true; + if($this->getBlockID($x+1, $y+1, $z) == 2) return true; + if($this->getBlockID($x+1, $y+1, $z-1) == 2) return true; + if($this->getBlockID($x, $y+1, $z+1) == 2) return true; + if($this->getBlockID($x, $y+1, $z-1) == 2) return true; + if($this->getBlockID($x-1, $y+1, $z+1) == 2) return true; + if($this->getBlockID($x-1, $y+1, $z) == 2) return true; + if($this->getBlockID($x-1, $y+1, $z-1) == 2) return true; - $b = $this->level->getBlock(new Vector3($x0, $y, $z1)); - if ($b->getID() === GRASS) ++$grass; - break 1; - } - } - elseif($i > 5){ - $z2 = $z; - $y2 = $y; - for(--$y2;;){ - if($i == 6) ++$z2; - if($i == 8) --$z2; - - $b = $this->level->getBlock(new Vector3($x0, $y2, $z2)); - if ($b->getID() === GRASS) ++$grass; - break 1; - } - } - } - - for($i = 0; $i < 9; ++$i){//x - - if($i < 3){ - $z0 = $z; - $y0 = $y; - for(++$y0;;){ - if($i == 0) ++$z0; - if($i == 2) --$z0; - - $b = $this->level->getBlock(new Vector3($x, $y0, $z0)); - if ($b->getID() === GRASS) ++$grass; - break 1; - } - } - elseif($i > 2 and $i < 6){ - $z1 = $z; - for(;;){ - if($i == 3) ++$z1; - if($i == 5) --$z1; - - $b = $this->level->getBlock(new Vector3($x, $y, $z1)); - if ($b->getID() === GRASS) ++$grass; - break 1; - } - } - elseif($i > 5){ - $z2 = $z; - $y2 = $y; - for(--$y2;;){ - if($i == 6) ++$z2; - if($i == 8) --$z2; - - $b = $this->level->getBlock(new Vector3($x, $y2, $z2)); - if ($b->getID() === GRASS) ++$grass; - break 1; - } - } - } - - for($i = 0, $x2 = --$x; $i < 9; ++$i){//x-1 - - if($i < 3){ - $z0 = $z; - $y0 = $y; - for(++$y0;;){ - if($i == 0) ++$z0; - if($i == 2) --$z0; - - $b = $this->level->getBlock(new Vector3($x2, $y0, $z0)); - if ($b->getID() === GRASS) ++$grass; - break 1; - } - } - elseif($i > 2 and $i < 6){ - $z1 = $z; - for(;;){ - if($i == 3) ++$z1; - if($i == 5) --$z1; - - $b = $this->level->getBlock(new Vector3($x2, $y, $z1)); - if ($b->getID() === GRASS) ++$grass; - break 1; - } - } - elseif($i > 5){ - $z2 = $z; - $y2 = $y; - for(--$y2;;){ - if($i == 6) ++$z2; - if($i == 8) --$z2; - - $b = $this->level->getBlock(new Vector3($x2, $y2, $z2)); - if ($b->getID() === GRASS) ++$grass; - break 1; - } - } - } - return $grass; + return false; } + } \ No newline at end of file