type = $type ?? ShapelessRecipeType::CRAFTING(); if(count($ingredients) > 9){ throw new \InvalidArgumentException("Shapeless recipes cannot have more than 9 ingredients"); } $this->ingredients = $ingredients; $this->results = Utils::cloneObjectArray($results); } /** * @return Item[] */ public function getResults() : array{ return Utils::cloneObjectArray($this->results); } public function getResultsFor(CraftingGrid $grid) : array{ return $this->getResults(); } public function getType() : ShapelessRecipeType{ return $this->type; } /** * @return RecipeIngredient[] */ public function getIngredientList() : array{ return $this->ingredients; } public function getIngredientCount() : int{ return count($this->ingredients); } public function matchesCraftingGrid(CraftingGrid $grid) : bool{ //don't pack the ingredients - shapeless recipes require that each ingredient be in a separate slot $input = $grid->getContents(); foreach($this->ingredients as $ingredient){ foreach($input as $j => $haveItem){ if($ingredient->accepts($haveItem)){ unset($input[$j]); continue 2; } } return false; //failed to match the needed item to a given item } return count($input) === 0; //crafting grid should be empty apart from the given ingredient stacks } }