pocketmine\inventory\ShapedRecipe::setIngredient PHP Method

setIngredient() public method

public setIngredient ( string $key, Item $item )
$key string
$item pocketmine\item\Item
    public function setIngredient($key, Item $item)
    {
        if (!array_key_exists($key, $this->shape)) {
            throw new \Exception("Symbol does not appear in the shape: " . $key);
        }
        $item->setCount(1);
        $this->fixRecipe($key, $item);
        return $this;
    }

Usage Example

 public function onEnable()
 {
     //CraftBug(RecipeBug)
     if (self::ENABLE_CRAFT_BUG) {
         $craftingManager = Server::getInstance()->getCraftingManager();
         $recipes = $craftingManager->getRecipes();
         foreach ($recipes as $recipe) {
             if ($recipe instanceof ShapelessRecipe) {
                 $map = $this->getRecipeMap($recipe);
                 $newRecipe = new ShapedRecipe($recipe->getResult(), $map["map"][0] . $map["map"][1] . $map["map"][2], $map["map"][3] . $map["map"][4] . $map["map"][5], $map["map"][6] . $map["map"][7] . $map["map"][8]);
                 foreach ($map["items"] as $key => $item) {
                     $newRecipe->setIngredient($key, $item);
                 }
                 $craftingManager->registerRecipe($newRecipe);
             }
         }
     }
     if (self::ENABLE_ITEM_DAMAGE_BUG or self::ENABLE_CRAFTING_BUG) {
         Server::getInstance()->getPluginManager()->registerEvents($this, $this);
     }
 }