use of buildcraft.lib.recipe.IntegrationRecipeBasic in project BuildCraft by BuildCraft.
the class BCSiliconRecipes method registerRecipes.
@SubscribeEvent
public static void registerRecipes(RegistryEvent.Register<IRecipe> event) {
Loader.instance().getActiveModList().forEach((mod) -> {
JsonContext ctx = new JsonContext(mod.getModId());
CraftingHelper.findFiles(mod, "assets/" + mod.getModId() + "/assembly_recipes", null, (root, file) -> {
String path = root.relativize(file).toString();
if (!FilenameUtils.getExtension(file.toString()).equals("json"))
return true;
String name = FilenameUtils.removeExtension(path).replaceAll("\\\\", "/");
ResourceLocation key = new ResourceLocation(mod.getModId(), name);
BufferedReader reader = null;
try {
reader = Files.newBufferedReader(file);
JsonObject json = JsonUtils.fromJson(GSON, reader, JsonObject.class);
if (json == null || json.isJsonNull())
throw new JsonSyntaxException("Json is null (empty file?)");
ItemStack output = CraftingHelper.getItemStack(json.getAsJsonObject("result"), ctx);
long powercost = json.get("MJ").getAsLong() * MjAPI.MJ;
ArrayList<IngredientStack> ingredients = new ArrayList<>();
json.getAsJsonArray("components").forEach(element -> {
JsonObject object = element.getAsJsonObject();
ingredients.add(new IngredientStack(CraftingHelper.getIngredient(object.get("ingredient"), ctx), JsonUtils.getInt(object, "amount", 1)));
});
AssemblyRecipeRegistry.REGISTRY.put(key, new AssemblyRecipeBasic(key, powercost, ImmutableSet.copyOf(ingredients), output));
} catch (IOException e) {
BCLog.logger.error("Couldn't read recipe {} from {}", key, file, e);
return false;
} finally {
IOUtils.closeQuietly(reader);
}
return true;
});
CraftingHelper.findFiles(mod, "assets/" + mod.getModId() + "/integration_recipes", null, (root, file) -> {
String path = root.relativize(file).toString();
if (!FilenameUtils.getExtension(file.toString()).equals("json"))
return true;
String name = FilenameUtils.removeExtension(path).replaceAll("\\\\", "/");
ResourceLocation key = new ResourceLocation(mod.getModId(), name);
BufferedReader reader = null;
try {
reader = Files.newBufferedReader(file);
JsonObject json = JsonUtils.fromJson(GSON, reader, JsonObject.class);
if (json == null || json.isJsonNull())
throw new JsonSyntaxException("Json is null (empty file?)");
ItemStack output = CraftingHelper.getItemStack(json.getAsJsonObject("result"), ctx);
IngredientStack centerStack = IngredientStack.of(CraftingHelper.getIngredient(json.getAsJsonObject("centerStack"), ctx));
long powercost = json.get("MJ").getAsLong() * MjAPI.MJ;
ArrayList<IngredientStack> ingredients = new ArrayList<>();
json.getAsJsonArray("components").forEach(element -> {
JsonObject object = element.getAsJsonObject();
ingredients.add(new IngredientStack(CraftingHelper.getIngredient(object.get("ingredient"), ctx), JsonUtils.getInt(object, "amount", 1)));
});
IntegrationRecipeRegistry.INSTANCE.addRecipe(new IntegrationRecipeBasic(key, powercost, centerStack, ingredients, output));
} catch (IOException e) {
BCLog.logger.error("Couldn't read recipe {} from {}", key, file, e);
return false;
} finally {
IOUtils.closeQuietly(reader);
}
return true;
});
});
}
Aggregations