Skip to content

Commit

Permalink
NEW CLASS: RecipeUtility
Browse files Browse the repository at this point in the history
  • Loading branch information
Xelbayria committed Dec 13, 2024
1 parent 9bd9856 commit 9f45ee3
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.mehvahdjukaar.every_compat.common_classes;

import com.google.gson.JsonObject;
import net.mehvahdjukaar.every_compat.dynamicpack.ServerDynamicResourcesHandler;
import net.mehvahdjukaar.moonlight.api.resources.RPUtils;
import net.mehvahdjukaar.moonlight.api.resources.ResType;
import net.mehvahdjukaar.moonlight.api.util.Utils;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.world.level.block.Block;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;

@SuppressWarnings("unused")
public class RecipeUtility {

/**
* Create Stonecutting Recipe that use tag as an ingredient
*/
public static void stonecuttingWithTagRecipe(Block output, ResourceLocation recipeLoc, ResourceLocation tagResLoc,
ResourceLocation newRecipeLoc, ServerDynamicResourcesHandler handler, ResourceManager manager) {
if (Objects.nonNull(output)) {
try (InputStream recipeStream = manager.getResource(recipeLoc)
.orElseThrow(() -> new FileNotFoundException("Failed to get " + recipeLoc)).open()) {
JsonObject recipe = RPUtils.deserializeJson(recipeStream);

// Editing the recipe
recipe.getAsJsonObject("ingredient").addProperty("tag", tagResLoc.toString());
recipe.addProperty("result", Utils.getID(output).toString());

// Adding to the resources
handler.dynamicPack.addJson(newRecipeLoc, recipe, ResType.RECIPES);

} catch (IOException e) {
handler.getLogger().error("Failed to generate the recipe @ {} : {}", recipeLoc, e);
}
}
}
}

0 comments on commit 9f45ee3

Please sign in to comment.