PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
PineTree.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 
22 namespace pocketmine\level\generator\object;
23 
27 
28 class PineTree extends Tree{
29  var $type = 1;
30  private $totalHeight = 8;
31  private $leavesSizeY = -1;
32  private $leavesAbsoluteMaxRadius = -1;
33 
34  public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random){
35  $this->findRandomLeavesSize($random);
36  $checkRadius = 0;
37  for($yy = 0; $yy < $this->totalHeight; ++$yy){
38  if($yy === $this->leavesSizeY){
39  $checkRadius = $this->leavesAbsoluteMaxRadius;
40  }
41  for($xx = -$checkRadius; $xx < ($checkRadius + 1); ++$xx){
42  for($zz = -$checkRadius; $zz < ($checkRadius + 1); ++$zz){
43  if(!isset($this->overridable[$level->getBlockIdAt($x + $xx, $y + $yy, $z + $zz)])){
44  return false;
45  }
46  }
47  }
48  }
49 
50  return true;
51  }
52 
53  private function findRandomLeavesSize(Random $random){
54  $this->totalHeight += $random->nextRange(-1, 2);
55  $this->leavesSizeY = 1 + $random->nextRange(0, 2);
56  $this->leavesAbsoluteMaxRadius = 2 + $random->nextRange(0, 1);
57  }
58 
59  public function placeObject(ChunkManager $level, $x, $y, $z, Random $random){
60  if($this->leavesSizeY === -1 or $this->leavesAbsoluteMaxRadius === -1){
61  $this->findRandomLeavesSize($random);
62  }
63  $level->setBlockIdAt($x, $y - 1, $z, Block::DIRT);
64  $leavesRadius = 0;
65  $leavesMaxRadius = 1;
66  $leavesBottomY = $this->totalHeight - $this->leavesSizeY;
67  $firstMaxedRadius = false;
68  for($leavesY = 0; $leavesY <= $leavesBottomY; ++$leavesY){
69  $yy = $this->totalHeight - $leavesY;
70  for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx){
71  for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz){
72  if(abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0){
73  $level->setBlockIdAt($x + $xx, $y + $yy, $z + $zz, Block::LEAVES);
74  $level->setBlockDataAt($x + $xx, $y + $yy, $z + $zz, $this->type);
75  }
76  }
77  }
78  if($leavesRadius >= $leavesMaxRadius){
79  $leavesRadius = $firstMaxedRadius ? 1 : 0;
80  $firstMaxedRadius = true;
81  if(++$leavesMaxRadius > $this->leavesAbsoluteMaxRadius){
82  $leavesMaxRadius = $this->leavesAbsoluteMaxRadius;
83  }
84  }else{
85  ++$leavesRadius;
86  }
87  }
88  $trunkHeightReducer = $random->nextRange(0, 3);
89  for($yy = 0; $yy < ($this->totalHeight - $trunkHeightReducer); ++$yy){
90  $level->setBlockIdAt($x, $y + $yy, $z, Block::TRUNK);
91  $level->setBlockDataAt($x, $y + $yy, $z, $this->type);
92  }
93  }
94 
95 
96 }
setBlockIdAt($x, $y, $z, $id)
setBlockDataAt($x, $y, $z, $data)
nextRange($start=0, $end=0x7fffffff)
Definition: Random.php:112