PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
Bucket.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\item;
23 
30 
31 class Bucket extends Item{
32  public function __construct($meta = 0, $count = 1){
33  parent::__construct(self::BUCKET, $meta, $count, "Bucket");
34  }
35 
36  public function getMaxStackSize(){
37  return 1;
38  }
39 
40  public function canBeActivated(){
41  return true;
42  }
43 
44  public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
45  $targetBlock = Block::get($this->meta);
46 
47  if($targetBlock instanceof Air){
48  if($target instanceof Liquid and $target->getDamage() === 0){
49  $result = clone $this;
50  $result->setDamage($target->getId());
51  $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
52  if(!$ev->isCancelled()){
53  $player->getLevel()->setBlock($target, new Air(), true, true);
54  if($player->isSurvival()){
55  $player->getInventory()->setItemInHand($ev->getItem(), $player);
56  }
57  return true;
58  }else{
59  $player->getInventory()->sendContents($player);
60  }
61  }
62  }elseif($targetBlock instanceof Liquid){
63  $result = clone $this;
64  $result->setDamage(0);
65  $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
66  if(!$ev->isCancelled()){
67  $player->getLevel()->setBlock($block, $targetBlock, true, true);
68  if($player->isSurvival()){
69  $player->getInventory()->setItemInHand($ev->getItem(), $player);
70  }
71  return true;
72  }else{
73  $player->getInventory()->sendContents($player);
74  }
75  }
76 
77  return false;
78  }
79 }
static get($id, $meta=0, Position $pos=null)
Definition: Block.php:782