PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
block/Cake.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 
30 
31 class Cake extends Transparent{
32 
33  protected $id = self::CAKE_BLOCK;
34 
35  public function __construct($meta = 0){
36  $this->meta = $meta;
37  }
38 
39  public function canBeActivated(){
40  return true;
41  }
42 
43  public function getHardness(){
44  return 2.5;
45  }
46 
47  public function getName(){
48  return "Cake Block";
49  }
50 
51  protected function recalculateBoundingBox(){
52 
53  $f = (1 + $this->getDamage() * 2) / 16;
54 
55  return new AxisAlignedBB(
56  $this->x + $f,
57  $this->y,
58  $this->z + 0.0625,
59  $this->x + 1 - 0.0625,
60  $this->y + 0.5,
61  $this->z + 1 - 0.0625
62  );
63  }
64 
65  public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
66  $down = $this->getSide(0);
67  if($down->getId() !== self::AIR){
68  $this->getLevel()->setBlock($block, $this, true, true);
69 
70  return true;
71  }
72 
73  return false;
74  }
75 
76  public function onUpdate($type){
77  if($type === Level::BLOCK_UPDATE_NORMAL){
78  if($this->getSide(0)->getId() === self::AIR){ //Replace with common break method
79  $this->getLevel()->setBlock($this, new Air(), true);
80 
81  return Level::BLOCK_UPDATE_NORMAL;
82  }
83  }
84 
85  return false;
86  }
87 
88  public function getDrops(Item $item){
89  return [];
90  }
91 
92  public function onActivate(Item $item, Player $player = null){
93  if($player instanceof Player and $player->getHealth() < 20){
94  ++$this->meta;
95  Server::getInstance()->getPluginManager()->callEvent($ev = new EntityRegainHealthEvent($player, 3, EntityRegainHealthEvent::CAUSE_EATING));
96  if(!$ev->isCancelled()){
97  $player->heal($ev->getAmount(), $ev);
98  }
99  if($this->meta >= 0x06){
100  $this->getLevel()->setBlock($this, new Air(), true);
101  }else{
102  $this->getLevel()->setBlock($this, $this, true);
103  }
104 
105  return true;
106  }
107 
108  return false;
109  }
110 
111 }
static getInstance()
Definition: Server.php:1444
getSide($side, $step=1)
Definition: Block.php:1028