diff --git a/src/pocketmine/inventory/CraftingManager.php b/src/pocketmine/inventory/CraftingManager.php index 68a4cc8a5..103a4504c 100644 --- a/src/pocketmine/inventory/CraftingManager.php +++ b/src/pocketmine/inventory/CraftingManager.php @@ -220,7 +220,10 @@ class CraftingManager{ * @param ShapedRecipe $recipe */ public function registerShapedRecipe(ShapedRecipe $recipe) : void{ + $recipe->setId($uuid = UUID::fromData((string) ++self::$RECIPE_COUNT, json_encode(self::pack($recipe->getResults())))); + $this->recipes[$uuid->toBinary()] = $recipe; $this->shapedRecipes[self::hashOutputs($recipe->getResults())][] = $recipe; + $this->craftingDataCache = null; } @@ -228,7 +231,10 @@ class CraftingManager{ * @param ShapelessRecipe $recipe */ public function registerShapelessRecipe(ShapelessRecipe $recipe) : void{ + $recipe->setId($uuid = UUID::fromData((string) ++self::$RECIPE_COUNT, json_encode(self::pack($recipe->getResults())))); + $this->recipes[$uuid->toBinary()] = $recipe; $this->shapelessRecipes[self::hashOutputs($recipe->getResults())][] = $recipe; + $this->craftingDataCache = null; } @@ -284,11 +290,6 @@ class CraftingManager{ * @param Recipe $recipe */ public function registerRecipe(Recipe $recipe) : void{ - if($recipe instanceof CraftingRecipe){ - $recipe->setId($uuid = UUID::fromData((string) ++self::$RECIPE_COUNT, json_encode(self::pack($recipe->getResults())))); - $this->recipes[$uuid->toBinary()] = $recipe; - } - $recipe->registerToCraftingManager($this); } diff --git a/src/pocketmine/inventory/CraftingRecipe.php b/src/pocketmine/inventory/CraftingRecipe.php index d0e31ff9e..0f184d958 100644 --- a/src/pocketmine/inventory/CraftingRecipe.php +++ b/src/pocketmine/inventory/CraftingRecipe.php @@ -46,11 +46,13 @@ interface CraftingRecipe extends Recipe{ public function getIngredientList() : array; /** - * Returns a list of items created by crafting this recipe. + * Returns a list of results this recipe will produce when the inputs in the given crafting grid are consumed. + * + * @param CraftingGrid $grid * * @return Item[] */ - public function getResults() : array; + public function getResultsFor(CraftingGrid $grid) : array; /** * Returns whether the given crafting grid meets the requirements to craft this recipe. diff --git a/src/pocketmine/inventory/ShapedRecipe.php b/src/pocketmine/inventory/ShapedRecipe.php index 2b7386cd7..f1cbf372a 100644 --- a/src/pocketmine/inventory/ShapedRecipe.php +++ b/src/pocketmine/inventory/ShapedRecipe.php @@ -107,6 +107,15 @@ class ShapedRecipe implements CraftingRecipe{ return array_map(function(Item $item) : Item{ return clone $item; }, $this->results); } + /** + * @param CraftingGrid $grid + * + * @return Item[] + */ + public function getResultsFor(CraftingGrid $grid) : array{ + return $this->getResults(); + } + /** * @return UUID|null */ diff --git a/src/pocketmine/inventory/ShapelessRecipe.php b/src/pocketmine/inventory/ShapelessRecipe.php index 405a33c71..3b3597d33 100644 --- a/src/pocketmine/inventory/ShapelessRecipe.php +++ b/src/pocketmine/inventory/ShapelessRecipe.php @@ -70,6 +70,10 @@ class ShapelessRecipe implements CraftingRecipe{ return array_map(function(Item $item) : Item{ return clone $item; }, $this->results); } + public function getResultsFor(CraftingGrid $grid) : array{ + return $this->getResults(); + } + /** * @param Item $item * diff --git a/src/pocketmine/inventory/transaction/CraftingTransaction.php b/src/pocketmine/inventory/transaction/CraftingTransaction.php index 48f549b75..940856156 100644 --- a/src/pocketmine/inventory/transaction/CraftingTransaction.php +++ b/src/pocketmine/inventory/transaction/CraftingTransaction.php @@ -121,7 +121,7 @@ class CraftingTransaction extends InventoryTransaction{ } try{ - $this->repetitions = $this->matchRecipeItems($this->outputs, $this->recipe->getResults(), false); + $this->repetitions = $this->matchRecipeItems($this->outputs, $this->recipe->getResultsFor($this->source->getCraftingGrid()), false); if(($inputIterations = $this->matchRecipeItems($this->inputs, $this->recipe->getIngredientList(), true)) !== $this->repetitions){ throw new \InvalidStateException("Tried to craft recipe $this->repetitions times in batch, but have enough inputs for $inputIterations");