New food system from official repo is coming
This commit is contained in:
parent
e29ce18e24
commit
67a7486213
26 changed files with 636 additions and 115 deletions
|
|
@ -43,6 +43,7 @@ use pocketmine\event\block\SignChangeEvent;
|
|||
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
||||
use pocketmine\event\entity\EntityDamageByEntityEvent;
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\event\entity\EntityEatItemEvent;
|
||||
use pocketmine\event\entity\EntityRegainHealthEvent;
|
||||
use pocketmine\event\entity\EntityShootBowEvent;
|
||||
use pocketmine\event\entity\ProjectileLaunchEvent;
|
||||
|
|
@ -90,6 +91,7 @@ use pocketmine\inventory\PlayerInventory;
|
|||
use pocketmine\inventory\ShapedRecipe;
|
||||
use pocketmine\inventory\ShapelessRecipe;
|
||||
use pocketmine\inventory\SimpleTransactionGroup;
|
||||
use pocketmine\item\FoodSource;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\Potion;
|
||||
use pocketmine\level\ChunkLoader;
|
||||
|
|
@ -1996,6 +1998,14 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
|||
return;
|
||||
}
|
||||
|
||||
if($slot instanceof FoodSource){
|
||||
$this->server->getPluginManager()->callEvent($ev = new EntityEatItemEvent($this, $slot));
|
||||
if($ev->isCancelled()){
|
||||
$this->inventory->sendContents($this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$pk = new EntityEventPacket();
|
||||
$pk->eid = $this->getId();
|
||||
$pk->event = EntityEventPacket::USE_ITEM;
|
||||
|
|
|
|||
49
src/pocketmine/event/entity/EntityEatBlockEvent.php
Normal file
49
src/pocketmine/event/entity/EntityEatBlockEvent.php
Normal 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);
|
||||
}
|
||||
}
|
||||
99
src/pocketmine/event/entity/EntityEatEvent.php
Normal file
99
src/pocketmine/event/entity/EntityEatEvent.php
Normal 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;
|
||||
}
|
||||
}
|
||||
46
src/pocketmine/event/entity/EntityEatItemEvent.php
Normal file
46
src/pocketmine/event/entity/EntityEatItemEvent.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?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\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($residue){
|
||||
if(!($residue instanceof Item)){
|
||||
throw new \InvalidArgumentException("Eating an Item can only result in an Item residue");
|
||||
}
|
||||
parent::setResidue($residue);
|
||||
}
|
||||
}
|
||||
|
|
@ -22,9 +22,16 @@
|
|||
namespace pocketmine\item;
|
||||
|
||||
|
||||
class Apple extends Item{
|
||||
class Apple extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::APPLE, 0, $count, "Apple");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 4;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 2.4;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,28 +2,36 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* _____ _____ __ _ _ _____ __ __ _____
|
||||
* / ___| | ____| | \ | | | | / ___/ \ \ / / / ___/
|
||||
* | | | |__ | \| | | | | |___ \ \/ / | |___
|
||||
* | | _ | __| | |\ | | | \___ \ \ / \___ \
|
||||
* | |_| | | |___ | | \ | | | ___| | / / ___| |
|
||||
* \_____/ |_____| |_| \_| |_| /_____/ /_/ /_____/
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 iTX Technologies
|
||||
* @link https://mcper.cn
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
*/
|
||||
|
||||
namespace pocketmine\item;
|
||||
|
||||
class BakedPotato extends Item {
|
||||
public function __construct($meta = 0, $count = 1) {
|
||||
class BakedPotato extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::BAKED_POTATO, $meta, $count, "Baked Potato");
|
||||
}
|
||||
|
||||
}
|
||||
public function getFoodRestore() : int{
|
||||
return 5;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 7.2;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,28 +2,36 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* _____ _____ __ _ _ _____ __ __ _____
|
||||
* / ___| | ____| | \ | | | | / ___/ \ \ / / / ___/
|
||||
* | | | |__ | \| | | | | |___ \ \/ / | |___
|
||||
* | | _ | __| | |\ | | | \___ \ \ / \___ \
|
||||
* | |_| | | |___ | | \ | | | ___| | / / ___| |
|
||||
* \_____/ |_____| |_| \_| |_| /_____/ /_/ /_____/
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 iTX Technologies
|
||||
* @link https://mcper.cn
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
*/
|
||||
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Beetroot extends Item {
|
||||
public function __construct($meta = 0, $count = 1) {
|
||||
class Beetroot extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::BEETROOT, $meta, $count, "Beetroot");
|
||||
}
|
||||
|
||||
}
|
||||
public function getFoodRestore() : int{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 1.2;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,10 +21,17 @@
|
|||
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Bread extends Item{
|
||||
class Bread extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::BREAD, $meta, $count, "Bread");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 5;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,9 +23,17 @@ namespace pocketmine\item;
|
|||
|
||||
use pocketmine\block\Block;
|
||||
|
||||
class Carrot extends Item{
|
||||
class Carrot extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = Block::get(Item::CARROT_BLOCK);
|
||||
parent::__construct(self::CARROT, 0, $count, "Carrot");
|
||||
}
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 4.8;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
|
|
@ -15,16 +15,23 @@
|
|||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\item;
|
||||
|
||||
class CookedChicken extends Item{
|
||||
class CookedChicken extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::COOKED_CHICKEN, $meta, $count, "Cooked Chicken");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 6;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 7.2;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
|
|
@ -15,19 +15,22 @@
|
|||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\item;
|
||||
|
||||
|
||||
class CookedFish extends Item{
|
||||
class CookedFish extends Fish{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::COOKED_FISH, $meta, $count, "Cooked Fish");
|
||||
if($this->meta === 1){
|
||||
$this->name = "Cooked Salmon";
|
||||
}
|
||||
Food::__construct(self::COOKED_FISH, $meta, $count, $meta === self::FISH_SALMON ? "Cooked Salmon" : "Cooked Fish");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return $this->meta === self::FISH_SALMON ? 6 : 5;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return $this->meta === self::FISH_SALMON ? 9.6 : 6;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
|
|
@ -15,16 +15,23 @@
|
|||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\item;
|
||||
|
||||
class CookedPorkchop extends Item{
|
||||
class CookedPorkchop extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::COOKED_PORKCHOP, $meta, $count, "Cooked Porkchop");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 8;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 12.8;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,16 @@
|
|||
|
||||
namespace pocketmine\item;
|
||||
|
||||
class CookedRabbit extends Item {
|
||||
public function __construct($meta = 0, $count =1){
|
||||
parent::__construct(self::COOKED_RABBIT, $meta, $count, "Cooked Rabbit");
|
||||
}
|
||||
class CookedRabbit extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::COOKED_RABBIT, $meta, $count, "Cooked Rabbit");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 5;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
|
|
@ -15,16 +15,23 @@
|
|||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Cookie extends Item{
|
||||
class Cookie extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::COOKIE, $meta, $count, "Cookie");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 0.4;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
|
|
@ -15,23 +15,63 @@
|
|||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\entity\Effect;
|
||||
|
||||
class Fish extends Food{
|
||||
const FISH_FISH = 0;
|
||||
const FISH_SALMON = 1;
|
||||
const FISH_CLOWNFISH = 2;
|
||||
const FISH_PUFFERFISH = 3;
|
||||
|
||||
class Fish extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::RAW_FISH, $meta, $count, "Raw Fish");
|
||||
if($this->meta === 1){
|
||||
$this->name = "Raw Salmon";
|
||||
}elseif($this->meta === 2){
|
||||
$this->name = "Clownfish";
|
||||
}elseif($this->meta === 3){
|
||||
$this->name = "Pufferfish";
|
||||
$name = "Raw Fish";
|
||||
if($this->meta === self::FISH_SALMON){
|
||||
$name = "Raw Salmon";
|
||||
}elseif($this->meta === self::FISH_CLOWNFISH){
|
||||
$name = "Clownfish";
|
||||
}elseif($this->meta === self::FISH_PUFFERFISH){
|
||||
$name = "Pufferfish";
|
||||
}
|
||||
parent::__construct(self::RAW_FISH, $meta, $count, $name);
|
||||
}
|
||||
|
||||
}
|
||||
public function getFoodRestore() : int{
|
||||
if($this->meta === self::FISH_FISH){
|
||||
return 2;
|
||||
}elseif($this->meta === self::FISH_SALMON){
|
||||
return 2;
|
||||
}elseif($this->meta === self::FISH_CLOWNFISH){
|
||||
return 1;
|
||||
}elseif($this->meta === self::FISH_PUFFERFISH){
|
||||
return 1.2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
if($this->meta === self::FISH_FISH){
|
||||
return 0.4;
|
||||
}elseif($this->meta === self::FISH_SALMON){
|
||||
return 0.4;
|
||||
}elseif($this->meta === self::FISH_CLOWNFISH){
|
||||
return 0.2;
|
||||
}elseif($this->meta === self::FISH_PUFFERFISH){
|
||||
return 0.2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getAdditionalEffects() : array{
|
||||
return $this->meta === self::FISH_PUFFERFISH ? [
|
||||
Effect::getEffect(Effect::HUNGER)->setDuration(300)->setAmplifier(2),
|
||||
Effect::getEffect(Effect::NAUSEA)->setDuration(300)->setAmplifier(1),
|
||||
Effect::getEffect(Effect::POISON)->setDuration(1200)->setAmplifier(3),
|
||||
] : [];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
73
src/pocketmine/item/Food.php
Normal file
73
src/pocketmine/item/Food.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?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\Entity;
|
||||
use pocketmine\entity\Human;
|
||||
use pocketmine\event\entity\EntityEatItemEvent;
|
||||
use pocketmine\network\protocol\EntityEventPacket;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
|
||||
abstract class Food extends Item implements FoodSource{
|
||||
public function canBeConsumed() : bool{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canBeConsumedBy(Entity $entity) : bool{
|
||||
return $entity instanceof Human and $entity->getFood() < $entity->getMaxFood();
|
||||
}
|
||||
|
||||
public function getResidue(){
|
||||
if($this->getCount() === 1){
|
||||
return Item::get(0);
|
||||
}else{
|
||||
$new = clone $this;
|
||||
$new->count--;
|
||||
return $new;
|
||||
}
|
||||
}
|
||||
|
||||
public function getAdditionalEffects() : array{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function onConsume(Entity $human){
|
||||
$pk = new EntityEventPacket();
|
||||
$pk->eid = $human->getId();
|
||||
$pk->event = EntityEventPacket::USE_ITEM;
|
||||
if($human instanceof Player){
|
||||
$human->dataPacket($pk);
|
||||
}
|
||||
Server::broadcastPacket($human->getViewers(), $pk);
|
||||
|
||||
$ev = new EntityEatItemEvent($human, $this);
|
||||
|
||||
$human->addSaturation($ev->getSaturationRestore());
|
||||
$human->addFood($ev->getFoodRestore());
|
||||
foreach($ev->getAdditionalEffects() as $effect){
|
||||
$human->addEffect($effect);
|
||||
}
|
||||
|
||||
$human->getInventory()->setItemInHand($ev->getResidue());
|
||||
}
|
||||
}
|
||||
37
src/pocketmine/item/FoodSource.php
Normal file
37
src/pocketmine/item/FoodSource.php
Normal 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;
|
||||
}
|
||||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
|
|
@ -15,16 +15,37 @@
|
|||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\item;
|
||||
|
||||
class GoldenApple extends Item{
|
||||
use pocketmine\entity\Effect;
|
||||
|
||||
class GoldenApple extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::GOLDEN_APPLE, $meta, $count, (($meta == 0 ? "Golden Apple" : "Enchanted Golden Apple")));
|
||||
parent::__construct(self::GOLDEN_APPLE, $meta, $count, ($meta === 1 ? "Enchanted " : "") . "Golden Apple");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 4;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 9.6;
|
||||
}
|
||||
|
||||
public function getAdditionalEffects() : array{
|
||||
return $this->meta === 1 ? [
|
||||
Effect::getEffect(Effect::REGENERATION)->setDuration(600)->setAmplifier(4),
|
||||
Effect::getEffect(Effect::ABSORPTION)->setDuration(2400),
|
||||
Effect::getEffect(Effect::DAMAGE_RESISTANCE)->setDuration(6000),
|
||||
Effect::getEffect(Effect::FIRE_RESISTANCE)->setDuration(6000),
|
||||
] : [
|
||||
Effect::getEffect(Effect::REGENERATION)->setDuration(100)->setAmplifier(1),
|
||||
Effect::getEffect(Effect::ABSORPTION)->setDuration(2400)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,16 @@
|
|||
|
||||
namespace pocketmine\item;
|
||||
|
||||
class GoldenCarrot extends Item {
|
||||
public function __construct($meta = 0, $count =1){
|
||||
parent::__construct(self::GOLDEN_CARROT, $meta, $count, "Golden Carrot");
|
||||
}
|
||||
class GoldenCarrot extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::GOLDEN_CARROT, $meta, $count, "Golden Carrot");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 6;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 14.4;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
|
|
@ -15,16 +15,23 @@
|
|||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Melon extends Item{
|
||||
class Melon extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::MELON, $meta, $count, "Melon");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 1.2;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
|
|
@ -15,19 +15,30 @@
|
|||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\item;
|
||||
|
||||
|
||||
class MushroomStew extends Item{
|
||||
class MushroomStew extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::MUSHROOM_STEW, 0, $count, "Mushroom Stew");
|
||||
}
|
||||
|
||||
public function getMaxStackSize() : int {
|
||||
public function getMaxStackSize(){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 6;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 7.2;
|
||||
}
|
||||
|
||||
public function getResidue(){
|
||||
return Item::get(Item::BOWL);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,10 +21,17 @@
|
|||
|
||||
namespace pocketmine\item;
|
||||
|
||||
class PumpkinPie extends Item{
|
||||
class PumpkinPie extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::PUMPKIN_PIE, $meta, $count, "Pumpkin Pie");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 8;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 4.8;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,10 +21,17 @@
|
|||
|
||||
namespace pocketmine\item;
|
||||
|
||||
class RawBeef extends Item{
|
||||
class RawBeef extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::RAW_BEEF, $meta, $count, "Raw Beef");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 1.8;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,10 +21,25 @@
|
|||
|
||||
namespace pocketmine\item;
|
||||
|
||||
class RawChicken extends Item{
|
||||
use pocketmine\entity\Effect;
|
||||
|
||||
class RawChicken extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::RAW_CHICKEN, $meta, $count, "Raw Chicken");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 1.2;
|
||||
}
|
||||
|
||||
public function getAdditionalEffects() : array{
|
||||
if(mt_rand(0, 9) < 3){
|
||||
return Effect::getEffect(Effect::HUNGER)->setDuration(600);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,22 @@
|
|||
|
||||
namespace pocketmine\item;
|
||||
|
||||
class SpiderEye extends Item {
|
||||
public function __construct($meta = 0, $count =1){
|
||||
use pocketmine\entity\Effect;
|
||||
|
||||
class SpiderEye extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::SPIDER_EYE, $meta, $count, "Spider Eye");
|
||||
}
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 3.2;
|
||||
}
|
||||
|
||||
public function getAdditionalEffects() : array{
|
||||
return [Effect::getEffect(Effect::POISON)->setDuration(80)];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
|
|
@ -15,16 +15,23 @@
|
|||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Steak extends Item{
|
||||
class Steak extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::STEAK, $meta, $count, "Steak");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 8;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 12.8;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue