GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
Tree Class Reference

Public Member Functions

 canPlaceObject (ChunkManager $level, $x, $y, $z, Random $random)
 
 placeObject (ChunkManager $level, $x, $y, $z, Random $random)
 

Static Public Member Functions

static growTree (ChunkManager $level, $x, $y, $z, Random $random, $type=0, bool $noBigTree=true)
 

Data Fields

 $overridable
 
 $type = 0
 
 $trunkBlock = Block::LOG
 
 $leafBlock = Block::LEAVES
 
 $treeHeight = 7
 
 $leafType = 0
 

Protected Member Functions

 placeTrunk (ChunkManager $level, $x, $y, $z, Random $random, $trunkHeight)
 

Member Function Documentation

◆ canPlaceObject()

canPlaceObject ( ChunkManager  $level,
  $x,
  $y,
  $z,
Random  $random 
)
Parameters
ChunkManager$level
$x
$y
$z
Random$random
Returns
bool
100  {
101  $radiusToCheck = 0;
102  for($yy = 0; $yy < $this->treeHeight + 3; ++$yy){
103  if($yy == 1 or $yy === $this->treeHeight){
104  ++$radiusToCheck;
105  }
106  for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){
107  for($zz = -$radiusToCheck; $zz < ($radiusToCheck + 1); ++$zz){
108  if(!isset($this->overridable[$level->getBlockIdAt($x + $xx, $y + $yy, $z + $zz)])){
109  return false;
110  }
111  }
112  }
113  }
114 
115  return true;
116  }

◆ growTree()

static growTree ( ChunkManager  $level,
  $x,
  $y,
  $z,
Random  $random,
  $type = 0,
bool  $noBigTree = true 
)
static
Parameters
ChunkManager$level
$x
$y
$z
Random$random
int$type
bool$noBigTree
55  {
56  switch($type){
57  case Sapling::SPRUCE:
58  $tree = new SpruceTree();
59  break;
60  case Sapling::BIRCH:
61  if($random->nextBoundedInt(39) === 0){
62  $tree = new BirchTree(true);
63  }else{
64  $tree = new BirchTree();
65  }
66  break;
67  case Sapling::JUNGLE:
68  $tree = new JungleTree();
69  break;
70  case Sapling::ACACIA:
71  $tree = new AcaciaTree();
72  break;
73  case Sapling::DARK_OAK:
74  $tree = new DarkOakTree();
75  break;
76  case Sapling::OAK:
77  default:
78  if(!$noBigTree and $random->nextRange(0, 9) === 0){
79  $tree = new BigTree();
80  }else{
81  $tree = new OakTree();
82  }
83  break;
84  }
85  if($tree->canPlaceObject($level, $x, $y, $z, $random)){
86  $tree->placeObject($level, $x, $y, $z, $random);
87  }
88  }

◆ placeObject()

placeObject ( ChunkManager  $level,
  $x,
  $y,
  $z,
Random  $random 
)
Parameters
ChunkManager$level
$x
$y
$z
Random$random
125  {
126 
127  $this->placeTrunk($level, $x, $y, $z, $random, $this->treeHeight - 1);
128 
129  for($yy = $y - 3 + $this->treeHeight; $yy <= $y + $this->treeHeight; ++$yy){
130  $yOff = $yy - ($y + $this->treeHeight);
131  $mid = (int) (1 - $yOff / 2);
132  for($xx = $x - $mid; $xx <= $x + $mid; ++$xx){
133  $xOff = abs($xx - $x);
134  for($zz = $z - $mid; $zz <= $z + $mid; ++$zz){
135  $zOff = abs($zz - $z);
136  if($xOff === $mid and $zOff === $mid and ($yOff === 0 or $random->nextBoundedInt(2) === 0)){
137  continue;
138  }
139  if(!Block::$solid[$level->getBlockIdAt($xx, $yy, $zz)]){
140  $level->setBlockIdAt($xx, $yy, $zz, $this->leafBlock);
141  $level->setBlockDataAt($xx, $yy, $zz, $this->leafType);
142  }
143  }
144  }
145  }
146  }

◆ placeTrunk()

placeTrunk ( ChunkManager  $level,
  $x,
  $y,
  $z,
Random  $random,
  $trunkHeight 
)
protected
Parameters
ChunkManager$level
$x
$y
$z
Random$random
$trunkHeight
156  {
157  // The base dirt block
158  $level->setBlockIdAt($x, $y - 1, $z, Block::DIRT);
159 
160  for($yy = 0; $yy < $trunkHeight; ++$yy){
161  $blockId = $level->getBlockIdAt($x, $y + $yy, $z);
162  if(isset($this->overridable[$blockId])){
163  $level->setBlockIdAt($x, $y + $yy, $z, $this->trunkBlock);
164  $level->setBlockDataAt($x, $y + $yy, $z, $this->type);
165  }
166  }
167  }

Field Documentation

◆ $leafBlock

$leafBlock = Block::LEAVES

◆ $leafType

$leafType = 0

◆ $overridable

$overridable
Initial value:
= [
Block::AIR => true

◆ $treeHeight

$treeHeight = 7

◆ $trunkBlock

$trunkBlock = Block::LOG

◆ $type

$type = 0

The documentation for this class was generated from the following file: