3){ throw new \Exception("Crafting recipes should be 1, 2, 3 rows, not " . count($shape)); } foreach($shape as $row){ if(strlen($row) === 0 or strlen($row) > 3){ throw new \Exception("Crafting rows should be 1, 2, 3 characters, not " . count($row)); } $this->rows[] = $row; $len = strlen($row); for($i = 0; $i < $len; ++$i){ $this->ingredients[$row{$i}] = null; } } $this->output = clone $result; } /** * @param string $key * @param Item $item * * @return $this * @throws \Exception */ public function setIngredient($key, Item $item){ if(!isset($this->ingredients[$key])){ throw new \Exception("Symbol does not appear in the shape: " . $key); } $this->ingredients[$key] = $item; return $this; } /** * @return Item[] */ public function getIngredientMap(){ $ingredients = []; foreach($this->ingredients as $key => $ingredient){ if($ingredient instanceof Item){ $ingredients[$key] = clone $ingredient; }else{ $ingredients[$key] = $ingredient; } } return $ingredients; } /** * @return string[] */ public function getShape(){ return $this->rows; } public function registerToCraftingManager(){ Server::getInstance()->getCraftingManager()->registerShapedRecipe($this); } }