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

@ -9,6 +9,13 @@ class FireBlock extends FlowableBlock implements LightingBlock{
$this->hardness = 0;
}
public static function onRandomTick(Level $level, $x, $y, $z){
console("Fire tick at $x $y $z");
if($level->level->getBlockID($x, $y - 1, $z) !== NETHERRACK){
$level->setBlock(new Position($x, $y, $z, $level), new AirBlock(), true, false, true);
}
}
public function getDrops(Item $item, Player $player){
return array();
}
@ -25,11 +32,6 @@ class FireBlock extends FlowableBlock implements LightingBlock{
}
$this->level->setBlock($this, new AirBlock(), true, false, true);
return BLOCK_UPDATE_NORMAL;
}elseif($type === BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== NETHERRACK){
$this->level->setBlock($this, new AirBlock(), true, false, true);
return BLOCK_UPDATE_NORMAL;
}
}
return false;
}

View file

@ -15,6 +15,37 @@ class FarmlandBlock extends TransparentBlock{
$b = $this->getSide(1);
return $b->isTransparent && $b->id != 0;
}
public static function onRandomTick(Level $level, $x, $y, $z){
$meta = $level->level->getBlockDamage($x, $y, $z);
$b = $level->getBlockWithoutVector($x, $y + 1, $z, $level, false);
if($meta === 0 && mt_rand(0, 5) === 0){
$water = self::checkWaterStatic($level, $x, $y, $z);
if($water){
$level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(FARMLAND, 1), true, false, true);
}elseif(!(($b instanceof Block) && $b->isTransparent && $b->id != 0)){
$level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(DIRT, 0), true, false, true);
}
}
if($b instanceof Block && !$b->isFlowable){
$level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(DIRT, 0), true, false, true);
}
}
public static function checkWaterStatic(Level $level, $x, $y, $z){
for($bx = $x - 4; $bx <= $x + 4; $bx++){
for($by = $y; $by <= $y + 1; $by++){
for($bz = $z - 4; $bz <= $z + 4; $bz++){
$id = $level->level->getBlockID($bx, $by, $bz);
if($id === 8 || $id === 9){
return true;
}
}
}
}
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if(!$this->getSide(1)->isTransparent){
@ -22,26 +53,12 @@ class FarmlandBlock extends TransparentBlock{
return $type;
}
}
if($type === BLOCK_UPDATE_RANDOM){
if($this->meta === 0 && mt_rand(0,5) == 0){
$water = $this->checkWater();
if($water){
$this->level->setBlock($this, BlockAPI::get(FARMLAND, 1), true, false, true);
}elseif(!$this->hasCrops()){
$this->level->setBlock($this, BlockAPI::get(DIRT, 0), true, false, true);
}
}
if(!$this->getSide(1)->isFlowable){
$this->level->setBlock($this, BlockAPI::get(DIRT, 0), true, false, true);
}
return $type;
}
return false;
}
public function getBlockID($x, $y, $z){
return $this->level->level->getBlockID($x, $y, $z); //PMFLevel method
}
}
public function checkWater(){

View file

@ -5,13 +5,13 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{
parent::__construct(GLOWING_REDSTONE_ORE, 0, "Glowing Redstone Ore");
$this->hardness = 15;
}
public static function onRandomTick(Level $level, $x, $y, $z){
$level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(REDSTONE_ORE, $level->level->getBlockDamage($x, $y, $z)), false, false, true);
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_SCHEDULED or $type === BLOCK_UPDATE_RANDOM){
if($type === BLOCK_UPDATE_SCHEDULED){
$this->level->setBlock($this, BlockAPI::get(REDSTONE_ORE, $this->meta), false, false, true);
return BLOCK_UPDATE_WEAK;
}else{
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
}
return false;
}

View file

@ -16,7 +16,14 @@ class BeetrootBlock extends FlowableBlock{
}
return false;
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(0, 2) == 1){
$b = $level->level->getBlock($x, $y, $z);
if($b[1] < 0x07){
$level->fastSetBlockUpdate($x, $y, $z, $b[0], $b[1] + 1);
}
}
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
$this->meta += mt_rand(0, 3) + 2;
@ -39,16 +46,6 @@ class BeetrootBlock extends FlowableBlock{
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
}
}else{
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}

View file

@ -7,6 +7,30 @@ class CactusBlock extends TransparentBlock{
$this->hardness = 2;
}
public static function onRandomTick(Level $level, $x, $y, $z){
//$b = $level->level->getBlock($x, $y - 1, $z);
$underID = $level->level->getBlockID($x, $y - 1, $z);
$b = $level->level->getBlock($x, $y, $z);
$id = $b[0];
$meta = $b[1];
if($underID !== CACTUS){
if($meta == 0x0F){
for($yy = 1; $yy < 3; ++$yy){
$bID = $level->level->getBlockID($x, $y + $yy, $z);
if($bID === AIR){
$level->setBlock(new Position($x, $y, $z, $level), new CactusBlock(), true, false, true);
break;
}
}
$meta = 0;
$level->fastSetBlockUpdate($x, $y, $z, $id, $meta);
}else{
$level->fastSetBlockUpdate($x, $y, $z, $id, $meta + 1);
}
return BLOCK_UPDATE_RANDOM;
}
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0);
@ -19,24 +43,6 @@ class CactusBlock extends TransparentBlock{
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem($this->id));
return BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== CACTUS){
if($this->meta == 0x0F){
for($y = 1; $y < 3; ++$y){
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
if($b->getID() === AIR){
$this->level->setBlock($b, new CactusBlock(), true, false, true);
break;
}
}
$this->meta = 0;
$this->level->setBlock($this, $this, false);
}else{
++$this->meta;
$this->level->setBlock($this, $this, false);
}
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}

