From 36cdfd969d927993fe2ce0294cdc2af81f6bea56 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 22 Jun 2014 22:26:36 +0200 Subject: [PATCH] Fixed #799 Added Grass growth algorithm --- src/pocketmine/block/Grass.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/block/Grass.php b/src/pocketmine/block/Grass.php index a4b324217..b6e8ecf35 100644 --- a/src/pocketmine/block/Grass.php +++ b/src/pocketmine/block/Grass.php @@ -24,6 +24,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\level\generator\object\TallGrass; use pocketmine\level\Level; +use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\utils\Random; @@ -41,7 +42,19 @@ class Grass extends Solid{ } public function onUpdate($type){ - + if($type === Level::BLOCK_UPDATE_RANDOM){ + //TODO: light levels + $x = mt_rand($this->x - 1, $this->x + 1); + $y = mt_rand($this->y - 2, $this->y + 2); + $z = mt_rand($this->z - 1, $this->z + 1); + $block = $this->getLevel()->getBlockIdAt($x, $y, $z); + if($block === Block::DIRT){ + $block = $this->getLevel()->getBlock(new Vector3($x, $y, $z)); + if($block->getSide(1) instanceof Transparent){ + $this->getLevel()->setBlock($block, new Grass()); + } + } + } } public function onActivate(Item $item, Player $player = null){