From ec82434ef4b2c319c8710337db15df7b892e2c4d Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 5 Jun 2015 15:18:16 +0200 Subject: [PATCH] Added charcoal for torches, improved recipe matching for wildcards, closes #3108 --- src/pocketmine/inventory/CraftingManager.php | 42 +++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/inventory/CraftingManager.php b/src/pocketmine/inventory/CraftingManager.php index fd9bb8b71..6b99e26ee 100644 --- a/src/pocketmine/inventory/CraftingManager.php +++ b/src/pocketmine/inventory/CraftingManager.php @@ -67,6 +67,7 @@ class CraftingManager{ $this->registerRecipe((new ShapelessRecipe(Item::get(Item::WOODEN_PLANK, Planks::DARK_OAK, 4)))->addIngredient(Item::get(Item::WOOD2, Wood2::DARK_OAK, 1))); $this->registerRecipe((new ShapelessRecipe(Item::get(Item::WOOL, 0, 1)))->addIngredient(Item::get(Item::STRING, 0, 4))); $this->registerRecipe((new ShapelessRecipe(Item::get(Item::TORCH, 0, 4)))->addIngredient(Item::get(Item::COAL, 0, 1))->addIngredient(Item::get(Item::STICK, 0, 1))); + $this->registerRecipe((new ShapelessRecipe(Item::get(Item::TORCH, 0, 4)))->addIngredient(Item::get(Item::COAL, 1, 1))->addIngredient(Item::get(Item::STICK, 0, 1))); $this->registerRecipe((new ShapelessRecipe(Item::get(Item::SUGAR, 0, 1)))->addIngredient(Item::get(Item::SUGARCANE, 0, 1))); @@ -386,7 +387,46 @@ class CraftingManager{ $hash .= $item->getId() . ":" . ($item->getDamage() === null ? "?" : $item->getDamage()) . "x" . $item->getCount() . ","; } - return isset($this->recipeLookup[$idx][$hash]); + 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)){ + $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; + } /**