GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
ShapelessRecipe Class Reference

Public Member Functions

 __construct (Item $result)
 
 getId ()
 
 setId (UUID $id)
 
 getResult ()
 
 addIngredient (Item $item)
 
 removeIngredient (Item $item)
 
 getIngredientList ()
 
 getIngredientCount ()
 
 registerToCraftingManager ()
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( Item  $result)

ShapelessRecipe constructor.

Parameters
Item$result
42  {
43  $this->output = clone $result;
44  }

Member Function Documentation

◆ addIngredient()

addIngredient ( Item  $item)
Parameters
Item$item
Returns
ShapelessRecipe
Exceptions
78  {
79  if(count($this->ingredients) >= 9){
80  throw new \InvalidArgumentException("Shapeless recipes cannot have more than 9 ingredients");
81  }
82 
83  $it = clone $item;
84  $it->setCount(1);
85 
86  while($item->getCount() > 0){
87  $this->ingredients[] = clone $it;
88  $item->setCount($item->getCount() - 1);
89  }
90 
91  return $this;
92  }

◆ getId()

getId ( )
Returns
null

Implements Recipe.

49  {
50  return $this->id;
51  }

◆ getIngredientCount()

getIngredientCount ( )
Returns
int
128  {
129  $count = 0;
130  foreach($this->ingredients as $ingredient){
131  $count += $ingredient->getCount();
132  }
133 
134  return $count;
135  }

◆ getIngredientList()

getIngredientList ( )
Returns
Item[]
116  {
117  $ingredients = [];
118  foreach($this->ingredients as $ingredient){
119  $ingredients[] = clone $ingredient;
120  }
121 
122  return $ingredients;
123  }

◆ getResult()

getResult ( )
Returns
Item

Implements Recipe.

67  {
68  return clone $this->output;
69  }

◆ registerToCraftingManager()

registerToCraftingManager ( )

Implements Recipe.

137  {
138  Server::getInstance()->getCraftingManager()->registerShapelessRecipe($this);
139  }

◆ removeIngredient()

removeIngredient ( Item  $item)
Parameters
Item$item
Returns
$this
99  {
100  foreach($this->ingredients as $index => $ingredient){
101  if($item->getCount() <= 0){
102  break;
103  }
104  if($ingredient->equals($item, !$item->hasAnyDamageValue(), $item->hasCompoundTag())){
105  unset($this->ingredients[$index]);
106  $item->setCount($item->getCount() - 1);
107  }
108  }
109 
110  return $this;
111  }

◆ setId()

setId ( UUID  $id)
Parameters
UUID$id
56  {
57  if($this->id !== null){
58  throw new \InvalidStateException("Id is already set");
59  }
60 
61  $this->id = $id;
62  }

The documentation for this class was generated from the following file: