From 2353457b5bdef2b4da00cd21f1b9530620c31167 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Thu, 27 Dec 2012 01:08:26 +0100 Subject: [PATCH] Tree growing! --- TODO.md | 2 +- classes/API/BlockAPI.php | 4 ++ classes/API/ServerAPI.php | 2 +- classes/Generator.class.php | 3 +- classes/Utils.class.php | 2 +- common/dependencies.php | 2 + common/functions.php | 15 +++++ misc/block/plant/Sapling.php | 38 ++++++++++++ .../generator/object/tree/SmallTreeObject.php | 60 +++++++++++++++++++ .../generator/object/tree/TreeObject.php | 40 +++++++++++++ 10 files changed, 163 insertions(+), 5 deletions(-) create mode 100644 misc/block/plant/Sapling.php create mode 100644 misc/world/generator/object/tree/SmallTreeObject.php create mode 100644 misc/world/generator/object/tree/TreeObject.php diff --git a/TODO.md b/TODO.md index 821e2eaf6..75e80f221 100644 --- a/TODO.md +++ b/TODO.md @@ -15,7 +15,7 @@ __Check Milestones [here](https://github.com/shoghicp/PocketMine-MP/issues/miles * Done! ### Alpha v1.1 - +* Tree growing! ## Beta (Survival) - Random Chunk Updates diff --git a/classes/API/BlockAPI.php b/classes/API/BlockAPI.php index e0cdd664b..11d1c990b 100644 --- a/classes/API/BlockAPI.php +++ b/classes/API/BlockAPI.php @@ -176,6 +176,10 @@ class BlockAPI{ if(isset(Material::$activable[$target[0]])){ switch($target[0]){ case 6: + if($data["block"] === 351 and $data["meta"] === 0x0F){ //Bonemeal + Sapling::growTree($this->server->api->level, $target, $target[1] & 0x03); + $cancelPlace = true; + } break; case 2: case 3: diff --git a/classes/API/ServerAPI.php b/classes/API/ServerAPI.php index 73b90b349..67873e84f 100644 --- a/classes/API/ServerAPI.php +++ b/classes/API/ServerAPI.php @@ -153,7 +153,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run if($this->getProperty("generator") !== false and class_exists($this->getProperty("generator"))){ $generator = $this->getProperty("generator"); } - $this->gen = new Generator($generator, $this->server->seed); + $this->gen = new WorldGenerator($generator, $this->server->seed); if($this->getProperty("generator-settings") !== false and trim($this->getProperty("generator-settings")) != ""){ $this->gen->set("preset", $this->getProperty("generator-settings")); } diff --git a/classes/Generator.class.php b/classes/Generator.class.php index c9e01b7af..b2caac306 100644 --- a/classes/Generator.class.php +++ b/classes/Generator.class.php @@ -25,8 +25,7 @@ the Free Software Foundation, either version 3 of the License, or */ - -class Generator{ +class WorldGenerator{ private $gen, $seed, $raw; public function __construct($genName, $seed){ $this->seed = (int) $seed; diff --git a/classes/Utils.class.php b/classes/Utils.class.php index 9ba37e22b..76115ca8f 100644 --- a/classes/Utils.class.php +++ b/classes/Utils.class.php @@ -35,7 +35,7 @@ define("BIG_ENDIAN", 0x00); define("LITTLE_ENDIAN", 0x01); define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? BIG_ENDIAN:LITTLE_ENDIAN)); -class Utils{ +abstract class Utils{ public static function getOS(){ $uname = strtoupper(php_uname("s")); diff --git a/common/dependencies.php b/common/dependencies.php index 4ed0e72c1..462fcf0eb 100644 --- a/common/dependencies.php +++ b/common/dependencies.php @@ -69,6 +69,7 @@ if($errors > 0){ } + require_once("classes/Data.class.php"); require_once("classes/Player.class.php"); require_once("classes/Generator.class.php"); @@ -84,5 +85,6 @@ require_once("classes/SerializedPacketHandler.class.php"); require_once("classes/CustomPacketHandler.class.php"); require_once("classes/MinecraftInterface.class.php"); require_once("classes/BigInteger.class.php"); +require_all("misc/"); ?> \ No newline at end of file diff --git a/common/functions.php b/common/functions.php index 82b44061a..3380213e7 100644 --- a/common/functions.php +++ b/common/functions.php @@ -26,6 +26,21 @@ the Free Software Foundation, either version 3 of the License, or */ +function require_all($path, &$count = 0){ + $dir = dir($path."/"); + while(false !== ($file = $dir->read())){ + if($file !== "." and $file !== ".."){ + if(!is_dir($path.$file) and strtolower(substr($file, -3)) === "php"){ + require_once($path.$file); + ++$count; + }elseif(is_dir($path.$file)){ + require_all($path.$file."/", $count); + } + } + } + +} + function hard_unset(&$var){ if(is_object($var)){ $unset = new ReflectionClass($var); diff --git a/misc/block/plant/Sapling.php b/misc/block/plant/Sapling.php new file mode 100644 index 000000000..784346c6c --- /dev/null +++ b/misc/block/plant/Sapling.php @@ -0,0 +1,38 @@ +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/misc/world/generator/object/tree/TreeObject.php b/misc/world/generator/object/tree/TreeObject.php new file mode 100644 index 000000000..16027f995 --- /dev/null +++ b/misc/world/generator/object/tree/TreeObject.php @@ -0,0 +1,40 @@ +placeObject($level, $block[2][0], $block[2][1], $block[2][2], $type); + } +} \ No newline at end of file