Cleaned Mycelium.php and fixed its potential crash

Crash report: http://crash.pocketmine.net/view/27500
This commit is contained in:
PEMapModder 2014-08-22 11:05:47 +08:00
parent 4858c7d82e
commit e8b1b0fab6

View File

@ -2,11 +2,11 @@
/* /*
* *
* ____ _ _ __ __ _ __ __ ____ * ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU Lesser General Public License as published by
@ -22,6 +22,7 @@
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\level\Level;
class Mycelium extends Solid{ class Mycelium extends Solid{
public function __construct(){ public function __construct(){
@ -29,25 +30,25 @@ class Mycelium extends Solid{
$this->hardness = 2.5; $this->hardness = 2.5;
} }
public function getDrops(Item $item){ public function getDrops(Item $item){
return [ return [
[Item::DIRT, 0, 1], [Item::DIRT, 0, 1],
]; ];
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_RANDOM){ if($type === Level::BLOCK_UPDATE_RANDOM){
//TODO: light levels //TODO: light levels
$x = mt_rand($this->x - 1, $this->x + 1); $x = mt_rand($this->x - 1, $this->x + 1);
$y = mt_rand($this->y - 2, $this->y + 2); $y = mt_rand($this->y - 2, $this->y + 2);
$z = mt_rand($this->z - 1, $this->z + 1); $z = mt_rand($this->z - 1, $this->z + 1);
$block = $this->getLevel()->getBlockIdAt($x, $y, $z); $block = $this->getLevel()->getBlockIdAt($x, $y, $z);
if($block === Block::DIRT){ if($block === Block::DIRT){
$block = $this->getLevel()->getBlock(new Vector3($x, $y, $z)); $block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
if($block->getSide(1) instanceof Transparent){ if($block->getSide(1) instanceof Transparent){
$this->getLevel()->setBlock($block, new Mycelium()); $this->getLevel()->setBlock($block, new Mycelium());
} }
} }
} }
} }
} }