-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
common/src/main/java/net/mehvahdjukaar/every_compat/common_classes/RecipeUtility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |