PocketMine-MP 5.33.2 git-1133d49c924b4358c79d44eeb97dcbf56cb4d1eb
Loading...
Searching...
No Matches
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
22declare(strict_types=1);
23
24namespace pocketmine\item;
25
34
35class Bucket extends Item{
36
37 public function getMaxStackSize() : int{
38 return 16;
39 }
40
41 public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{
42 //TODO: move this to generic placement logic
43 if($blockClicked instanceof Liquid && $blockClicked->isSource()){
44 $stack = clone $this;
45 $stack->pop();
46
47 $resultItem = match($blockClicked->getTypeId()){
48 BlockTypeIds::LAVA => VanillaItems::LAVA_BUCKET(),
49 BlockTypeIds::WATER => VanillaItems::WATER_BUCKET(),
50 default => null
51 };
52 if($resultItem === null){
53 return ItemUseResult::FAIL;
54 }
55
56 $ev = new PlayerBucketFillEvent($player, $blockReplace, $face, $this, $resultItem);
57 $ev->call();
58 if(!$ev->isCancelled()){
59 $player->getWorld()->setBlock($blockClicked->getPosition(), VanillaBlocks::AIR());
60 $player->getWorld()->addSound($blockClicked->getPosition()->add(0.5, 0.5, 0.5), $blockClicked->getBucketFillSound());
61
62 $this->pop();
63 $returnedItems[] = $ev->getItem();
64 return ItemUseResult::SUCCESS;
65 }
66
67 return ItemUseResult::FAIL;
68 }
69
70 return ItemUseResult::NONE;
71 }
72}
onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, array &$returnedItems)
Definition Bucket.php:41