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:
Dylan K. Taylor
2017-12-23 13:03:41 +00:00
committed by GitHub
parent 329fe7d844
commit 6e1df36188
14 changed files with 113 additions and 306 deletions

View File

@ -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();
}
}