Recipe.pattern constructor
Recipe.pattern(})
Want to stay close to the original minecraft notation and want to prove a pattern? You can also do that with:
Recipe.pattern | |
---|---|
List<String> | Each String of Length 3 represents one row in the crafting grid, use the same char for same items |
Map<String,Item> | For each used character in the pattern, define a corresponding item |
... | stays the same |
Implementation
factory Recipe.pattern(
List<String> pattern,
Map<String, Item> keys,
Item result, {
int? id,
String name = 'recipe',
bool exactlyPlaced = false,
int? exactResult,
RecipeType type = RecipeType.shaped,
}) {
var ingredients = <int, Item>{};
var i = 1;
for (var row in pattern) {
if (row.isNotEmpty && row[0] != ' ') ingredients[i] = keys[row[0]]!;
if (row.length > 1 && row[1] != ' ') ingredients[i + 1] = keys[row[1]]!;
if (row.length > 2 && row[2] != ' ') ingredients[i + 2] = keys[row[2]]!;
i += 3;
}
return Recipe(
ingredients,
result,
id: id,
name: name,
type: type,
exactlyPlaced: exactlyPlaced,
exactResult: exactResult,
);
}