bounds for pmflevel methods, random block ticking ported from 0.1.3 core, player height was decreased a bit

This commit is contained in:
GameHerobrine 2023-06-23 07:41:04 +03:00
parent 84dd0b82b3
commit 3dd9e38a37
22 changed files with 326 additions and 216 deletions

View file

@ -20,56 +20,48 @@ class DirtBlock extends SolidBlock{
}
return false;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 3) == 0){
$up = $this->getSide(1);
if(($up->isTransparent === false) or ($up->isLiquid) or ($up->getID() == 60)) return false;
if($this->getGrassInRadius()){
$this->level->setBlock($this, BlockAPI::get(GRASS, 0), true, false, true);
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(0, 3) == 0){
$up = $level->getBlockWithoutVector($x, $y + 1, $z, false); //$this->getSide(1);
if(($up->isTransparent === false) or ($up->isLiquid) or ($up->getID() == 60)) return false;
if(self::getGrassInRadius($level, $x, $y, $z)){
$level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(GRASS), true, false, true);
}
}
return BLOCK_UPDATE_RANDOM;
}
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;
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;
public static function getGrassInRadius(Level $level, $x, $y, $z){ //umwut (although kinda faster than for loop =D)
if($level->level->getBlockID($x+1, $y, $z+1) == 2) return true;
if($level->level->getBlockID($x+1, $y, $z) == 2) return true;
if($level->level->getBlockID($x+1, $y, $z-1) == 2) return true;
if($level->level->getBlockID($x, $y, $z+1) == 2) return true;
if($level->level->getBlockID($x, $y, $z-1) == 2) return true;
if($level->level->getBlockID($x-1, $y, $z+1) == 2) return true;
if($level->level->getBlockID($x-1, $y, $z) == 2) return true;
if($level->level->getBlockID($x-1, $y, $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;
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;
if($level->level->getBlockID($x+1, $y-1, $z+1) == 2) return true;
if($level->level->getBlockID($x+1, $y-1, $z) == 2) return true;
if($level->level->getBlockID($x+1, $y-1, $z-1) == 2) return true;
if($level->level->getBlockID($x, $y-1, $z+1) == 2) return true;
if($level->level->getBlockID($x, $y-1, $z) == 2) return true;
if($level->level->getBlockID($x, $y-1, $z-1) == 2) return true;
if($level->level->getBlockID($x-1, $y-1, $z+1) == 2) return true;
if($level->level->getBlockID($x-1, $y-1, $z) == 2) return true;
if($level->level->getBlockID($x-1, $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;
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;
if($level->level->getBlockID($x+1, $y+1, $z+1) == 2) return true;
if($level->level->getBlockID($x+1, $y+1, $z) == 2) return true;
if($level->level->getBlockID($x+1, $y+1, $z-1) == 2) return true;
if($level->level->getBlockID($x, $y+1, $z+1) == 2) return true;
if($level->level->getBlockID($x, $y+1, $z-1) == 2) return true;
if($level->level->getBlockID($x-1, $y+1, $z+1) == 2) return true;
if($level->level->getBlockID($x-1, $y+1, $z) == 2) return true;
if($level->level->getBlockID($x-1, $y+1, $z-1) == 2) return true;
return false;
}