From f6af1add93f2f348c7ddd3d22242b761cfc1e599 Mon Sep 17 00:00:00 2001 From: Justin Parsell Date: Sun, 24 Oct 2021 20:23:33 -0400 Subject: [PATCH] Addition of dynamic recipe additions --- .../parsell/glowstonewire/core/glowItems.java | 13 +++-- .../glowstonewire/core/glowRecipes.java | 53 +++++++++++++++++++ .../mixin/RecipeManagerInjector.java | 28 ++++++++++ src/main/resources/glowstonewire.mixins.json | 3 +- 4 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 src/main/java/me/parsell/glowstonewire/core/glowRecipes.java create mode 100644 src/main/java/me/parsell/glowstonewire/mixin/RecipeManagerInjector.java diff --git a/src/main/java/me/parsell/glowstonewire/core/glowItems.java b/src/main/java/me/parsell/glowstonewire/core/glowItems.java index 099865a..c4a593b 100644 --- a/src/main/java/me/parsell/glowstonewire/core/glowItems.java +++ b/src/main/java/me/parsell/glowstonewire/core/glowItems.java @@ -1,5 +1,9 @@ package me.parsell.glowstonewire.core; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + import me.parsell.glowstonewire.GlowstoneWire; import me.parsell.glowstonewire.mixin.BrewingRecipeRegistryInvoker; import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder; @@ -10,6 +14,7 @@ import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.potion.Potions; +import net.minecraft.recipe.Ingredient; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; @@ -32,11 +37,5 @@ public class glowItems { BrewingRecipeRegistryInvoker.registerPotionRecipe(Potions.REGENERATION, GLOWSTONE_DUST, Potions.STRONG_REGENERATION); BrewingRecipeRegistryInvoker.registerPotionRecipe(Potions.STRENGTH, GLOWSTONE_DUST, Potions.STRONG_STRENGTH); } - - // Vanilla Glowstone -> Modded Glowstone - // TODO: IF "convert" or "both" config is set - if(GlowstoneWire.CONFIG.addConversionRecipe) { - - } - }; + } } diff --git a/src/main/java/me/parsell/glowstonewire/core/glowRecipes.java b/src/main/java/me/parsell/glowstonewire/core/glowRecipes.java new file mode 100644 index 0000000..df68270 --- /dev/null +++ b/src/main/java/me/parsell/glowstonewire/core/glowRecipes.java @@ -0,0 +1,53 @@ +package me.parsell.glowstonewire.core; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; + +import me.parsell.glowstonewire.GlowstoneWire; + +public class glowRecipes { + public static JsonObject MODDED_TO_VANILLA; + public static JsonObject VANILLA_TO_MODDED; + + public static void init(){ + // Vanilla Glowstone -> Modded Glowstone + if(GlowstoneWire.CONFIG.addConversionRecipe || true) { + // This is the json objects + JsonObject cIngredientsKey = new JsonObject(); + JsonArray cIngredientsList = new JsonArray(); + + // FOR VANILLA TO MODDED + VANILLA_TO_MODDED = new JsonObject(); + + // Header, defining what type of crafting recipe it is + VANILLA_TO_MODDED.addProperty("type", "minecraft:crafting_shapeless"); + + // Adding the ingredients + cIngredientsKey.addProperty("item", "minecraft:glowstone_dust"); + cIngredientsList.add(cIngredientsKey); + VANILLA_TO_MODDED.add("ingredients", cIngredientsList); + + // Adding the result + cIngredientsKey.addProperty("item", "glowstonewire:glowstone_dust"); + VANILLA_TO_MODDED.add("result", cIngredientsKey); + + // Clearing out the old array for new + cIngredientsList = new JsonArray(); + + // FOR MODDED TO VANILLA + MODDED_TO_VANILLA = new JsonObject(); + + // Define reccipe type + MODDED_TO_VANILLA.addProperty("type", "minecraft:crafting_shapeless"); + + // Add ingredients + cIngredientsKey.addProperty("item", "glowstonewire:glowstone_dust"); + cIngredientsList.add(cIngredientsKey); + MODDED_TO_VANILLA.add("ingredients", cIngredientsList); + + // Add result + cIngredientsKey.addProperty("item", "minecraft:glowstone_dust"); + MODDED_TO_VANILLA.add("result", cIngredientsKey); + } + } +} diff --git a/src/main/java/me/parsell/glowstonewire/mixin/RecipeManagerInjector.java b/src/main/java/me/parsell/glowstonewire/mixin/RecipeManagerInjector.java new file mode 100644 index 0000000..0ab8248 --- /dev/null +++ b/src/main/java/me/parsell/glowstonewire/mixin/RecipeManagerInjector.java @@ -0,0 +1,28 @@ +package me.parsell.glowstonewire.mixin; + +import java.util.Map; + +import com.google.gson.JsonElement; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import me.parsell.glowstonewire.GlowstoneWire; +import me.parsell.glowstonewire.core.glowRecipes; +import net.minecraft.recipe.RecipeManager; +import net.minecraft.resource.ResourceManager; +import net.minecraft.util.Identifier; +import net.minecraft.util.profiler.Profiler; + +@Mixin(RecipeManager.class) +public class RecipeManagerInjector { + @Inject(method = "apply", at = @At("HEAD")) + public void interceptApply(Map map, ResourceManager resourceManager, Profiler profiler, CallbackInfo info) { + if (GlowstoneWire.CONFIG.addConversionRecipe) { + map.put(new Identifier(GlowstoneWire.MODID, "glowstone_vanilla_modded"), glowRecipes.VANILLA_TO_MODDED); + map.put(new Identifier(GlowstoneWire.MODID, "glowstone_modded_vanilla"), glowRecipes.MODDED_TO_VANILLA); + } + } +} diff --git a/src/main/resources/glowstonewire.mixins.json b/src/main/resources/glowstonewire.mixins.json index 97ca642..408f534 100644 --- a/src/main/resources/glowstonewire.mixins.json +++ b/src/main/resources/glowstonewire.mixins.json @@ -6,7 +6,8 @@ "mixins": [ ], "client": [ - "BrewingRecipeRegistryInvoker" + "BrewingRecipeRegistryInvoker", + "RecipeManagerInjector" ], "injectors": { "defaultRequire": 1