From e8b1b0fab66a6a43d5082c799a4170bdeac4b21b Mon Sep 17 00:00:00 2001 From: PEMapModder Date: Fri, 22 Aug 2014 11:05:47 +0800 Subject: [PATCH] Cleaned Mycelium.php and fixed its potential crash Crash report: http://crash.pocketmine.net/view/27500 --- src/pocketmine/block/Mycelium.php | 49 ++++++++++++++++--------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/pocketmine/block/Mycelium.php b/src/pocketmine/block/Mycelium.php index 2d9389a30..c6d434f71 100644 --- a/src/pocketmine/block/Mycelium.php +++ b/src/pocketmine/block/Mycelium.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -22,6 +22,7 @@ namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\level\Level; class Mycelium extends Solid{ public function __construct(){ @@ -29,25 +30,25 @@ class Mycelium extends Solid{ $this->hardness = 2.5; } - public function getDrops(Item $item){ - return [ - [Item::DIRT, 0, 1], - ]; - } + public function getDrops(Item $item){ + return [ + [Item::DIRT, 0, 1], + ]; + } - 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 Mycelium()); - } - } - } - } -} \ No newline at end of file + 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 Mycelium()); + } + } + } + } +}