Cleaned up ShapedRecipe handling, ShapedRecipe API changes

use shapes from json instead of just generating maps
fix a ton of bugs
This commit is contained in:
Dylan K. Taylor
2017-09-17 11:45:09 +01:00
parent c8199e14ad
commit 642c7733cd
2 changed files with 59 additions and 61 deletions

View File

@ -68,16 +68,12 @@ class CraftingManager{
case 1:
// TODO: handle multiple result items
$first = $recipe["output"][0];
$result = new ShapedRecipe(Item::jsonDeserialize($first), $recipe["height"], $recipe["width"]);
$shape = array_map(function(string $keys) : array{ return str_split($keys); }, $recipe["shape"]);
$ingredients = array_map(function(array $data) : Item{ return Item::jsonDeserialize($data); }, $recipe["input"]);
foreach($shape as $y => $row){
foreach($row as $x => $ingredient){
$result->addIngredient($x, $y, $ingredients[$ingredient] ?? Item::get(Item::AIR, 0, 0));
}
}
$this->registerRecipe($result);
$this->registerRecipe(new ShapedRecipe(
Item::jsonDeserialize($first),
$recipe["shape"],
array_map(function(array $data) : Item{ return Item::jsonDeserialize($data); }, $recipe["input"])
));
break;
case 2:
case 3: