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

Public Member Functions

 __construct (Item $result, $height, $width)
 
 getWidth ()
 
 getHeight ()
 
 getResult ()
 
 getId ()
 
 setId (UUID $id)
 
 addIngredient ($x, $y, Item $item)
 
 setIngredient ($key, Item $item)
 
 getIngredientMap ()
 
 getIngredientList ()
 
 getIngredient ($x, $y)
 
 getShape ()
 
 registerToCraftingManager ()
 

Protected Member Functions

 fixRecipe ($key, $item)
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( Item  $result,
  $height,
  $width 
)
Parameters
Item$result
int$height
int$width
Exceptions
50  {
51  for($h = 0; $h < $height; $h++){
52  if($width === 0 or $width > 3){
53  throw new \InvalidStateException("Crafting rows should be 1, 2, 3 wide, not $width");
54  }
55  $this->ingredients[] = array_fill(0, $width, null);
56  }
57 
58  $this->output = clone $result;
59  }

Member Function Documentation

◆ addIngredient()

addIngredient (   $x,
  $y,
Item  $item 
)
Parameters
$x
$y
Item$item
Returns
$this
107  {
108  $this->ingredients[$y][$x] = clone $item;
109  return $this;
110  }

◆ fixRecipe()

fixRecipe (   $key,
  $item 
)
protected
Parameters
$key
$item
134  {
135  foreach($this->shapeItems[$key] as $entry){
136  $this->ingredients[$entry->y][$entry->x] = clone $item;
137  }
138  }

◆ getHeight()

getHeight ( )
Returns
int
71  {
72  return count($this->ingredients);
73  }

◆ getId()

getId ( )
Returns
null

Implements Recipe.

85  {
86  return $this->id;
87  }

◆ getIngredient()

getIngredient (   $x,
  $y 
)
Parameters
$x
$y
Returns
null|Item
182  {
183  return isset($this->ingredients[$y][$x]) ? $this->ingredients[$y][$x] : Item::get(Item::AIR);
184  }

◆ getIngredientList()

getIngredientList ( )
Returns
Item[]
162  {
163  $ingredients = [];
164  for($x = 0; $x < 3; ++$x){
165  for($y = 0; $y < 3; ++$y){
166  if(!empty($this->ingredients[$x][$y])){
167  if($this->ingredients[$x][$y]->getId() !== Item::AIR){
168  $ingredients[] = clone $this->ingredients[$x][$y];
169  }
170  }
171  }
172  }
173  return $ingredients;
174  }

◆ getIngredientMap()

getIngredientMap ( )
Returns
Item[][]
143  {
144  $ingredients = [];
145  foreach($this->ingredients as $y => $row){
146  $ingredients[$y] = [];
147  foreach($row as $x => $ingredient){
148  if($ingredient !== null){
149  $ingredients[$y][$x] = clone $ingredient;
150  }else{
151  $ingredients[$y][$x] = Item::get(Item::AIR);
152  }
153  }
154  }
155 
156  return $ingredients;
157  }

◆ getResult()

getResult ( )
Returns
Item

Implements Recipe.

78  {
79  return $this->output;
80  }

◆ getShape()

getShape ( )
Returns
string[]
189  {
190  return $this->shape;
191  }

◆ getWidth()

getWidth ( )
Returns
int
64  {
65  return count($this->ingredients[0]);
66  }

◆ registerToCraftingManager()

registerToCraftingManager ( )

Implements Recipe.

193  {
194  Server::getInstance()->getCraftingManager()->registerShapedRecipe($this);
195  }

◆ setId()

setId ( UUID  $id)
Parameters
UUID$id
92  {
93  if($this->id !== null){
94  throw new \InvalidStateException("Id is already set");
95  }
96 
97  $this->id = $id;
98  }

◆ setIngredient()

setIngredient (   $key,
Item  $item 
)
Parameters
string$key
Item$item
Returns
$this
Exceptions
119  {
120  if(!array_key_exists($key, $this->shape)){
121  throw new \Exception("Symbol does not appear in the shape: " . $key);
122  }
123 
124  $item->setCount(1);
125  $this->fixRecipe($key, $item);
126 
127  return $this;
128  }

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