mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Merge branch 'moar-typehints'
This commit is contained in:
@ -84,32 +84,32 @@ abstract class BaseInventory implements Inventory{
|
||||
$this->slots = [];
|
||||
}
|
||||
|
||||
public function getSize(){
|
||||
public function getSize() : int{
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
public function setSize($size){
|
||||
$this->size = (int) $size;
|
||||
public function setSize(int $size){
|
||||
$this->size = $size;
|
||||
}
|
||||
|
||||
public function getMaxStackSize(){
|
||||
public function getMaxStackSize() : int{
|
||||
return $this->maxStackSize;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
public function getName() : string{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getTitle(){
|
||||
public function getTitle() : string{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function getItem($index){
|
||||
public function getItem(int $index) : Item{
|
||||
assert($index >= 0, "Inventory slot should not be negative");
|
||||
return isset($this->slots[$index]) ? clone $this->slots[$index] : Item::get(Item::AIR, 0, 0);
|
||||
}
|
||||
|
||||
public function getContents(){
|
||||
public function getContents() : array{
|
||||
return $this->slots;
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ abstract class BaseInventory implements Inventory{
|
||||
}
|
||||
}
|
||||
|
||||
public function setItem($index, Item $item){
|
||||
public function setItem(int $index, Item $item) : bool{
|
||||
$item = clone $item;
|
||||
if($index < 0 or $index >= $this->size){
|
||||
return false;
|
||||
@ -159,7 +159,7 @@ abstract class BaseInventory implements Inventory{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function contains(Item $item){
|
||||
public function contains(Item $item) : bool{
|
||||
$count = max(1, $item->getCount());
|
||||
$checkDamage = !$item->hasAnyDamageValue();
|
||||
$checkTags = $item->hasCompoundTag();
|
||||
@ -175,7 +175,7 @@ abstract class BaseInventory implements Inventory{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function all(Item $item){
|
||||
public function all(Item $item) : array{
|
||||
$slots = [];
|
||||
$checkDamage = !$item->hasAnyDamageValue();
|
||||
$checkTags = $item->hasCompoundTag();
|
||||
@ -199,7 +199,7 @@ abstract class BaseInventory implements Inventory{
|
||||
}
|
||||
}
|
||||
|
||||
public function first(Item $item){
|
||||
public function first(Item $item) : int{
|
||||
$count = max(1, $item->getCount());
|
||||
$checkDamage = !$item->hasAnyDamageValue();
|
||||
$checkTags = $item->hasCompoundTag();
|
||||
@ -213,7 +213,7 @@ abstract class BaseInventory implements Inventory{
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function firstEmpty(){
|
||||
public function firstEmpty() : int{
|
||||
for($i = 0; $i < $this->size; ++$i){
|
||||
if($this->getItem($i)->getId() === Item::AIR){
|
||||
return $i;
|
||||
@ -223,7 +223,7 @@ abstract class BaseInventory implements Inventory{
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function canAddItem(Item $item){
|
||||
public function canAddItem(Item $item) : bool{
|
||||
$item = clone $item;
|
||||
$checkDamage = !$item->hasAnyDamageValue();
|
||||
$checkTags = $item->hasCompoundTag();
|
||||
@ -245,7 +245,7 @@ abstract class BaseInventory implements Inventory{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function addItem(Item ...$slots){
|
||||
public function addItem(Item ...$slots) : array{
|
||||
/** @var Item[] $itemSlots */
|
||||
/** @var Item[] $slots */
|
||||
$itemSlots = [];
|
||||
@ -302,7 +302,7 @@ abstract class BaseInventory implements Inventory{
|
||||
return $itemSlots;
|
||||
}
|
||||
|
||||
public function removeItem(Item ...$slots){
|
||||
public function removeItem(Item ...$slots) : array{
|
||||
/** @var Item[] $itemSlots */
|
||||
/** @var Item[] $slots */
|
||||
$itemSlots = [];
|
||||
@ -338,7 +338,7 @@ abstract class BaseInventory implements Inventory{
|
||||
return $itemSlots;
|
||||
}
|
||||
|
||||
public function clear($index){
|
||||
public function clear(int $index) : bool{
|
||||
if(isset($this->slots[$index])){
|
||||
$item = Item::get(Item::AIR, 0, 0);
|
||||
$old = $this->slots[$index];
|
||||
@ -372,7 +372,7 @@ abstract class BaseInventory implements Inventory{
|
||||
/**
|
||||
* @return Player[]
|
||||
*/
|
||||
public function getViewers(){
|
||||
public function getViewers() : array{
|
||||
return $this->viewers;
|
||||
}
|
||||
|
||||
@ -380,11 +380,11 @@ abstract class BaseInventory implements Inventory{
|
||||
return $this->holder;
|
||||
}
|
||||
|
||||
public function setMaxStackSize($size){
|
||||
$this->maxStackSize = (int) $size;
|
||||
public function setMaxStackSize(int $size){
|
||||
$this->maxStackSize = $size;
|
||||
}
|
||||
|
||||
public function open(Player $who){
|
||||
public function open(Player $who) : bool{
|
||||
$who->getServer()->getPluginManager()->callEvent($ev = new InventoryOpenEvent($this, $who));
|
||||
if($ev->isCancelled()){
|
||||
return false;
|
||||
@ -459,7 +459,7 @@ abstract class BaseInventory implements Inventory{
|
||||
}
|
||||
}
|
||||
|
||||
public function getType(){
|
||||
public function getType() : InventoryType{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
|
@ -43,31 +43,31 @@ class BaseTransaction implements Transaction{
|
||||
* @param Item $sourceItem
|
||||
* @param Item $targetItem
|
||||
*/
|
||||
public function __construct(Inventory $inventory, $slot, Item $sourceItem, Item $targetItem){
|
||||
public function __construct(Inventory $inventory, int $slot, Item $sourceItem, Item $targetItem){
|
||||
$this->inventory = $inventory;
|
||||
$this->slot = (int) $slot;
|
||||
$this->slot = $slot;
|
||||
$this->sourceItem = clone $sourceItem;
|
||||
$this->targetItem = clone $targetItem;
|
||||
$this->creationTime = microtime(true);
|
||||
}
|
||||
|
||||
public function getCreationTime(){
|
||||
public function getCreationTime() : float{
|
||||
return $this->creationTime;
|
||||
}
|
||||
|
||||
public function getInventory(){
|
||||
public function getInventory() : Inventory{
|
||||
return $this->inventory;
|
||||
}
|
||||
|
||||
public function getSlot(){
|
||||
public function getSlot() : int{
|
||||
return $this->slot;
|
||||
}
|
||||
|
||||
public function getSourceItem(){
|
||||
public function getSourceItem() : Item{
|
||||
return clone $this->sourceItem;
|
||||
}
|
||||
|
||||
public function getTargetItem(){
|
||||
public function getTargetItem() : Item{
|
||||
return clone $this->targetItem;
|
||||
}
|
||||
}
|
@ -56,7 +56,7 @@ class CraftingInventory extends BaseInventory{
|
||||
return $this->resultInventory;
|
||||
}
|
||||
|
||||
public function getSize(){
|
||||
public function getSize() : int{
|
||||
return $this->getResultInventory()->getSize() + parent::getSize();
|
||||
}
|
||||
}
|
@ -160,14 +160,14 @@ class CraftingManager{
|
||||
/**
|
||||
* @return Recipe[]
|
||||
*/
|
||||
public function getRecipes(){
|
||||
public function getRecipes() : array{
|
||||
return $this->recipes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FurnaceRecipe[]
|
||||
*/
|
||||
public function getFurnaceRecipes(){
|
||||
public function getFurnaceRecipes() : array{
|
||||
return $this->furnaceRecipes;
|
||||
}
|
||||
|
||||
@ -238,7 +238,7 @@ class CraftingManager{
|
||||
* @param ShapelessRecipe $recipe
|
||||
* @return bool
|
||||
*/
|
||||
public function matchRecipe(ShapelessRecipe $recipe){
|
||||
public function matchRecipe(ShapelessRecipe $recipe) : bool{
|
||||
if(!isset($this->recipeLookup[$idx = $recipe->getResult()->getId() . ":" . $recipe->getResult()->getDamage()])){
|
||||
return false;
|
||||
}
|
||||
|
@ -50,19 +50,19 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
|
||||
return $this->left->getHolder();
|
||||
}
|
||||
|
||||
public function getItem($index){
|
||||
public function getItem(int $index) : Item{
|
||||
return $index < $this->left->getSize() ? $this->left->getItem($index) : $this->right->getItem($index - $this->right->getSize());
|
||||
}
|
||||
|
||||
public function setItem($index, Item $item){
|
||||
public function setItem(int $index, Item $item) : bool{
|
||||
return $index < $this->left->getSize() ? $this->left->setItem($index, $item) : $this->right->setItem($index - $this->right->getSize(), $item);
|
||||
}
|
||||
|
||||
public function clear($index){
|
||||
public function clear(int $index) : bool{
|
||||
return $index < $this->left->getSize() ? $this->left->clear($index) : $this->right->clear($index - $this->right->getSize());
|
||||
}
|
||||
|
||||
public function getContents(){
|
||||
public function getContents() : array{
|
||||
$contents = [];
|
||||
for($i = 0; $i < $this->getSize(); ++$i){
|
||||
$contents[$i] = $this->getItem($i);
|
||||
@ -129,14 +129,14 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
|
||||
/**
|
||||
* @return ChestInventory
|
||||
*/
|
||||
public function getLeftSide(){
|
||||
public function getLeftSide() : ChestInventory{
|
||||
return $this->left;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ChestInventory
|
||||
*/
|
||||
public function getRightSide(){
|
||||
public function getRightSide() : ChestInventory{
|
||||
return $this->right;
|
||||
}
|
||||
}
|
||||
|
@ -41,21 +41,21 @@ class FurnaceInventory extends ContainerInventory{
|
||||
/**
|
||||
* @return Item
|
||||
*/
|
||||
public function getResult(){
|
||||
public function getResult() : Item{
|
||||
return $this->getItem(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Item
|
||||
*/
|
||||
public function getFuel(){
|
||||
public function getFuel() : Item{
|
||||
return $this->getItem(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Item
|
||||
*/
|
||||
public function getSmelting(){
|
||||
public function getSmelting() : Item{
|
||||
return $this->getItem(0);
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ class FurnaceInventory extends ContainerInventory{
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function setResult(Item $item){
|
||||
public function setResult(Item $item) : bool{
|
||||
return $this->setItem(2, $item);
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ class FurnaceInventory extends ContainerInventory{
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function setFuel(Item $item){
|
||||
public function setFuel(Item $item) : bool{
|
||||
return $this->setItem(1, $item);
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ class FurnaceInventory extends ContainerInventory{
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function setSmelting(Item $item){
|
||||
public function setSmelting(Item $item) : bool{
|
||||
return $this->setItem(0, $item);
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ use pocketmine\utils\UUID;
|
||||
|
||||
class FurnaceRecipe implements Recipe{
|
||||
|
||||
/** @var UUID|null */
|
||||
private $id = null;
|
||||
|
||||
/** @var Item */
|
||||
@ -46,10 +47,16 @@ class FurnaceRecipe implements Recipe{
|
||||
$this->ingredient = clone $ingredient;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UUID|null
|
||||
*/
|
||||
public function getId(){
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UUID $id
|
||||
*/
|
||||
public function setId(UUID $id){
|
||||
if($this->id !== null){
|
||||
throw new \InvalidStateException("Id is already set");
|
||||
@ -68,14 +75,14 @@ class FurnaceRecipe implements Recipe{
|
||||
/**
|
||||
* @return Item
|
||||
*/
|
||||
public function getInput(){
|
||||
public function getInput() : Item{
|
||||
return clone $this->ingredient;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Item
|
||||
*/
|
||||
public function getResult(){
|
||||
public function getResult() : Item{
|
||||
return clone $this->output;
|
||||
}
|
||||
|
||||
|
@ -32,37 +32,48 @@ use pocketmine\Player;
|
||||
interface Inventory{
|
||||
const MAX_STACK = 64;
|
||||
|
||||
public function getSize();
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getSize() : int;
|
||||
|
||||
public function getMaxStackSize();
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxStackSize() : int;
|
||||
|
||||
/**
|
||||
* @param int $size
|
||||
*/
|
||||
public function setMaxStackSize($size);
|
||||
public function setMaxStackSize(int $size);
|
||||
|
||||
public function getName();
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName() : string;
|
||||
|
||||
public function getTitle();
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() : string;
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function getItem($index);
|
||||
public function getItem(int $index) : Item;
|
||||
|
||||
/**
|
||||
* Puts an Item in a slot.
|
||||
* If a plugin refuses the update or $index is invalid, it'll return false
|
||||
* If a source Player is specified, it won't send a Inventory update to it
|
||||
*
|
||||
* @param int $index
|
||||
* @param Item $item
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function setItem($index, Item $item);
|
||||
public function setItem(int $index, Item $item) : bool;
|
||||
|
||||
/**
|
||||
* Stores the given Items in the inventory. This will try to fill
|
||||
@ -74,7 +85,7 @@ interface Inventory{
|
||||
*
|
||||
* @return Item[]
|
||||
*/
|
||||
public function addItem(Item ...$slots);
|
||||
public function addItem(Item ...$slots) : array;
|
||||
|
||||
/**
|
||||
* Checks if a given Item can be added to the inventory
|
||||
@ -83,7 +94,7 @@ interface Inventory{
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canAddItem(Item $item);
|
||||
public function canAddItem(Item $item) : bool;
|
||||
|
||||
/**
|
||||
* Removes the given Item from the inventory.
|
||||
@ -93,12 +104,12 @@ interface Inventory{
|
||||
*
|
||||
* @return Item[]
|
||||
*/
|
||||
public function removeItem(Item ...$slots);
|
||||
public function removeItem(Item ...$slots) : array;
|
||||
|
||||
/**
|
||||
* @return Item[]
|
||||
*/
|
||||
public function getContents();
|
||||
public function getContents() : array;
|
||||
|
||||
/**
|
||||
* @param Item[] $items
|
||||
@ -124,7 +135,7 @@ interface Inventory{
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function contains(Item $item);
|
||||
public function contains(Item $item) : bool;
|
||||
|
||||
/**
|
||||
* Will return all the Items that has the same id and metadata (if not null).
|
||||
@ -134,7 +145,7 @@ interface Inventory{
|
||||
*
|
||||
* @return Item[]
|
||||
*/
|
||||
public function all(Item $item);
|
||||
public function all(Item $item) : array;
|
||||
|
||||
/**
|
||||
* Will return the first slot has the same id and metadata (if not null) as the Item.
|
||||
@ -144,14 +155,14 @@ interface Inventory{
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function first(Item $item);
|
||||
public function first(Item $item) : int;
|
||||
|
||||
/**
|
||||
* Returns the first empty slot, or -1 if not found
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function firstEmpty();
|
||||
public function firstEmpty() : int;
|
||||
|
||||
/**
|
||||
* Will remove all the Items that has the same id and metadata (if not null)
|
||||
@ -167,7 +178,7 @@ interface Inventory{
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clear($index);
|
||||
public function clear(int $index) : bool;
|
||||
|
||||
/**
|
||||
* Clears all the slots
|
||||
@ -180,12 +191,12 @@ interface Inventory{
|
||||
*
|
||||
* @return Player[]
|
||||
*/
|
||||
public function getViewers();
|
||||
public function getViewers() : array;
|
||||
|
||||
/**
|
||||
* @return InventoryType
|
||||
*/
|
||||
public function getType();
|
||||
public function getType() : InventoryType;
|
||||
|
||||
/**
|
||||
* @return InventoryHolder
|
||||
@ -204,7 +215,7 @@ interface Inventory{
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function open(Player $who);
|
||||
public function open(Player $who) : bool;
|
||||
|
||||
public function close(Player $who);
|
||||
|
||||
|
@ -91,21 +91,21 @@ class InventoryType{
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getDefaultSize(){
|
||||
public function getDefaultSize() : int{
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultTitle(){
|
||||
public function getDefaultTitle() : string{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getNetworkType(){
|
||||
public function getNetworkType() : int{
|
||||
return $this->typeId;
|
||||
}
|
||||
}
|
@ -47,11 +47,11 @@ class PlayerInventory extends BaseInventory{
|
||||
parent::__construct($player, InventoryType::get(InventoryType::PLAYER));
|
||||
}
|
||||
|
||||
public function getSize(){
|
||||
public function getSize() : int{
|
||||
return parent::getSize() - 4; //Remove armor slots
|
||||
}
|
||||
|
||||
public function setSize($size){
|
||||
public function setSize(int $size){
|
||||
parent::setSize($size + 4);
|
||||
$this->sendContents($this->getViewers());
|
||||
}
|
||||
@ -316,7 +316,7 @@ class PlayerInventory extends BaseInventory{
|
||||
return $this->setItem($this->getSize() + 3, $boots);
|
||||
}
|
||||
|
||||
public function setItem($index, Item $item){
|
||||
public function setItem(int $index, Item $item) : bool{
|
||||
if($index < 0 or $index >= $this->size){
|
||||
return false;
|
||||
}elseif($item->getId() === 0 or $item->getCount() <= 0){
|
||||
@ -347,7 +347,7 @@ class PlayerInventory extends BaseInventory{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function clear($index){
|
||||
public function clear(int $index) : bool{
|
||||
if(isset($this->slots[$index])){
|
||||
$item = Item::get(Item::AIR, 0, 0);
|
||||
$old = $this->slots[$index];
|
||||
|
@ -31,14 +31,17 @@ interface Recipe{
|
||||
/**
|
||||
* @return Item
|
||||
*/
|
||||
public function getResult();
|
||||
public function getResult() : Item;
|
||||
|
||||
public function registerToCraftingManager();
|
||||
|
||||
/**
|
||||
* @return UUID
|
||||
* @return UUID|null
|
||||
*/
|
||||
public function getId();
|
||||
|
||||
/**
|
||||
* @param UUID $id
|
||||
*/
|
||||
public function setId(UUID $id);
|
||||
}
|
@ -32,6 +32,7 @@ class ShapedRecipe implements Recipe{
|
||||
/** @var Item */
|
||||
private $output;
|
||||
|
||||
/** @var UUID|null */
|
||||
private $id = null;
|
||||
|
||||
/** @var string[] */
|
||||
@ -49,7 +50,7 @@ class ShapedRecipe implements Recipe{
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct(Item $result, $height, $width){
|
||||
public function __construct(Item $result, int $height, int $width){
|
||||
for($h = 0; $h < $height; $h++){
|
||||
if($width === 0 or $width > 3){
|
||||
throw new \InvalidStateException("Crafting rows should be 1, 2, 3 wide, not $width");
|
||||
@ -60,18 +61,24 @@ class ShapedRecipe implements Recipe{
|
||||
$this->output = clone $result;
|
||||
}
|
||||
|
||||
public function getWidth(){
|
||||
public function getWidth() : int{
|
||||
return count($this->ingredients[0]);
|
||||
}
|
||||
|
||||
public function getHeight(){
|
||||
public function getHeight() : int{
|
||||
return count($this->ingredients);
|
||||
}
|
||||
|
||||
public function getResult(){
|
||||
/**
|
||||
* @return Item
|
||||
*/
|
||||
public function getResult() : Item{
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UUID|null
|
||||
*/
|
||||
public function getId(){
|
||||
return $this->id;
|
||||
}
|
||||
@ -84,7 +91,14 @@ class ShapedRecipe implements Recipe{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function addIngredient($x, $y, Item $item){
|
||||
/**
|
||||
* @param int $x
|
||||
* @param int $y
|
||||
* @param Item $item
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addIngredient(int $x, int $y, Item $item){
|
||||
$this->ingredients[$y][$x] = clone $item;
|
||||
return $this;
|
||||
}
|
||||
@ -96,7 +110,7 @@ class ShapedRecipe implements Recipe{
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setIngredient($key, Item $item){
|
||||
public function setIngredient(string $key, Item $item){
|
||||
if(!array_key_exists($key, $this->shape)){
|
||||
throw new \Exception("Symbol does not appear in the shape: " . $key);
|
||||
}
|
||||
@ -106,7 +120,11 @@ class ShapedRecipe implements Recipe{
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function fixRecipe($key, $item){
|
||||
/**
|
||||
* @param string $key
|
||||
* @param Item $item
|
||||
*/
|
||||
protected function fixRecipe(string $key, Item $item){
|
||||
foreach($this->shapeItems[$key] as $entry){
|
||||
$this->ingredients[$entry->y][$entry->x] = clone $item;
|
||||
}
|
||||
@ -115,7 +133,7 @@ class ShapedRecipe implements Recipe{
|
||||
/**
|
||||
* @return Item[][]
|
||||
*/
|
||||
public function getIngredientMap(){
|
||||
public function getIngredientMap() : array{
|
||||
$ingredients = [];
|
||||
foreach($this->ingredients as $y => $row){
|
||||
$ingredients[$y] = [];
|
||||
@ -132,18 +150,19 @@ class ShapedRecipe implements Recipe{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $x
|
||||
* @param $y
|
||||
* @return null|Item
|
||||
* @param int $x
|
||||
* @param int $y
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function getIngredient($x, $y){
|
||||
public function getIngredient(int $x, int $y) : Item{
|
||||
return $this->ingredients[$y][$x] ?? Item::get(Item::AIR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getShape(){
|
||||
public function getShape() : array{
|
||||
return $this->shape;
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ class ShapelessRecipe implements Recipe{
|
||||
/** @var Item */
|
||||
private $output;
|
||||
|
||||
/** @var UUID|null */
|
||||
private $id = null;
|
||||
|
||||
/** @var Item[] */
|
||||
@ -40,10 +41,16 @@ class ShapelessRecipe implements Recipe{
|
||||
$this->output = clone $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UUID|null
|
||||
*/
|
||||
public function getId(){
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UUID $id
|
||||
*/
|
||||
public function setId(UUID $id){
|
||||
if($this->id !== null){
|
||||
throw new \InvalidStateException("Id is already set");
|
||||
@ -52,18 +59,18 @@ class ShapelessRecipe implements Recipe{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function getResult(){
|
||||
public function getResult() : Item{
|
||||
return clone $this->output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item $item
|
||||
*
|
||||
* @returns ShapelessRecipe
|
||||
* @return ShapelessRecipe
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function addIngredient(Item $item){
|
||||
public function addIngredient(Item $item) : ShapelessRecipe{
|
||||
if(count($this->ingredients) >= 9){
|
||||
throw new \InvalidArgumentException("Shapeless recipes cannot have more than 9 ingredients");
|
||||
}
|
||||
@ -101,7 +108,7 @@ class ShapelessRecipe implements Recipe{
|
||||
/**
|
||||
* @return Item[]
|
||||
*/
|
||||
public function getIngredientList(){
|
||||
public function getIngredientList() : array{
|
||||
$ingredients = [];
|
||||
foreach($this->ingredients as $ingredient){
|
||||
$ingredients[] = clone $ingredient;
|
||||
@ -113,7 +120,7 @@ class ShapelessRecipe implements Recipe{
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getIngredientCount(){
|
||||
public function getIngredientCount() : int{
|
||||
$count = 0;
|
||||
foreach($this->ingredients as $ingredient){
|
||||
$count += $ingredient->getCount();
|
||||
|
@ -54,19 +54,25 @@ class SimpleTransactionGroup implements TransactionGroup{
|
||||
/**
|
||||
* @return Player
|
||||
*/
|
||||
public function getSource(){
|
||||
public function getSource() : Player{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
public function getCreationTime(){
|
||||
public function getCreationTime() : float{
|
||||
return $this->creationTime;
|
||||
}
|
||||
|
||||
public function getInventories(){
|
||||
/**
|
||||
* @return Inventory[]
|
||||
*/
|
||||
public function getInventories() : array{
|
||||
return $this->inventories;
|
||||
}
|
||||
|
||||
public function getTransactions(){
|
||||
/**
|
||||
* @return Transaction[]
|
||||
*/
|
||||
public function getTransactions() : array{
|
||||
return $this->transactions;
|
||||
}
|
||||
|
||||
@ -93,7 +99,7 @@ class SimpleTransactionGroup implements TransactionGroup{
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function matchItems(array &$needItems, array &$haveItems){
|
||||
protected function matchItems(array &$needItems, array &$haveItems) : bool{
|
||||
foreach($this->transactions as $key => $ts){
|
||||
if($ts->getTargetItem()->getId() !== Item::AIR){
|
||||
$needItems[] = $ts->getTargetItem();
|
||||
@ -128,7 +134,7 @@ class SimpleTransactionGroup implements TransactionGroup{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canExecute(){
|
||||
public function canExecute() : bool{
|
||||
$haveItems = [];
|
||||
$needItems = [];
|
||||
|
||||
@ -149,7 +155,10 @@ class SimpleTransactionGroup implements TransactionGroup{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function execute(){
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function execute() : bool{
|
||||
if($this->hasExecuted() or !$this->canExecute()){
|
||||
return false;
|
||||
}
|
||||
@ -175,7 +184,7 @@ class SimpleTransactionGroup implements TransactionGroup{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hasExecuted(){
|
||||
public function hasExecuted() : bool{
|
||||
return $this->hasExecuted;
|
||||
}
|
||||
}
|
@ -30,25 +30,25 @@ interface Transaction{
|
||||
/**
|
||||
* @return Inventory
|
||||
*/
|
||||
public function getInventory();
|
||||
public function getInventory() : Inventory;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getSlot();
|
||||
public function getSlot() : int;
|
||||
|
||||
/**
|
||||
* @return Item
|
||||
*/
|
||||
public function getSourceItem();
|
||||
public function getSourceItem() : Item;
|
||||
|
||||
/**
|
||||
* @return Item
|
||||
*/
|
||||
public function getTargetItem();
|
||||
public function getTargetItem() : Item;
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getCreationTime();
|
||||
public function getCreationTime() : float;
|
||||
}
|
@ -28,17 +28,17 @@ interface TransactionGroup{
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getCreationTime();
|
||||
public function getCreationTime() : float;
|
||||
|
||||
/**
|
||||
* @return Transaction[]
|
||||
*/
|
||||
public function getTransactions();
|
||||
public function getTransactions() : array;
|
||||
|
||||
/**
|
||||
* @return Inventory[]
|
||||
*/
|
||||
public function getInventories();
|
||||
public function getInventories() : array;
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
@ -48,16 +48,16 @@ interface TransactionGroup{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function canExecute();
|
||||
public function canExecute() : bool;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function execute();
|
||||
public function execute() : bool;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasExecuted();
|
||||
public function hasExecuted() : bool;
|
||||
|
||||
}
|
Reference in New Issue
Block a user