PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
MelonStem.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17  * @link http://www.pocketmine.net/
18  *
19  *
20 */
21 
22 namespace pocketmine\block;
23 
28 
29 class MelonStem extends Crops{
30 
31  protected $id = self::MELON_STEM;
32 
33  public function getName(){
34  return "Melon Stem";
35  }
36 
37  public function __construct($meta = 0){
38  $this->meta = $meta;
39  }
40 
41  public function onUpdate($type){
42  if($type === Level::BLOCK_UPDATE_NORMAL){
43  if($this->getSide(0)->isTransparent() === true){
44  $this->getLevel()->useBreakOn($this);
45  return Level::BLOCK_UPDATE_NORMAL;
46  }
47  }elseif($type === Level::BLOCK_UPDATE_RANDOM){
48  if(mt_rand(0, 2) == 1){
49  if($this->meta < 0x07){
50  $block = clone $this;
51  ++$block->meta;
52  Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
53  if(!$ev->isCancelled()){
54  $this->getLevel()->setBlock($this, $ev->getNewState(), true);
55  }
56 
57  return Level::BLOCK_UPDATE_RANDOM;
58  }else{
59  for($side = 2; $side <= 5; ++$side){
60  $b = $this->getSide($side);
61  if($b->getId() === self::MELON_BLOCK){
62  return Level::BLOCK_UPDATE_RANDOM;
63  }
64  }
65  $side = $this->getSide(mt_rand(2, 5));
66  $d = $side->getSide(0);
67  if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){
68  Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, new Melon()));
69  if(!$ev->isCancelled()){
70  $this->getLevel()->setBlock($side, $ev->getNewState(), true);
71  }
72  }
73  }
74  }
75 
76  return Level::BLOCK_UPDATE_RANDOM;
77  }
78 
79  return false;
80  }
81 
82  public function getDrops(Item $item){
83  return [
84  [Item::MELON_SEEDS, 0, mt_rand(0, 2)],
85  ];
86  }
87 }
static getInstance()
Definition: Server.php:1444
getSide($side, $step=1)
Definition: Block.php:1028