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;
}

View file

@ -46,12 +46,10 @@ class GrassBlock extends SolidBlock{
}
return;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_RANDOM && !$this->getSide(1)->isTransparent && mt_rand(0, 2) == 1){
$this->level->setBlock($this, BlockAPI::get(DIRT, 0), true, false, true);
public static function onRandomTick(Level $level, $x, $y, $z){
if(!$level->getBlockWithoutVector($x, $y + 1, $z, false)->isTransparent && mt_rand(0, 2) == 1){
$level->fastSetBlockUpdate($x, $y, $z, DIRT, 0);
}
return BLOCK_UPDATE_RANDOM;
}
}

View file

@ -41,7 +41,7 @@ class IceBlock extends TransparentBlock{
}
}
public function onUpdate($type){ /*Taken from https://github.com/PocketMine/PocketMine-MP/issues/3249*/
if($type === BLOCK_UPDATE_RANDOM){
/*if($type === BLOCK_UPDATE_RANDOM){
$light = $this->scanForNearbyLightSources(3,3,3);
if(LightUtils::getLightValueFromNearbySource($light,$this) > 12){
$this->level->setBlock($this, new WaterBlock(), true);
@ -49,7 +49,7 @@ class IceBlock extends TransparentBlock{
}
return BLOCK_UPDATE_RANDOM;
}
return false;
return false;*/ //TODO i dont want it now
}
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){

View file

@ -15,53 +15,55 @@ class LeavesBlock extends TransparentBlock{
$this->name = $names[$this->meta & 0x03];
$this->hardness = 1;
}
private function createIndex($x, $y, $z){
return $index = $x.".".$y.".".$z;
public static function createIndex($x, $y, $z){
return $x.".".$y.".".$z;
}
private function findLog(Block $pos, array $visited, $distance){ //port from newest pocketmine
$index = $this->createIndex($pos->x, $pos->y, $pos->z);
public static function findLog(Level $level, $x, $y, $z, array $visited, $distance){ //port from newest pocketmine
$index = self::createIndex($x, $y, $z);
if(isset($visited[$index])){
return false;
}
$visited[$index] = true;
$block = $this->level->getBlock($pos);
$block = $level->getBlockWithoutVector($x, $y, $z, false);
if($block instanceof WoodBlock){ //type doesn't matter
return true;
}
if($block->getId() === $this->getId() && $distance <= 4){
foreach(array(2,3,4,5) as $side){
if($this->findLog($pos->getSide($side), $visited, $distance + 1)){ //recursion i guess?
return true;
}
}
if($block->getId() === LEAVES && $distance <= 4){
if(self::findLog($level, $x - 1, $y, $z, $visited, $distance + 1)) return true;
if(self::findLog($level, $x + 1, $y, $z, $visited, $distance + 1)) return true;
if(self::findLog($level, $x, $y, $z - 1, $visited, $distance + 1)) return true;
if(self::findLog($level, $x, $y, $z + 1, $visited, $distance + 1)) return true;
}
return false;
}
public static function onRandomTick(Level $level, $x, $y, $z){
$b = $level->level->getBlock($x, $y, $z);
$id = $b[0];
$meta = $b[1];
if(($meta & 0b00001100) === 0x08){
$meta &= 0x03;
$visited = array();
if(!self::findLog($level, $x, $y, $z, $visited, 0)){
//$this->level->setBlock($this, new AirBlock(), false, false, true);
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
if(mt_rand(1,20) === 1){ //Saplings
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(SAPLING, $meta & 0x03, 1));
}
if(($meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(APPLE, 0, 1));
}
return BLOCK_UPDATE_NORMAL;
}
}
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if(($this->meta & 0b00001100) === 0){
$this->meta |= 0x08;
$this->level->setBlock($this, $this, false, false, true);
return BLOCK_UPDATE_RANDOM;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
if(($this->meta & 0b00001100) === 0x08){
$this->meta &= 0x03;
$visited = array();
$check = 0;
if($this->findLog($this, $visited, 0) !== true){
$this->level->setBlock($this, new AirBlock(), false, false, true);
if(mt_rand(1,20) === 1){ //Saplings
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SAPLING, $this->meta & 0x03, 1));
}
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(APPLE, 0, 1));
}
return BLOCK_UPDATE_NORMAL;
}
}
}
return false;