Added events

This commit is contained in:
PEMapModder 2016-02-11 22:07:04 +08:00
parent 8807617480
commit e79976bdac
18 changed files with 405 additions and 53 deletions

View File

@ -48,6 +48,7 @@ use pocketmine\event\player\PlayerChatEvent;
use pocketmine\event\player\PlayerCommandPreprocessEvent; use pocketmine\event\player\PlayerCommandPreprocessEvent;
use pocketmine\event\player\PlayerDeathEvent; use pocketmine\event\player\PlayerDeathEvent;
use pocketmine\event\player\PlayerDropItemEvent; use pocketmine\event\player\PlayerDropItemEvent;
use pocketmine\event\player\PlayerExhaustEvent;
use pocketmine\event\player\PlayerGameModeChangeEvent; use pocketmine\event\player\PlayerGameModeChangeEvent;
use pocketmine\event\player\PlayerInteractEvent; use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\player\PlayerItemConsumeEvent; use pocketmine\event\player\PlayerItemConsumeEvent;
@ -75,7 +76,6 @@ use pocketmine\inventory\PlayerInventory;
use pocketmine\inventory\ShapedRecipe; use pocketmine\inventory\ShapedRecipe;
use pocketmine\inventory\ShapelessRecipe; use pocketmine\inventory\ShapelessRecipe;
use pocketmine\inventory\SimpleTransactionGroup; use pocketmine\inventory\SimpleTransactionGroup;
use pocketmine\item\Food;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\level\ChunkLoader; use pocketmine\level\ChunkLoader;
use pocketmine\level\format\FullChunk; use pocketmine\level\format\FullChunk;
@ -2267,7 +2267,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->inventory->sendHeldItem($this->hasSpawned); $this->inventory->sendHeldItem($this->hasSpawned);
} }
$this->exhaust(0.025); $this->exhaust(0.025, PlayerExhaustEvent::CAUSE_MINING);
} }
break; break;
} }
@ -2408,7 +2408,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
} }
} }
$this->exhaust(0.3); $this->exhaust(0.3, PlayerExhaustEvent::CAUSE_ATTACK);
} }
} }
@ -2442,14 +2442,14 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
case EntityEventPacket::USE_ITEM: //Eating case EntityEventPacket::USE_ITEM: //Eating
$slot = $this->inventory->getItemInHand(); $slot = $this->inventory->getItemInHand();
if($slot instanceof Food){ if($slot->canBeConsumed()){
$ev = new PlayerItemConsumeEvent($this, $slot); $ev = new PlayerItemConsumeEvent($this, $slot);
if($this->getFood() >= $this->getMaxFood()){ if(!$slot->canBeConsumedBy($this)){
$ev->setCancelled(); $ev->setCancelled();
} }
$this->server->getPluginManager()->callEvent($ev); $this->server->getPluginManager()->callEvent($ev);
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$slot->onEat($this); $slot->onConsume($this);
}else{ }else{
$this->inventory->sendContents($this); $this->inventory->sendContents($this);
} }
@ -3226,7 +3226,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->dataPacket($pk); $this->dataPacket($pk);
if($this->isSurvival()){ if($this->isSurvival()){
$this->exhaust(0.3); $this->exhaust(0.3, PlayerExhaustEvent::CAUSE_DAMAGE);
} }
} }
} }

View File

@ -21,14 +21,15 @@
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\entity\Effect;
use pocketmine\event\entity\EntityEatBlockEvent;
use pocketmine\item\FoodSource;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\Player; use pocketmine\Player;
class Cake extends Transparent implements FoodSource{
class Cake extends Transparent{
protected $id = self::CAKE_BLOCK; protected $id = self::CAKE_BLOCK;
@ -91,18 +92,10 @@ class Cake extends Transparent{
public function onActivate(Item $item, Player $player = null){ public function onActivate(Item $item, Player $player = null){
if($player instanceof Player and $player->getHealth() < $player->getMaxHealth()){ if($player instanceof Player and $player->getHealth() < $player->getMaxHealth()){
++$this->meta; $ev = new EntityEatBlockEvent($player, $this);
$ev = new EntityRegainHealthEvent($player, 3, EntityRegainHealthEvent::CAUSE_EATING);
$player->heal($ev->getAmount(), $ev); // TODO hunger
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
if($this->meta >= 0x06){ $this->getLevel()->setBlock($this, $ev->getResidue());
$this->getLevel()->setBlock($this, new Air(), true);
}else{
$this->getLevel()->setBlock($this, $this, true);
}
return true; return true;
} }
} }
@ -110,4 +103,27 @@ class Cake extends Transparent{
return false; return false;
} }
public function getFoodRestore() : int{
return 2;
}
public function getSaturationRestore() : float{
return 0.4;
}
public function getResidue(){
$clone = clone $this;
$clone->meta++;
if($clone->meta >= 0x06){
$clone = new Air();
}
return $clone;
}
/**
* @return Effect[]
*/
public function getAdditionalEffects() : array{
return [];
}
} }

View File

@ -23,6 +23,7 @@ namespace pocketmine\entity;
use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\event\entity\EntityRegainHealthEvent;
use pocketmine\event\player\PlayerExhaustEvent;
use pocketmine\network\protocol\MobEffectPacket; use pocketmine\network\protocol\MobEffectPacket;
use pocketmine\Player; use pocketmine\Player;
@ -34,8 +35,8 @@ class Effect{
const FATIGUE = 4; const FATIGUE = 4;
const MINING_FATIGUE = 4; const MINING_FATIGUE = 4;
const STRENGTH = 5; const STRENGTH = 5;
//TODO: const HEALING = 6; // TODO: const HEALING = 6;
//TODO: const HARMING = 7; // TODO: const HARMING = 7;
const JUMP = 8; const JUMP = 8;
const NAUSEA = 9; const NAUSEA = 9;
const CONFUSION = 9; const CONFUSION = 9;
@ -46,7 +47,7 @@ class Effect{
const INVISIBILITY = 14; const INVISIBILITY = 14;
const BLINDNESS = 15; const BLINDNESS = 15;
const NIGHT_VISION = 16; const NIGHT_VISION = 16;
const HUNGER = 17; // TODO implement const HUNGER = 17;
const WEAKNESS = 18; const WEAKNESS = 18;
const POISON = 19; const POISON = 19;
const WITHER = 20; const WITHER = 20;
@ -74,15 +75,15 @@ class Effect{
self::$effects[Effect::FIRE_RESISTANCE] = new Effect(Effect::FIRE_RESISTANCE, "%potion.fireResistance", 228, 154, 58); self::$effects[Effect::FIRE_RESISTANCE] = new Effect(Effect::FIRE_RESISTANCE, "%potion.fireResistance", 228, 154, 58);
self::$effects[Effect::WATER_BREATHING] = new Effect(Effect::WATER_BREATHING, "%potion.waterBreathing", 46, 82, 153); self::$effects[Effect::WATER_BREATHING] = new Effect(Effect::WATER_BREATHING, "%potion.waterBreathing", 46, 82, 153);
self::$effects[Effect::INVISIBILITY] = new Effect(Effect::INVISIBILITY, "%potion.invisibility", 127, 131, 146); self::$effects[Effect::INVISIBILITY] = new Effect(Effect::INVISIBILITY, "%potion.invisibility", 127, 131, 146);
// TODO Blindness %potion.blindness self::$effects[Effect::BLINDNESS] = new Effect(Effect::BLINDNESS, "%potion.blindness", 191, 192, 192);
// TODO Night Vision %potion.nightVision self::$effects[Effect::NIGHT_VISION] = new Effect(Effect::NIGHT_VISION, "%potion.nightVision", 0, 0, 139);
// TODO Hunger %potion.hunger self::$effects[Effect::HUNGER] = new Effect(Effect::HUNGER, "%potion.hunger", 46, 139, 87);
self::$effects[Effect::WEAKNESS] = new Effect(Effect::WEAKNESS, "%potion.weakness", 72, 77, 72, true); self::$effects[Effect::WEAKNESS] = new Effect(Effect::WEAKNESS, "%potion.weakness", 72, 77, 72, true);
self::$effects[Effect::POISON] = new Effect(Effect::POISON, "%potion.poison", 78, 147, 49, true); self::$effects[Effect::POISON] = new Effect(Effect::POISON, "%potion.poison", 78, 147, 49, true);
self::$effects[Effect::WITHER] = new Effect(Effect::WITHER, "%potion.wither", 53, 42, 39, true); self::$effects[Effect::WITHER] = new Effect(Effect::WITHER, "%potion.wither", 53, 42, 39, true);
self::$effects[Effect::HEALTH_BOOST] = new Effect(Effect::HEALTH_BOOST, "%potion.healthBoost", 248, 125, 35); self::$effects[Effect::HEALTH_BOOST] = new Effect(Effect::HEALTH_BOOST, "%potion.healthBoost", 248, 125, 35);
// TODO Absorption %potion.absorption self::$effects[Effect::ABSORPTION] = new Effect(Effect::ABSORPTION, "%potion.absorption", 36, 107, 251);
// TODO Saturation %potion.saturation self::$effects[Effect::SATURATION] = new Effect(Effect::SATURATION, "%potion.saturation", 255, 0, 255);
} }
/** /**
@ -236,7 +237,7 @@ class Effect{
case Effect::HUNGER: case Effect::HUNGER:
if($entity instanceof Human){ if($entity instanceof Human){
$entity->exhaust(0.5 * $this->amplifier); $entity->exhaust(0.5 * $this->amplifier, PlayerExhaustEvent::CAUSE_POTION);
} }
} }
} }

View File

@ -23,6 +23,7 @@ namespace pocketmine\entity;
use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\event\entity\EntityRegainHealthEvent;
use pocketmine\event\player\PlayerExhaustEvent;
use pocketmine\inventory\InventoryHolder; use pocketmine\inventory\InventoryHolder;
use pocketmine\inventory\PlayerInventory; use pocketmine\inventory\PlayerInventory;
use pocketmine\item\Item as ItemItem; use pocketmine\item\Item as ItemItem;
@ -170,10 +171,18 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
* Increases a human's exhaustion level. * Increases a human's exhaustion level.
* *
* @param float $amount * @param float $amount
* @param int $cause
*
* @return float the amount of exhaustion level increased
*/ */
public function exhaust(float $amount){ public function exhaust(float $amount, int $cause = PlayerExhaustEvent::CAUSE_CUSTOM) : float{
$this->server->getPluginManager()->callEvent($ev = new PlayerExhaustEvent($this, $amount, $cause));
if($ev->isCancelled()){
return 0.0;
}
$exhaustion = $this->getExhaustion(); $exhaustion = $this->getExhaustion();
$exhaustion += $amount; $exhaustion += $ev->getAmount();
while($exhaustion >= 4.0){ while($exhaustion >= 4.0){
$exhaustion -= 4.0; $exhaustion -= 4.0;
@ -191,6 +200,8 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
} }
} }
$this->setExhaustion($exhaustion); $this->setExhaustion($exhaustion);
return $ev->getAmount();
} }
public function getInventory(){ public function getInventory(){
@ -254,7 +265,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$this->foodTickTimer++; $this->foodTickTimer++;
if($this->foodTickTimer >= 80){ if($this->foodTickTimer >= 80){
$this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION)); $this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION));
$this->exhaust(3.0); $this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN);
$this->foodTickTimer = 0; $this->foodTickTimer = 0;
} }
}elseif($food === 0){ }elseif($food === 0){

View File

@ -0,0 +1,49 @@
<?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/
*
*
*/
namespace pocketmine\event\entity;
use pocketmine\block\Block;
use pocketmine\entity\Entity;
use pocketmine\item\FoodSource;
class EntityEatBlockEvent extends EntityEatEvent{
public function __construct(Entity $entity, FoodSource $foodSource){
if(!($foodSource instanceof Block)){
throw new \InvalidArgumentException("Food source must be a block");
}
parent::__construct($entity, $foodSource);
}
/**
* @return Block
*/
public function getResidue(){
return parent::getResidue();
}
public function setResidue($residue){
if(!($residue instanceof Block)){
throw new \InvalidArgumentException("Eating a Block can only result in a Block residue");
}
parent::setResidue($residue);
}
}

View File

@ -0,0 +1,99 @@
<?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/
*
*
*/
namespace pocketmine\event\entity;
use pocketmine\entity\Effect;
use pocketmine\entity\Entity;
use pocketmine\event\Cancellable;
use pocketmine\item\FoodSource;
class EntityEatEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
/** @var FoodSource */
private $foodSource;
/** @var int */
private $foodRestore;
/** @var float */
private $saturationRestore;
private $residue;
/** @var Effect[] */
private $additionalEffects;
public function __construct(Entity $entity, FoodSource $foodSource){
$this->entity = $entity;
$this->foodSource = $foodSource;
$this->foodRestore = $foodSource->getFoodRestore();
$this->saturationRestore = $foodSource->getSaturationRestore();
$this->residue = $foodSource->getResidue();
$this->additionalEffects = $foodSource->getAdditionalEffects();
}
public function getFoodSource(){
return $this->foodSource;
}
public function getFoodRestore() : int{
return $this->foodRestore;
}
public function setFoodRestore(int $foodRestore){
$this->foodRestore = $foodRestore;
}
public function getSaturationRestore() : float{
return $this->saturationRestore;
}
public function setSaturationRestore(float $saturationRestore){
$this->saturationRestore = $saturationRestore;
}
public function getResidue(){
return $this->residue;
}
public function setResidue($residue){
$this->residue = $residue;
}
/**
* @return Effect[]
*/
public function getAdditionalEffects(){
return $this->additionalEffects;
}
/**
* @param Effect[] $additionalEffects
*
* @throws \TypeError
*/
public function setAdditionalEffects(array $additionalEffects){
foreach($additionalEffects as $effect){
if(!($effect instanceof Effect)){
throw new \TypeError("Argument 1 passed to EntityEatEvent::setAdditionalEffects() must be an Effect array");
}
}
$this->additionalEffects = $additionalEffects;
}
}

