toJson method
Implementation
Map<String, dynamic> toJson() {
final dat = <String, dynamic>{};
switch (type) {
case RecipeType.shaped:
{
dat['type'] = 'crafting_shaped';
final p = getPattern();
dat['pattern'] = p.key;
dat['key'] = p.value.map((k, v) => MapEntry(k, v.getMap(false)));
break;
}
case RecipeType.shapeless:
{
dat['type'] = 'crafting_shapeless';
dat['ingredients'] =
ingredients.values.map((i) => i.getMap(false)).toList();
break;
}
case RecipeType.smithing:
{
dat['type'] = 'smithing';
dat['base'] = ingredients.values.first.getMap(false);
if (ingredients.length > 1) {
dat['add'] = ingredients.values.toList()[1].getMap(false);
}
break;
}
default:
{
dat['type'] = type.name;
dat['ingredient'] = ingredients.values.first.getMap(false);
dat['result'] = 'minecraft:${result.getId()}';
}
}
dat['type'] = 'minecraft:${dat['type']}';
return dat;
}