CraftingRecipe: added methods to allow recipes to derive outputs from inputs

this will be needed for special recipes like shulker-box and banner recipes.
This commit is contained in:
Dylan K. Taylor
2018-03-28 19:54:52 +01:00
parent 8572e9e560
commit a1090623a2
5 changed files with 24 additions and 8 deletions

View File

@ -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);
}