View File

@ -0,0 +1,47 @@
<?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/
*
*
*/
namespace pocketmine\event\entity;
use pocketmine\entity\Entity;
use pocketmine\item\Food;
use pocketmine\item\FoodSource;
use pocketmine\item\Item;
class EntityEatItemEvent extends EntityEatEvent{
public function __construct(Entity $entity, Food $foodSource){
parent::__construct($entity, $foodSource);
}
/**
* @return Item
*/
public function getResidue(){
return parent::getResidue();
}
public function setResidue(FoodSource $residue){
if(!($residue instanceof Item)){
throw new \InvalidArgumentException("Eating an Item can only result in an Item residue");
}
parent::setResidue($residue);
}
}

View File

@ -0,0 +1,66 @@
<?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/
*
*
*/
namespace pocketmine\event\player;
use pocketmine\entity\Human;
use pocketmine\event\Cancellable;
use pocketmine\Player;
class PlayerExhaustEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
const CAUSE_ATTACK = 1;
const CAUSE_DAMAGE = 2;
const CAUSE_MINING = 3;
const CAUSE_HEALTH_REGEN = 4;
const CAUSE_POTION = 5;
const CAUSE_WALKING = 6;
const CAUSE_SNEAKING = 7;
const CAUSE_SWIMMING = 8;
const CAUSE_JUMPING = 10;
const CAUSE_CUSTOM = 11;
const CAUSE_FLAG_SPRINT = 0x10000;
/** @var float */
private $amount;
public function __construct(Human $human, float $amount, int $cause){
$this->player = $human;
$this->amount = $amount;
}
/**
* @return Human|Player
*/
public function getPlayer(){
return $this->player;
}
public function getAmount() : float{
return $this->amount;
}
public function setAmount(float $amount){
$this->amount = $amount;
}
}

View File

@ -39,7 +39,7 @@ class BeetrootSoup extends Food{
return 7.2; return 7.2;
} }
public function getResidue() : Item{ public function getResidue(){
return Item::get(Item::BOWL); return Item::get(Item::BOWL);
} }
} }

View File

@ -67,7 +67,7 @@ class Fish extends Food{
return 0; return 0;
} }
public function getAdditionEffects() : array{ public function getAdditionalEffects() : array{
return $this->meta === self::FISH_PUFFERFISH ? [ return $this->meta === self::FISH_PUFFERFISH ? [
Effect::getEffect(Effect::HUNGER)->setDuration(300)->setAmplifier(2), Effect::getEffect(Effect::HUNGER)->setDuration(300)->setAmplifier(2),
Effect::getEffect(Effect::NAUSEA)->setDuration(300)->setAmplifier(1), Effect::getEffect(Effect::NAUSEA)->setDuration(300)->setAmplifier(1),

View File

@ -21,18 +21,23 @@
namespace pocketmine\item; namespace pocketmine\item;
use pocketmine\entity\Effect; use pocketmine\entity\Entity;
use pocketmine\entity\Human; use pocketmine\entity\Human;
use pocketmine\event\entity\EntityEatItemEvent;
use pocketmine\network\protocol\EntityEventPacket; use pocketmine\network\protocol\EntityEventPacket;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\Server; use pocketmine\Server;
abstract class Food extends Item{ abstract class Food extends Item implements FoodSource{
public abstract function getFoodRestore() : int; public function canBeConsumed() : bool{
return true;
}
public abstract function getSaturationRestore() : float; public function canBeConsumedBy(Entity $entity){
return $entity instanceof Human and $entity->getFood() < $entity->getMaxFood();
}
public function getResidue() : Item{ public function getResidue(){
if($this->getCount() === 1){ if($this->getCount() === 1){
return Item::get(0); return Item::get(0);
}else{ }else{
@ -42,14 +47,11 @@ abstract class Food extends Item{
} }
} }
/** public function getAdditionalEffects() : array{
* @return Effect[]
*/
public function getAdditionEffects() : array{
return []; return [];
} }
public function onEat(Human $human){ public function onConsume(Entity $human){
$pk = new EntityEventPacket(); $pk = new EntityEventPacket();
$pk->eid = $human->getId(); $pk->eid = $human->getId();
$pk->event = EntityEventPacket::USE_ITEM; $pk->event = EntityEventPacket::USE_ITEM;
@ -58,11 +60,14 @@ abstract class Food extends Item{
} }
Server::broadcastPacket($human->getViewers(), $pk); Server::broadcastPacket($human->getViewers(), $pk);
$human->addSaturation($this->getSaturationRestore()); $ev = new EntityEatItemEvent($human, $this);
$human->addFood($this->getFoodRestore());
foreach($this->getAdditionEffects() as $effect){ $human->addSaturation($ev->getSaturationRestore());
$human->addFood($ev->getFoodRestore());
foreach($ev->getAdditionalEffects() as $effect){
$human->addEffect($effect); $human->addEffect($effect);
} }
$human->getInventory()->setItemInHand($this->getResidue());
$human->getInventory()->setItemInHand($ev->getResidue());
} }
} }

View File

@ -0,0 +1,37 @@
<?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/
*
*
*/
namespace pocketmine\item;
use pocketmine\entity\Effect;
interface FoodSource{
public function getFoodRestore() : int;
public function getSaturationRestore() : float;
public function getResidue();
/**
* @return Effect[]
*/
public function getAdditionalEffects() : array;
}

View File

@ -36,7 +36,7 @@ class GoldenApple extends Food{
return 9.6; return 9.6;
} }
public function getAdditionEffects() : array{ public function getAdditionalEffects() : array{
return $this->meta === 1 ? [ return $this->meta === 1 ? [
Effect::getEffect(Effect::REGENERATION)->setDuration(600)->setAmplifier(4), Effect::getEffect(Effect::REGENERATION)->setDuration(600)->setAmplifier(4),
Effect::getEffect(Effect::ABSORPTION)->setDuration(2400), Effect::getEffect(Effect::ABSORPTION)->setDuration(2400),

View File

@ -1042,6 +1042,17 @@ class Item{
return $this->block !== null and $this->block->canBePlaced(); return $this->block !== null and $this->block->canBePlaced();
} }
public function canBeConsumed() : bool{
return false;
}
public function canBeConsumedBy(Entity $entity) : bool{
return $this->canBeConsumed();
}
public function onConsume(Entity $entity){
}
public function getBlock() : Block{ public function getBlock() : Block{
if($this->block instanceof Block){ if($this->block instanceof Block){
return clone $this->block; return clone $this->block;

View File

@ -38,7 +38,7 @@ class MushroomStew extends Food{
return 7.2; return 7.2;
} }
public function getResidue() : Item{ public function getResidue(){
return Item::get(Item::BOWL); return Item::get(Item::BOWL);
} }
} }

View File

@ -21,8 +21,18 @@
namespace pocketmine\item; namespace pocketmine\item;
use pocketmine\entity\Entity;
class Potion extends Item{ class Potion extends Item{
public function __construct($meta = 0, $count = 1){ public function __construct($meta = 0, $count = 1){
parent::__construct(self::POTION, $meta, $count, "Potion"); parent::__construct(self::POTION, $meta, $count, "Potion");
} }
public function canBeConsumed() : bool{
return true;
}
public function onConsume(Entity $entity){
// TODO: Implement potions
}
} }

View File

@ -36,7 +36,7 @@ class RawChicken extends Food{
return 1.2; return 1.2;
} }
public function getAdditionEffects() : array{ public function getAdditionalEffects() : array{
if(mt_rand(0, 9) < 3){ if(mt_rand(0, 9) < 3){
return Effect::getEffect(Effect::HUNGER)->setDuration(600); return Effect::getEffect(Effect::HUNGER)->setDuration(600);
} }

View File

@ -36,7 +36,7 @@ class SpiderEye extends Food{
return 3.2; return 3.2;
} }
public function getAdditionEffects() : array{ public function getAdditionalEffects() : array{
return [Effect::getEffect(Effect::POISON)->setDuration(80)]; return [Effect::getEffect(Effect::POISON)->setDuration(80)];
} }
} }