mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 02:42:58 +00:00
Consumables refactor (#1796)
* Removed broken EntityEatEvents - these don't fit the pattern since they only apply to Human entities anyway. PlayerItemConsumeEvent and PlayerInteractEvent can be used for cancellation purposes, and plugins can do custom stuff without mess. * Restrict item consuming to Living entities only * Added FoodSource->requiresHunger() * Only items implementing the Consumable interface can now be consumed. * The effects from consuming items are now generic-ized by way of the Living->consume() function. This is overridden in Human to allow applying food and hunger. * Fixed the hardcoded mess for buckets
This commit is contained in:
@ -27,13 +27,14 @@ use pocketmine\block\Air;
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\Liquid;
|
||||
use pocketmine\entity\Living;
|
||||
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{
|
||||
class Bucket extends Item implements Consumable{
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::BUCKET, $meta, "Bucket");
|
||||
}
|
||||
@ -85,4 +86,20 @@ class Bucket extends Item{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getResidue(){
|
||||
return ItemFactory::get(Item::BUCKET, 0, 1);
|
||||
}
|
||||
|
||||
public function getAdditionalEffects() : array{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function canBeConsumed() : bool{
|
||||
return $this->meta === 1; //Milk
|
||||
}
|
||||
|
||||
public function onConsume(Living $consumer){
|
||||
$consumer->removeAllEffects();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user