mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-05 09:39:56 +00:00
88 lines
2.7 KiB
PHP
88 lines
2.7 KiB
PHP
<?php
|
|
|
|
/*
|
|
*
|
|
* ____ _ _ __ __ _ __ __ ____
|
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
*
|
|
* 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
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* @author PocketMine Team
|
|
* @link http://www.pocketmine.net/
|
|
*
|
|
*
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine\item;
|
|
|
|
use pocketmine\block\Air;
|
|
use pocketmine\block\Block;
|
|
use pocketmine\block\BlockFactory;
|
|
use pocketmine\block\Liquid;
|
|
use pocketmine\event\player\PlayerBucketEmptyEvent;
|
|
use pocketmine\event\player\PlayerBucketFillEvent;
|
|
use pocketmine\level\Level;
|
|
use pocketmine\math\Vector3;
|
|
use pocketmine\Player;
|
|
|
|
class Bucket extends Item{
|
|
public function __construct(int $meta = 0){
|
|
parent::__construct(self::BUCKET, $meta, "Bucket");
|
|
}
|
|
|
|
public function getMaxStackSize() : int{
|
|
return 1;
|
|
}
|
|
|
|
public function getFuelTime() : int{
|
|
if($this->meta === Block::LAVA or $this->meta === Block::FLOWING_LAVA){
|
|
return 20000;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{
|
|
$targetBlock = BlockFactory::get($this->meta);
|
|
|
|
if($targetBlock instanceof Air){
|
|
if($target instanceof Liquid and $target->getDamage() === 0){
|
|
$result = clone $this;
|
|
$result->setDamage($target->getId());
|
|
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
|
|
if(!$ev->isCancelled()){
|
|
$player->getLevel()->setBlock($target, BlockFactory::get(Block::AIR), true, true);
|
|
if($player->isSurvival()){
|
|
$player->getInventory()->setItemInHand($ev->getItem());
|
|
}
|
|
return true;
|
|
}else{
|
|
$player->getInventory()->sendContents($player);
|
|
}
|
|
}
|
|
}elseif($targetBlock instanceof Liquid){
|
|
$result = clone $this;
|
|
$result->setDamage(0);
|
|
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketEmptyEvent($player, $block, $face, $this, $result));
|
|
if(!$ev->isCancelled()){
|
|
$player->getLevel()->setBlock($block, $targetBlock, true, true);
|
|
if($player->isSurvival()){
|
|
$player->getInventory()->setItemInHand($ev->getItem());
|
|
}
|
|
return true;
|
|
}else{
|
|
$player->getInventory()->sendContents($player);
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |