diff --git a/src/misc/world/generator/object/tree/BigTreeObject.php b/src/misc/world/generator/object/tree/BigTreeObject.php new file mode 100644 index 00000000..3e5f3cb8 --- /dev/null +++ b/src/misc/world/generator/object/tree/BigTreeObject.php @@ -0,0 +1,89 @@ +trunkHeight = (int) ($this->totalHeight * $this->trunkHeightMultiplier); + $leaves = $this->getLeafGroupPoints($level, $x, $y, $z); + foreach($leaves as $leafGroup){ + $groupX = $leafGroup->getBlockX(); + $groupY = $leafGrou->getBlockY(); + $groupZ = $leafGroup->getBlockZ(); + for ($yy = $groupY; $yy < $groupY + $this->leafDistanceLimit; ++$yy) { + $this->generateGroupLayer($level, $groupX, $yy, $groupZ, $this->getLeafGroupLayerSize($yy - $groupY)); + } + } + /*final BlockIterator trunk = new BlockIterator(new Point(w, x, y - 1, z), new Point(w, x, y + trunkHeight, z)); + while (trunk.hasNext()) { + trunk.next().setMaterial(VanillaMaterials.LOG, logMetadata); + } + generateBranches(w, x, y, z, leaves); + + $level->setBlock($x, $y - 1, $z, 3, 0); + $this->totalHeight += mt_rand(-1, 3); + $this->leavesHeight += mt_rand(0, 1); + for($yy = ($this->totalHeight - $this->leavesHeight); $yy < ($this->totalHeight + 1); ++$yy){ + $yRadius = ($yy - $this->totalHeight); + $xzRadius = (int) (($this->radiusIncrease + 1) - $yRadius / 2); + for($xx = -$xzRadius; $xx < ($xzRadius + 1); ++$xx){ + for($zz = -$xzRadius; $zz < ($xzRadius + 1); ++$zz){ + if((abs($xx) != $xzRadius or abs($zz) != $xzRadius) and $yRadius != 0){ + $level->setBlock($x + $xx, $y + $yy, $z + $zz, 18, $type); + } + } + } + } + for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){ + $level->setBlock($x, $y + $yy, $z, 17, $type); + } + */ + } + + +} \ No newline at end of file diff --git a/src/misc/world/generator/object/tree/PineTreeObject.php b/src/misc/world/generator/object/tree/PineTreeObject.php new file mode 100644 index 00000000..9718c462 --- /dev/null +++ b/src/misc/world/generator/object/tree/PineTreeObject.php @@ -0,0 +1,97 @@ +findRandomLeavesSize(); + $checkRadius = 0; + for($yy = 0; $yy < $this->totalHeight + 2; ++$yy) { + if($yy === $this->leavesSizeY) { + $checkRadius = $this->leavesAbsoluteMaxRadius; + } + for($xx = -$checkRadius; $xx < ($checkRadius + 1); ++$xx){ + for($zz = -$checkRadius; $zz < ($checkRadius + 1); ++$zz){ + $block = $level->getBlock($x + $xx, $y + $yy, $z + $zz); + if(!isset($this->overridable[$block[0]])){ + return false; + } + } + } + } + return true; + } + + private function findRandomLeavesSize(){ + $this->totalHeight += mt_rand(-1, 2); + $this->leavesSizeY = 1 + mt_rand(0,2); + $this->leavesAbsoluteMaxRadius = 2 + mt_rand(0, 2); + } + + public function placeObject(LevelAPI $level, $x, $y, $z){ + if($this->leavesSizeY === -1 or $this->leavesAbsoluteMaxRadius === -1) { + $this->findRandomLeavesSize(); + } + $level->setBlock($x, $y - 1, $z, 3, 0); + $leavesRadius = mt_rand(0,2); + $leavesMaxRadius = 1; + $leavesBottomY = $this->totalHeight - $this->leavesSizeY; + $firstMaxedRadius = false; + for($leavesY = 0; $leavesY < ($leavesBottomY + 1); ++$leavesY) { + $yy = $this->totalHeight - $leavesY; + for ($xx = -$leavesRadius; $xx < ($leavesRadius + 1); ++$xx) { + for ($zz = -$leavesRadius; $zz < ($leavesRadius + 1); ++$zz) { + if (abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) { + $level->setBlock($x + $xx, $y + $yy, $z + $zz, 18, $this->type); + } + } + } + if ($leavesRadius >= $leavesMaxRadius) { + $leavesRadius = $firstMaxedRadius ? 1 : 0; + $firstMaxedRadius = true; + if (++$leavesMaxRadius > $this->leavesAbsoluteMaxRadius) { + $leavesMaxRadius = $this->leavesAbsoluteMaxRadius; + } + }else{ + ++$leavesRadius; + } + } + $trunkHeightReducer = mt_rand(0,3); + for($yy = 0; $yy < ($this->totalHeight - $trunkHeightReducer); ++$yy){ + $level->setBlock($x, $y + $yy, $z, 17, $this->type); + } + } + + +} \ No newline at end of file diff --git a/src/misc/world/generator/object/tree/SmallTreeObject.php b/src/misc/world/generator/object/tree/SmallTreeObject.php index 99c5a1a5..2b142ea5 100644 --- a/src/misc/world/generator/object/tree/SmallTreeObject.php +++ b/src/misc/world/generator/object/tree/SmallTreeObject.php @@ -29,6 +29,7 @@ the Free Software Foundation, either version 3 of the License, or require_once("misc/world/generator/object/tree/TreeObject.php"); class SmallTreeObject extends TreeObject{ + var $type = 0; private $totalHeight = 6; private $leavesHeight = 3; protected $radiusIncrease = 0; @@ -36,7 +37,25 @@ class SmallTreeObject extends TreeObject{ private $addLogVines = false; private $addCocoaPlants = false; - public function placeObject(LevelAPI $level, $x, $y, $z, $type){ + public function canPlaceObject(LevelAPI $level, $x, $y, $z){ + $radiusToCheck = $this->radiusIncrease; + for ($yy = 0; $yy < $this->totalHeight + 2; ++$yy) { + if ($yy == 1 or $yy === $this->totalHeight - 1) { + ++$radiusToCheck; + } + for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){ + for($zz = -$radiusToCheck; $zz < ($radiusToCheck + 1); ++$zz){ + $block = $level->getBlock($x + $xx, $y + $yy, $z + $zz); + if(!isset($this->overridable[$block[0]])){ + return false; + } + } + } + } + return true; + } + + public function placeObject(LevelAPI $level, $x, $y, $z){ $level->setBlock($x, $y - 1, $z, 3, 0); $this->totalHeight += mt_rand(-1, 3); $this->leavesHeight += mt_rand(0, 1); @@ -46,13 +65,13 @@ class SmallTreeObject extends TreeObject{ for($xx = -$xzRadius; $xx < ($xzRadius + 1); ++$xx){ for($zz = -$xzRadius; $zz < ($xzRadius + 1); ++$zz){ if((abs($xx) != $xzRadius or abs($zz) != $xzRadius) and $yRadius != 0){ - $level->setBlock($x + $xx, $y + $yy, $z + $zz, 18, $type); + $level->setBlock($x + $xx, $y + $yy, $z + $zz, 18, $this->type); } } } } for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){ - $level->setBlock($x, $y + $yy, $z, 17, $type); + $level->setBlock($x, $y + $yy, $z, 17, $this->type); } } diff --git a/src/misc/world/generator/object/tree/SpruceTreeObject.php b/src/misc/world/generator/object/tree/SpruceTreeObject.php new file mode 100644 index 00000000..3f72ae15 --- /dev/null +++ b/src/misc/world/generator/object/tree/SpruceTreeObject.php @@ -0,0 +1,88 @@ +findRandomLeavesSize(); + $checkRadius = 0; + for($yy = 0; $yy < $this->totalHeight + 2; ++$yy) { + if($yy === $this->leavesBottomY) { + $checkRadius = $this->leavesMaxRadius; + } + for($xx = -$checkRadius; $xx < ($checkRadius + 1); ++$xx){ + for($zz = -$checkRadius; $zz < ($checkRadius + 1); ++$zz){ + $block = $level->getBlock($x + $xx, $y + $yy, $z + $zz); + if(!isset($this->overridable[$block[0]])){ + return false; + } + } + } + } + return true; + } + + private function findRandomLeavesSize(){ + $this->totalHeight += mt_rand(-1, 2); + $this->leavesBottomY = (int) ($this->totalHeight - mt_rand(1,2) - 3); + $this->leavesMaxRadius = 1 + mt_rand(0, 1); + } + + public function placeObject(LevelAPI $level, $x, $y, $z){ + if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1) { + $this->findRandomLeavesSize(); + } + $level->setBlock($x, $y - 1, $z, 3, 0); + $leavesRadius = 0; + for($yy = $this->totalHeight; $yy >= $this->leavesBottomY; --$yy){ + for ($xx = -$leavesRadius; $xx < ($leavesRadius + 1); ++$xx) { + for ($zz = -$leavesRadius; $zz < ($leavesRadius + 1); ++$zz) { + if (abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) { + $level->setBlock($x + $xx, $y + $yy, $z + $zz, 18, $this->type); + } + } + } + if ($leavesRadius > 0 and $yy === ($y + $this->leavesBottomY + 1)) { + --$leavesRadius; + }elseif($leavesRadius < $this->leavesMaxRadius){ + ++$leavesRadius; + } + } + for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){ + $level->setBlock($x, $y + $yy, $z, 17, $this->type); + } + } + + +} \ No newline at end of file diff --git a/src/misc/world/generator/object/tree/TreeObject.php b/src/misc/world/generator/object/tree/TreeObject.php index 16027f99..14ca1f49 100644 --- a/src/misc/world/generator/object/tree/TreeObject.php +++ b/src/misc/world/generator/object/tree/TreeObject.php @@ -27,14 +27,36 @@ the Free Software Foundation, either version 3 of the License, or class TreeObject{ - + var $overridable = array( + 0 => true, + 6 => true, + 17 => true, + 18 => true, + ); public static function growTree(LevelAPI $level, $block, $type){ switch($type){ + case Sapling::SPRUCE: + if(mt_rand(0,1) == 2){ + $tree = new SpruceTreeObject(); + }else{ + $tree = new PineTreeObject(); + } + break; + case Sapling::BIRCH: + $tree = new SmallTreeObject(); + $tree->type = Sapling::BIRCH; + break; default: case Sapling::OAK: - $tree = new SmallTreeObject(); + if(mt_rand(0,9) === 0){ + $tree = new BigTreeObject(); + }else{ + $tree = new SmallTreeObject(); + } break; } - $tree->placeObject($level, $block[2][0], $block[2][1], $block[2][2], $type); + if($tree->canPlaceObject($level, $block[2][0], $block[2][1], $block[2][2])){ + $tree->placeObject($level, $block[2][0], $block[2][1], $block[2][2]); + } } } \ No newline at end of file