fix some inspections related to crafting recipes

This commit is contained in:
Dylan K. Taylor 2017-07-13 13:59:45 +01:00
parent 7f99d9019a
commit b9355387da
4 changed files with 57 additions and 21 deletions

View File

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

View File

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

View File

@ -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){
return $this->ingredients[$y][$x] ?? Item::get(Item::AIR);
}
/**
* @return string[]
*/
public function getShape(){
public function getShape() : array{
return $this->shape;
}

View File

@ -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,14 +59,14 @@ 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
*/
@ -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();