trunkHeight + 3; ++$yy) { if ($yy == 1 or $yy === $this->trunkHeight) { ++$radiusToCheck; } for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){ for($zz = -$radiusToCheck; $zz < ($radiusToCheck + 1); ++$zz){ $block = $level->getBlock(new Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz)); if(!isset($this->overridable[$block->getID()])){ return false; } } } } return true; } public function placeObject(Level $level, Vector3 $pos, Random $random){ // The base dirt block $dirtpos = new Vector3( $pos->x, $pos->y -1, $pos->z ); $level->setBlock( $dirtpos, new DirtBlock() ); // Adjust the tree trunk's height randomly // plot [-14:11] int( x / 8 ) + 5 // - min=4 (all leaves are 4 tall, some trunk must show) // - max=6 (top leaves are within ground-level whacking range // on all small trees) $heightPre = $random->nextRange(-14, 11); $this->trunkHeight = intval( $heightPre / 8 ) + 5; // Adjust the starting leaf density using the trunk height as a // starting position (tall trees with skimpy leaves don't look // too good) $leafPre = $random->nextRange($this->trunkHeight, 10) / 20; // (TODO: seed may apply) // Now build the tree (from the top down) $leaflevel = 0; for( $yy = ($this->trunkHeight + 1); $yy >= 0; --$yy ) { if( $leaflevel < self::$leavesHeight ) { // The size is a slight variation on the trunkheight $radius = self::$leafRadii[ $leaflevel ] + $leafPre; $bRadius = 3; for( $xx = -$bRadius; $xx <= $bRadius; ++ $xx ) { for( $zz = -$bRadius; $zz <= $bRadius; ++ $zz ) { if( sqrt(($xx * $xx) + ($zz * $zz)) <= $radius ) { $leafpos = new Vector3( $pos->x + $xx, $pos->y + $yy, $pos->z + $zz ); $level->setBlock( $leafpos, new LeavesBlock( $this->type ) ); } } } $leaflevel ++; } // Place the trunk last if( $leaflevel > 1 ) { $trunkpos = new Vector3( $pos->x, $pos->y + $yy, $pos->z ); $level->setBlock( $trunkpos, new WoodBlock( $this->type ) ); } } } }