mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
Optimised dirt.php code
This commit is contained in:
parent
292581cf89
commit
6704610a54
1 changed files with 33 additions and 119 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue