diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 287ac7182..7d7eb861c 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -81,6 +81,7 @@ use pocketmine\item\Durable; use pocketmine\item\enchantment\EnchantmentInstance; use pocketmine\item\enchantment\MeleeWeaponEnchantment; use pocketmine\item\Item; +use pocketmine\item\MaybeConsumable; use pocketmine\item\WritableBook; use pocketmine\item\WrittenBook; use pocketmine\lang\TextContainer; @@ -2451,7 +2452,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ case InventoryTransactionPacket::USE_ITEM_ACTION_CLICK_AIR: if($this->isUsingItem()){ $slot = $this->inventory->getItemInHand(); - if($slot instanceof Consumable){ + if($slot instanceof Consumable and !($slot instanceof MaybeConsumable and !$slot->canBeConsumed())){ $ev = new PlayerItemConsumeEvent($this, $slot); if($this->hasItemCooldown($slot)){ $ev->setCancelled(); diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 96fcf0b96..0889ab07c 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -38,6 +38,7 @@ use pocketmine\item\Durable; use pocketmine\item\enchantment\Enchantment; use pocketmine\item\FoodSource; use pocketmine\item\Item; +use pocketmine\item\MaybeConsumable; use pocketmine\item\Totem; use pocketmine\level\Level; use pocketmine\nbt\NBT; @@ -296,6 +297,10 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ } public function consumeObject(Consumable $consumable) : bool{ + if($consumable instanceof MaybeConsumable and !$consumable->canBeConsumed()){ + return false; + } + if($consumable instanceof FoodSource){ if($consumable->requiresHunger() and !$this->isHungry()){ return false; diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 0e107d69b..21bd4523f 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -37,6 +37,7 @@ use pocketmine\item\Consumable; use pocketmine\item\Durable; use pocketmine\item\enchantment\Enchantment; use pocketmine\item\Item; +use pocketmine\item\MaybeConsumable; use pocketmine\math\Vector3; use pocketmine\math\VoxelRayTrace; use pocketmine\nbt\tag\ByteTag; @@ -359,6 +360,10 @@ abstract class Living extends Entity implements Damageable{ * etc. */ public function consumeObject(Consumable $consumable) : bool{ + if($consumable instanceof MaybeConsumable and !$consumable->canBeConsumed()){ + return false; + } + foreach($consumable->getAdditionalEffects() as $effect){ $this->addEffect($effect); } diff --git a/src/pocketmine/item/Bucket.php b/src/pocketmine/item/Bucket.php index 3c7834350..717a4b5c6 100644 --- a/src/pocketmine/item/Bucket.php +++ b/src/pocketmine/item/Bucket.php @@ -33,7 +33,7 @@ use pocketmine\event\player\PlayerBucketFillEvent; use pocketmine\math\Vector3; use pocketmine\Player; -class Bucket extends Item implements Consumable{ +class Bucket extends Item implements MaybeConsumable{ public function __construct(int $meta = 0){ parent::__construct(self::BUCKET, $meta, "Bucket"); } diff --git a/src/pocketmine/item/MaybeConsumable.php b/src/pocketmine/item/MaybeConsumable.php new file mode 100644 index 000000000..2bd380e14 --- /dev/null +++ b/src/pocketmine/item/MaybeConsumable.php @@ -0,0 +1,36 @@ +