Check to see if the player can start using the Releasable item. (#4532)

This commit is contained in:
Rush2929
2021-11-02 23:36:16 +09:00
committed by GitHub
parent 34ea199fb0
commit ede4157814
6 changed files with 24 additions and 1 deletions

View File

@@ -123,4 +123,8 @@ class Bow extends Tool implements Releasable{
return ItemUseResult::SUCCESS();
}
public function canStartUsingItem(Player $player) : bool{
return !$player->hasFiniteResources() || $player->getOffHandInventory()->contains($arrow = VanillaItems::ARROW()) || $player->getInventory()->contains($arrow);
}
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\entity\Living;
use pocketmine\player\Player;
abstract class Food extends Item implements FoodSourceItem{
public function requiresHunger() : bool{
@@ -41,4 +42,8 @@ abstract class Food extends Item implements FoodSourceItem{
public function onConsume(Living $consumer) : void{
}
public function canStartUsingItem(Player $player) : bool{
return !$this->requiresHunger() || $player->getHungerManager()->isHungry();
}
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\entity\Living;
use pocketmine\player\Player;
class MilkBucket extends Item implements ConsumableItem{
@@ -42,4 +43,8 @@ class MilkBucket extends Item implements ConsumableItem{
public function onConsume(Living $consumer) : void{
$consumer->getEffects()->clear();
}
public function canStartUsingItem(Player $player) : bool{
return true;
}
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\entity\Living;
use pocketmine\player\Player;
class Potion extends Item implements ConsumableItem{
@@ -52,4 +53,8 @@ class Potion extends Item implements ConsumableItem{
public function getResidue() : Item{
return VanillaItems::GLASS_BOTTLE();
}
public function canStartUsingItem(Player $player) : bool{
return true;
}
}

View File

@@ -23,9 +23,13 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\player\Player;
/**
* Interface implemented by objects that can be used.
*/
interface Releasable{
public function canStartUsingItem(Player $player) : bool;
}