pocketmine\inventory\CraftingManager::matchRecipe PHP Метод

matchRecipe() публичный Метод

public matchRecipe ( ShapelessRecipe $recipe ) : boolean
$recipe ShapelessRecipe
Результат boolean
    public function matchRecipe(ShapelessRecipe $recipe)
    {
        if (!isset($this->recipeLookup[$idx = $recipe->getResult()->getId() . ":" . $recipe->getResult()->getDamage()])) {
            return false;
        }
        $hash = "";
        $ingredients = $recipe->getIngredientList();
        usort($ingredients, [$this, "sort"]);
        foreach ($ingredients as $item) {
            $hash .= $item->getId() . ":" . ($item->getDamage() === null ? "?" : $item->getDamage()) . "x" . $item->getCount() . ",";
        }
        if (isset($this->recipeLookup[$idx][$hash])) {
            return true;
        }
        $hasRecipe = null;
        foreach ($this->recipeLookup[$idx] as $recipe) {
            if ($recipe instanceof ShapelessRecipe) {
                if ($recipe->getIngredientCount() !== count($ingredients)) {
                    continue;
                }
                $checkInput = $recipe->getIngredientList();
                foreach ($ingredients as $item) {
                    $amount = $item->getCount();
                    foreach ($checkInput as $k => $checkItem) {
                        if ($checkItem->equals($item, $checkItem->getDamage() === null ? false : true, $checkItem->getCompoundTag() === null ? false : true)) {
                            $remove = min($checkItem->getCount(), $amount);
                            $checkItem->setCount($checkItem->getCount() - $remove);
                            if ($checkItem->getCount() === 0) {
                                unset($checkInput[$k]);
                            }
                            $amount -= $remove;
                            if ($amount === 0) {
                                break;
                            }
                        }
                    }
                }
                if (count($checkInput) === 0) {
                    $hasRecipe = $recipe;
                    break;
                }
            }
            if ($hasRecipe instanceof Recipe) {
                break;
            }
        }
        return $hasRecipe !== null;
    }