New crafting recipe data format, more readable & more compact

This commit is contained in:
Dylan K. Taylor 2017-08-24 12:05:35 +01:00
parent 17518195d1
commit 76acb1da7b
2 changed files with 12756 additions and 23553 deletions

View File

@ -70,10 +70,11 @@ class CraftingManager{
$first = $recipe["output"][0];
$result = new ShapedRecipe(Item::jsonDeserialize($first), $recipe["height"], $recipe["width"]);
$shape = array_chunk($recipe["input"], $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, Item::jsonDeserialize($ingredient));
$result->addIngredient($x, $y, $ingredients[$ingredient] ?? Item::get(Item::AIR, 0, 0));
}
}
$this->registerRecipe($result);

File diff suppressed because it is too large Load Diff