View file

@ -31,7 +31,16 @@ class CarrotBlock extends FlowableBlock{
}
return false;
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(0, 2) == 1){
$block = $level->level->getBlock($x, $y, $z);
if($block[1] < 0x07){
//++$this->meta;
//$this->level->setBlock($this, $this, true, false, true);
$level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1);
}
}
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() != 60){
@ -39,16 +48,6 @@ class CarrotBlock extends FlowableBlock{
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
}
}else{
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}

View file

@ -15,7 +15,34 @@ class MelonStemBlock extends FlowableBlock{
}
return false;
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(0, 2) == 1){
$block = $level->level->getBlock($x, $y, $z);
if($block[1] < 0x07){
//++$this->meta;
//$this->level->setBlock($this, $this, true, false, true);
$level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1);
}else{
$position = new AirBlock(); //feke block
$position->x = $x;
$position->y = $y;
$position->z = $z;
$position->level = $level;
for($side = 2; $side <= 5; ++$side){
$b = $position->getSide($side);
if($b->getID() === MELON_BLOCK){
return;
}
}
$side = $position->getSide(mt_rand(2,5));
$d = $side->getSide(0);
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){
$level->setBlock($side, new MelonBlock(), true, false, true);
}
}
}
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() != 60){
@ -23,27 +50,6 @@ class MelonStemBlock extends FlowableBlock{
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
}else{
for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side);
if($b->getID() === MELON_BLOCK){
return BLOCK_UPDATE_RANDOM;
}
}
$side = $this->getSide(mt_rand(2,5));
$d = $side->getSide(0);
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){
$this->level->setBlock($side, new MelonBlock(), true, false, true);
}
}
}
return BLOCK_UPDATE_RANDOM;
}
return false;
}

View file

@ -16,7 +16,16 @@ class PotatoBlock extends FlowableBlock{
}
return false;
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(0, 2) == 1){
$block = $level->level->getBlock($x, $y, $z);
if($block[1] < 0x07){
//++$this->meta;
//$this->level->setBlock($this, $this, true, false, true);
$level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1);
}
}
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
$this->meta += mt_rand(0, 3) + 2;
@ -39,16 +48,6 @@ class PotatoBlock extends FlowableBlock{
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
}
}else{
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}

View file

@ -15,7 +15,34 @@ class PumpkinStemBlock extends FlowableBlock{
}
return false;
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(0, 2) == 1){
$block = $level->level->getBlock($x, $y, $z);
if($block[1] < 0x07){
//++$this->meta;
//$this->level->setBlock($this, $this, true, false, true);
$level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1);
}else{
$position = new AirBlock(); //feke block
$position->x = $x;
$position->y = $y;
$position->z = $z;
$position->level = $level;
for($side = 2; $side <= 5; ++$side){
$b = $position->getSide($side);
if($b->getID() === PUMPKIN){
return;
}
}
$side = $position->getSide(mt_rand(2,5));
$d = $side->getSide(0);
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){
$level->setBlock($side, new PumpkinBlock(), true, false, true);
}
}
}
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() != 60){

View file

@ -55,27 +55,30 @@ class SugarcaneBlock extends FlowableBlock{
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== SUGARCANE_BLOCK){
if($this->meta === 0x0F){
for($y = 1; $y < 3; ++$y){
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
if($b->getID() === AIR){
$this->level->setBlock($b, new SugarcaneBlock(), true, false, true);
}
}
$this->meta = 0;
$this->level->setBlock($this, $this, true, false, true);
}else{
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
}
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}
public static function onRandomTick(Level $level, $x, $y, $z){
$underID = $level->level->getBlockID($x, $y - 1, $z);
$b = $level->level->getBlock($x, $y, $z);
$id = $b[0];
$meta = $b[1];
if($underID !== SUGARCANE_BLOCK){
if($meta == 0x0F){
for($yy = 1; $yy < 3; ++$yy){
$bID = $level->level->getBlockID($x, $y + $yy, $z);
if($bID === AIR){
$level->setBlock(new Position($x, $y, $z, $level), new SugarcaneBlock(), true, false, true);
}
}
$meta = 0;
$level->fastSetBlockUpdate($x, $y, $z, $id, $meta);
}else{
$level->fastSetBlockUpdate($x, $y, $z, $id, $meta + 1);
}
return BLOCK_UPDATE_RANDOM;
}
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === SUGARCANE_BLOCK){

View file

@ -31,7 +31,16 @@ class WheatBlock extends FlowableBlock{
}
return false;
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(0, 2) == 1){
$block = $level->level->getBlock($x, $y, $z);
if($block[1] < 0x07){
//++$this->meta;
//$this->level->setBlock($this, $this, true, false, true);
$level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1);
}
}
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() != 60){
@ -40,17 +49,6 @@ class WheatBlock extends FlowableBlock{
return BLOCK_UPDATE_NORMAL;
}
}
elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
}
}else{
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}

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;