From 1272932257e5c002f3d7240a4a80a0c0f0e25224 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sun, 4 Jan 2026 10:54:03 +0300 Subject: [PATCH] ported leaf decay logic from b1.7.3 --- src/entity/Projectile.php | 2 +- src/material/block/solid/LeavesBlock.php | 74 +++++++++++++++++++----- src/material/block/solid/WoodBlock.php | 6 +- 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/src/entity/Projectile.php b/src/entity/Projectile.php index b6a916b1..444edd73 100644 --- a/src/entity/Projectile.php +++ b/src/entity/Projectile.php @@ -77,7 +77,7 @@ abstract class Projectile extends Entity{ $this->lastSpeedY = $this->speedY; $this->lastSpeedZ = $this->speedZ; $this->needsUpdate = true; - $this->handleWaterMovement(); //TODO: maybe just call parent::update(); ? + $this->handleWaterMovement(); if($this->fire > 0){ if(!$this->isImmuneToFire){ if(($this->fire % 20) == 0){ diff --git a/src/material/block/solid/LeavesBlock.php b/src/material/block/solid/LeavesBlock.php index ee2e6a59..5129752b 100644 --- a/src/material/block/solid/LeavesBlock.php +++ b/src/material/block/solid/LeavesBlock.php @@ -27,6 +27,9 @@ class LeavesBlock extends TransparentBlock{ public static function createIndex($x, $y, $z){ return "$x.$y.$z"; } + /** + * @deprecated leaf decay was rewritten + */ 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])){ @@ -49,37 +52,76 @@ class LeavesBlock extends TransparentBlock{ return ($visited[$index] = false); } + private static $treeBlocksNearby = null; 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); + //TODO MCPE uses 0x04 for detecting updates + if(($meta & 0b1100) == 0b1000){ + if(self::$treeBlocksNearby == null) self::$treeBlocksNearby = array_fill(0, 32*32*32, 0); + for ($xx = - 4; $xx <= 4; $xx ++) { + for ($yy = - 4; $yy <= 4; $yy ++) { + for ($zz = - 4; $zz <= 4; $zz ++) { + $k3 = $level->level->getBlockID($x + $xx, $y + $yy, $z + $zz); + if ($k3 == TRUNK) { + self::$treeBlocksNearby[($xx + 16) * 1024 + ($yy + 16) * 32 + ($zz + 16)] = 0; + } else if ($k3 == LEAVES) { + self::$treeBlocksNearby[($xx + 16) * 1024 + ($yy + 16) * 32 + ($zz + 16)] = - 2; + } else { + self::$treeBlocksNearby[($xx + 16) * 1024 + ($yy + 16) * 32 + ($zz + 16)] = - 1; + } + } + } + } + + for ($i2 = 1; $i2 <= 4; $i2 ++) { + for ($l2 = - 4; $l2 <= 4; $l2 ++) { + for ($j3 = - 4; $j3 <= 4; $j3 ++) { + for ($l3 = - 4; $l3 <= 4; $l3 ++) { + if (self::$treeBlocksNearby[($l2 + 16) * 1024 + ($j3 + 16) * 32 + ($l3 + 16)] != $i2 - 1) continue; + if (self::$treeBlocksNearby[(($l2 + 16) - 1) * 1024 + ($j3 + 16) * 32 + ($l3 + 16)] == - 2) { + self::$treeBlocksNearby[(($l2 + 16) - 1) * 1024 + ($j3 + 16) * 32 + ($l3 + 16)] = $i2; + } + if (self::$treeBlocksNearby[($l2 + 16 + 1) * 1024 + ($j3 + 16) * 32 + ($l3 + 16)] == - 2) { + self::$treeBlocksNearby[($l2 + 16 + 1) * 1024 + ($j3 + 16) * 32 + ($l3 + 16)] = $i2; + } + if (self::$treeBlocksNearby[($l2 + 16) * 1024 + (($j3 + 16) - 1) * 32 + ($l3 + 16)] == - 2) { + self::$treeBlocksNearby[($l2 + 16) * 1024 + (($j3 + 16) - 1) * 32 + ($l3 + 16)] = $i2; + } + if (self::$treeBlocksNearby[($l2 + 16) * 1024 + ($j3 + 16 + 1) * 32 + ($l3 + 16)] == - 2) { + self::$treeBlocksNearby[($l2 + 16) * 1024 + ($j3 + 16 + 1) * 32 + ($l3 + 16)] = $i2; + } + if (self::$treeBlocksNearby[($l2 + 16) * 1024 + ($j3 + 16) * 32 + (($l3 + 16) - 1)] == - 2) { + self::$treeBlocksNearby[($l2 + 16) * 1024 + ($j3 + 16) * 32 + (($l3 + 16) - 1)] = $i2; + } + if (self::$treeBlocksNearby[($l2 + 16) * 1024 + ($j3 + 16) * 32 + ($l3 + 16 + 1)] == - 2) { + self::$treeBlocksNearby[($l2 + 16) * 1024 + ($j3 + 16) * 32 + ($l3 + 16 + 1)] = $i2; + } + } + } + } + } + $j2 = self::$treeBlocksNearby[(32/2) * (32*32) + (32/2) * 32 + (32/2)]; + if($j2 >= 0) + { + $level->level->setBlockDamage($x, $y, $z, $meta & 0xf7); + } else + { 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)); } - }else{ - $level->fastSetBlockUpdate($x, $y, $z, $id, $meta); + $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true, false); } } } - public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ - [$id, $meta] = $level->level->getBlock($x, $y, $z); - if(($meta & 0b00001100) === 0){ - $meta |= 0x08; - $level->fastSetBlockUpdate($x, $y, $z, $id, $meta); //TODO maybe use $level->level->setBlock directly, the client doesnt need to know thism info. - } - } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - $this->meta |= 0x04; + //TODO MCPE uses 0x08 for detecting was it placed by player or not + if($player instanceof Player && $player != PlayerNull::$INSTANCE) $this->meta |= 0x04; $this->level->setBlock($this, $this, true, false, true); } diff --git a/src/material/block/solid/WoodBlock.php b/src/material/block/solid/WoodBlock.php index c9d2fafa..4b688228 100644 --- a/src/material/block/solid/WoodBlock.php +++ b/src/material/block/solid/WoodBlock.php @@ -41,12 +41,12 @@ class WoodBlock extends SolidBlock{ for($xOff = -4; $xOff <= 4; ++$xOff){ for($yOff = -4; $yOff <= 4; ++$yOff){ for($zOff = -4; $zOff <= 4; ++$zOff){ - $b = $player->level->level->getBlock($this->x + $xOff, $this->y + $yOff, $this->z + $zOff); + $b = $this->level->level->getBlock($this->x + $xOff, $this->y + $yOff, $this->z + $zOff); $id = $b[0]; $meta = $b[1]; if($id === LEAVES){ - if(($meta & 0x8) === 0){ - $player->level->fastSetBlockUpdate($this->x + $xOff, $this->y + $yOff, $this->z + $zOff, $id, $meta | 8); + if(($meta & 8) == 0){//TODO MCPE uses 0x04 for detecting updates + $b = $this->level->level->setBlockDamage($this->x + $xOff, $this->y + $yOff, $this->z + $zOff, $meta | 8); } } }