PocketMine-MP 5.18.2 git-00e39821f06a4b6d728d35053c2621dbb19369ff
SpruceTree.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\world\generator\object;
25
30use function abs;
31
32class SpruceTree extends Tree{
33
34 public function __construct(){
35 parent::__construct(VanillaBlocks::SPRUCE_LOG(), VanillaBlocks::SPRUCE_LEAVES(), 10);
36 }
37
38 protected function generateTrunkHeight(Random $random) : int{
39 return $this->treeHeight - $random->nextBoundedInt(3);
40 }
41
42 public function getBlockTransaction(ChunkManager $world, int $x, int $y, int $z, Random $random) : ?BlockTransaction{
43 $this->treeHeight = $random->nextBoundedInt(4) + 6;
44 return parent::getBlockTransaction($world, $x, $y, $z, $random);
45 }
46
47 protected function placeCanopy(int $x, int $y, int $z, Random $random, BlockTransaction $transaction) : void{
48 $topSize = $this->treeHeight - (1 + $random->nextBoundedInt(2));
49 $lRadius = 2 + $random->nextBoundedInt(2);
50 $radius = $random->nextBoundedInt(2);
51 $maxR = 1;
52 $minR = 0;
53
54 for($yy = 0; $yy <= $topSize; ++$yy){
55 $yyy = $y + $this->treeHeight - $yy;
56
57 for($xx = $x - $radius; $xx <= $x + $radius; ++$xx){
58 $xOff = abs($xx - $x);
59 for($zz = $z - $radius; $zz <= $z + $radius; ++$zz){
60 $zOff = abs($zz - $z);
61 if($xOff === $radius && $zOff === $radius && $radius > 0){
62 continue;
63 }
64
65 if(!$transaction->fetchBlockAt($xx, $yyy, $zz)->isSolid()){
66 $transaction->addBlockAt($xx, $yyy, $zz, $this->leafBlock);
67 }
68 }
69 }
70
71 if($radius >= $maxR){
72 $radius = $minR;
73 $minR = 1;
74 if(++$maxR > $lRadius){
75 $maxR = $lRadius;
76 }
77 }else{
78 ++$radius;
79 }
80 }
81 }
82}
addBlockAt(int $x, int $y, int $z, Block $state)
fetchBlockAt(int $x, int $y, int $z)
getBlockTransaction(ChunkManager $world, int $x, int $y, int $z, Random $random)
Definition: SpruceTree.php:42