diff --git a/CraftTweakerCompat.md b/CraftTweakerCompat.md index 60bb2de6..8ae9fd6d 100644 --- a/CraftTweakerCompat.md +++ b/CraftTweakerCompat.md @@ -1,13 +1,23 @@ # Editing Nature's Aura recipes with CraftTweaker A few notes that apply for most of the recipe types: - If you don't know how the CraftTweaker syntax works, [read up on it](https://docs.blamejared.com/en/#Getting_Started/) first. -- `name` is the name of a recipe. For most recipes, the name is important as recipes are referenced by name in the Book of Natural Aura. When replacing an existing recipe, make sure to give it the same name as the original recipe. All recipes are prefixed with `naturesaura:`, and crafting recipes get their name from their [json files](https://github.com/Ellpeck/NaturesAura/tree/master/src/main/resources/assets/naturesaura/recipes) and other recipes get their name from their [registration call](https://github.com/Ellpeck/NaturesAura/blob/master/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java). To see which recipes are referenced where, you can also see the [Patchouli documentation](https://github.com/Ellpeck/NaturesAura/tree/master/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries). -- `IIngredient` is any kind of ingredient, meaning either an OreDictionary entry or an item -- `IItemStack` is an item +- `name` is the name of a recipe. Read on for more information about this. - `aura` is the amount of Aura required and represents the total amount required for the completion of the recipe (for reference, 1,000,000 is the default amount of Aura present in the world and 2,000,000 is the amount that is required for the Environmental Eye's bar to fill up fully) - `time` is the time processes take in ticks - For most removal recipes, `output` is the output of the recipe that should be removed. All recipes with the given outupt will be removed. +## On the Importance of Recipe Names +When replacing an existing recipe with a new one, the `name` variable of the recipe matters greatly, both for Nature's Aura's custom recipe types and for [vanilla crafting recipes](https://crafttweaker.readthedocs.io/en/latest/#Vanilla/Recipes/Crafting/Recipes_Crafting_Table/), if the replacement recipe should be displayed correctly in the Book of Natural Aura in place of the original recipe. +__The replacement recipe that is added for any given item inside of Nature's Aura needs to be named after the item id of the item that is being crafted.__ + +As an example, the following piece of code will remove the existing recipe of the Imperceptible Builder and replace it with a new one. Checking its Book of Natural Aura entry will then also display the new recipe correctly without errors. +``` +recipes.remove(); +recipes.addShapeless("placer", , , ); +``` +Note that the name of the recipe is supplied as `placer` because the item id of the Imperceptible Builder is `naturesaura:placer`. Not doing this would lead to the Book of Natural Aura not displaying the new recipe. + +_When adding a new recipe without replacing an existing one, the name of the newly added recipe does not matter._ ## Natural Altar `mods.naturesaura.Altar.addRecipe(String name, IIngredient input, IItemStack output, IIngredient catalyst, int aura, int time)` diff --git a/build.gradle b/build.gradle index a64e6ffd..c40e1639 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ repositories { } dependencies { - compile "vazkii.patchouli:Patchouli:1.0-18.93" + compile "vazkii.patchouli:Patchouli:1.0-19.96" deobfCompile "mezz.jei:jei_1.12.2:4.14.4.267" deobfCompile "com.azanor.baubles:Baubles:1.12-1.5.2" diff --git a/src/main/java/de/ellpeck/naturesaura/compat/Compat.java b/src/main/java/de/ellpeck/naturesaura/compat/Compat.java index 55b56fa1..18e32480 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/Compat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/Compat.java @@ -4,18 +4,17 @@ import de.ellpeck.naturesaura.compat.crafttweaker.CraftTweakerCompat; import de.ellpeck.naturesaura.compat.patchouli.PatchouliCompat; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; public final class Compat { + public static final String CRAFT_TWEAKER = "crafttweaker"; public static boolean baubles; public static boolean craftTweaker; public static boolean mtLib; public static void preInit() { baubles = Loader.isModLoaded("baubles"); - craftTweaker = Loader.isModLoaded("crafttweaker"); + craftTweaker = Loader.isModLoaded(CRAFT_TWEAKER); mtLib = Loader.isModLoaded("mtlib"); if (baubles) diff --git a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AltarTweaker.java b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AltarTweaker.java index 94a6403e..0d25de1e 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AltarTweaker.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AltarTweaker.java @@ -12,6 +12,7 @@ import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.recipes.AltarRecipe; +import de.ellpeck.naturesaura.compat.Compat; import net.minecraft.util.ResourceLocation; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; @@ -27,7 +28,7 @@ public final class AltarTweaker { @ZenMethod public static void addRecipe(String name, IIngredient input, IItemStack output, IIngredient catalyst, int aura, int time) { CraftTweakerCompat.SCHEDULED_ACTIONS.add(() -> { - ResourceLocation res = new ResourceLocation(name); + ResourceLocation res = new ResourceLocation(Compat.CRAFT_TWEAKER, name); return new Add(Collections.singletonMap(res, new AltarRecipe(res, CraftTweakerMC.getIngredient(input), InputHelper.toStack(output), diff --git a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AnimalSpawnerTweaker.java b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AnimalSpawnerTweaker.java index 097bb30f..31c3cf1c 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AnimalSpawnerTweaker.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AnimalSpawnerTweaker.java @@ -8,6 +8,7 @@ import crafttweaker.api.minecraft.CraftTweakerMC; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.recipes.AnimalSpawnerRecipe; +import de.ellpeck.naturesaura.compat.Compat; import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.ResourceLocation; import stanhebben.zenscript.annotations.ZenClass; @@ -24,7 +25,7 @@ public final class AnimalSpawnerTweaker { @ZenMethod public static void addRecipe(String name, String entity, int aura, int time, IIngredient[] ingredients) { CraftTweakerCompat.SCHEDULED_ACTIONS.add(() -> { - ResourceLocation res = new ResourceLocation(name); + ResourceLocation res = new ResourceLocation(Compat.CRAFT_TWEAKER, name); return new Add(Collections.singletonMap(res, new AnimalSpawnerRecipe(res, new ResourceLocation(entity), aura, time, Arrays.stream(ingredients).map(CraftTweakerMC::getIngredient).toArray(Ingredient[]::new) ))); diff --git a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/OfferingTweaker.java b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/OfferingTweaker.java index 03d198a1..a835e7f4 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/OfferingTweaker.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/OfferingTweaker.java @@ -13,6 +13,7 @@ import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.recipes.OfferingRecipe; import de.ellpeck.naturesaura.api.recipes.ing.AmountIngredient; +import de.ellpeck.naturesaura.compat.Compat; import net.minecraft.util.ResourceLocation; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; @@ -28,7 +29,7 @@ public final class OfferingTweaker { @ZenMethod public static void addRecipe(String name, IIngredient input, int inputAmount, IIngredient startItem, IItemStack output) { CraftTweakerCompat.SCHEDULED_ACTIONS.add(() -> { - ResourceLocation res = new ResourceLocation(name); + ResourceLocation res = new ResourceLocation(Compat.CRAFT_TWEAKER, name); return new Add(Collections.singletonMap(res, new OfferingRecipe(res, new AmountIngredient(CraftTweakerMC.getIngredient(input), inputAmount), CraftTweakerMC.getIngredient(startItem), diff --git a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/TreeRitualTweaker.java b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/TreeRitualTweaker.java index 4d79576e..83198033 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/TreeRitualTweaker.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/TreeRitualTweaker.java @@ -12,6 +12,7 @@ import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.recipes.TreeRitualRecipe; +import de.ellpeck.naturesaura.compat.Compat; import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.ResourceLocation; import stanhebben.zenscript.annotations.ZenClass; @@ -29,7 +30,7 @@ public final class TreeRitualTweaker { @ZenMethod public static void addRecipe(String name, IIngredient saplingType, IItemStack result, int time, IIngredient[] items) { CraftTweakerCompat.SCHEDULED_ACTIONS.add(() -> { - ResourceLocation res = new ResourceLocation(name); + ResourceLocation res = new ResourceLocation(Compat.CRAFT_TWEAKER, name); return new Add(Collections.singletonMap(res, new TreeRitualRecipe(res, CraftTweakerMC.getIngredient(saplingType), InputHelper.toStack(result), diff --git a/src/main/java/de/ellpeck/naturesaura/compat/patchouli/PatchouliCompat.java b/src/main/java/de/ellpeck/naturesaura/compat/patchouli/PatchouliCompat.java index ef937592..3173c7c1 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/patchouli/PatchouliCompat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/patchouli/PatchouliCompat.java @@ -3,14 +3,13 @@ package de.ellpeck.naturesaura.compat.patchouli; import de.ellpeck.naturesaura.ModConfig; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.api.multiblock.Matcher; +import de.ellpeck.naturesaura.compat.Compat; import de.ellpeck.naturesaura.events.ClientEvents; import de.ellpeck.naturesaura.renderers.SupporterFancyHandler; import de.ellpeck.naturesaura.renderers.SupporterFancyHandler.FancyInfo; import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.TextFormatting; import net.minecraftforge.common.MinecraftForge; @@ -24,6 +23,7 @@ import vazkii.patchouli.api.PatchouliAPI; import java.time.LocalDateTime; import java.time.Month; import java.util.Collections; +import java.util.Map; public final class PatchouliCompat { @@ -101,4 +101,12 @@ public final class PatchouliCompat { } PatchouliAPI.instance.registerMultiblock(name, PatchouliAPI.instance.makeMultiblock(pattern, rawMatchers)); } + + public static T getRecipe(Map recipes, String name) { + ResourceLocation res = new ResourceLocation(name); + T recipe = recipes.get(res); + if (recipe == null) + recipe = recipes.get(new ResourceLocation(Compat.CRAFT_TWEAKER, res.getPath())); + return recipe; + } } diff --git a/src/main/java/de/ellpeck/naturesaura/compat/patchouli/ProcessorAltar.java b/src/main/java/de/ellpeck/naturesaura/compat/patchouli/ProcessorAltar.java index 4b12d8cd..03ff3c1f 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/patchouli/ProcessorAltar.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/patchouli/ProcessorAltar.java @@ -3,7 +3,6 @@ package de.ellpeck.naturesaura.compat.patchouli; import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.recipes.AltarRecipe; import net.minecraft.item.crafting.Ingredient; -import net.minecraft.util.ResourceLocation; import vazkii.patchouli.api.IComponentProcessor; import vazkii.patchouli.api.IVariableProvider; import vazkii.patchouli.api.PatchouliAPI; @@ -14,12 +13,13 @@ public class ProcessorAltar implements IComponentProcessor { @Override public void setup(IVariableProvider provider) { - ResourceLocation res = new ResourceLocation(provider.get("recipe")); - this.recipe = NaturesAuraAPI.ALTAR_RECIPES.get(res); + this.recipe = PatchouliCompat.getRecipe(NaturesAuraAPI.ALTAR_RECIPES, provider.get("recipe")); } @Override public String process(String key) { + if (this.recipe == null) + return null; switch (key) { case "input": return PatchouliAPI.instance.serializeIngredient(this.recipe.input); diff --git a/src/main/java/de/ellpeck/naturesaura/compat/patchouli/ProcessorAnimalSpawner.java b/src/main/java/de/ellpeck/naturesaura/compat/patchouli/ProcessorAnimalSpawner.java index fb691275..ebac89ae 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/patchouli/ProcessorAnimalSpawner.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/patchouli/ProcessorAnimalSpawner.java @@ -6,7 +6,6 @@ import net.minecraft.client.resources.I18n; import net.minecraft.init.Items; import net.minecraft.item.ItemMonsterPlacer; import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.registry.EntityEntry; import net.minecraftforge.fml.common.registry.ForgeRegistries; import vazkii.patchouli.api.IComponentProcessor; @@ -19,12 +18,13 @@ public class ProcessorAnimalSpawner implements IComponentProcessor { @Override public void setup(IVariableProvider provider) { - ResourceLocation res = new ResourceLocation(provider.get("recipe")); - this.recipe = NaturesAuraAPI.ANIMAL_SPAWNER_RECIPES.get(res); + this.recipe = PatchouliCompat.getRecipe(NaturesAuraAPI.ANIMAL_SPAWNER_RECIPES, provider.get("recipe")); } @Override public String process(String key) { + if (this.recipe == null) + return null; if (key.startsWith("input")) { int id = Integer.parseInt(key.substring(5)) - 1; if (this.recipe.ingredients.length > id) diff --git a/src/main/java/de/ellpeck/naturesaura/compat/patchouli/ProcessorOffering.java b/src/main/java/de/ellpeck/naturesaura/compat/patchouli/ProcessorOffering.java index 70364724..920cc15b 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/patchouli/ProcessorOffering.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/patchouli/ProcessorOffering.java @@ -2,7 +2,6 @@ package de.ellpeck.naturesaura.compat.patchouli; import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.recipes.OfferingRecipe; -import net.minecraft.util.ResourceLocation; import vazkii.patchouli.api.IComponentProcessor; import vazkii.patchouli.api.IVariableProvider; import vazkii.patchouli.api.PatchouliAPI; @@ -13,12 +12,13 @@ public class ProcessorOffering implements IComponentProcessor { @Override public void setup(IVariableProvider provider) { - ResourceLocation res = new ResourceLocation(provider.get("recipe")); - this.recipe = NaturesAuraAPI.OFFERING_RECIPES.get(res); + this.recipe = PatchouliCompat.getRecipe(NaturesAuraAPI.OFFERING_RECIPES, provider.get("recipe")); } @Override public String process(String key) { + if (this.recipe == null) + return null; switch (key) { case "input": return PatchouliAPI.instance.serializeIngredient(this.recipe.input); diff --git a/src/main/java/de/ellpeck/naturesaura/compat/patchouli/ProcessorTreeRitual.java b/src/main/java/de/ellpeck/naturesaura/compat/patchouli/ProcessorTreeRitual.java index 4a0da84d..b4be71dc 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/patchouli/ProcessorTreeRitual.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/patchouli/ProcessorTreeRitual.java @@ -2,7 +2,6 @@ package de.ellpeck.naturesaura.compat.patchouli; import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.recipes.TreeRitualRecipe; -import net.minecraft.util.ResourceLocation; import vazkii.patchouli.api.IComponentProcessor; import vazkii.patchouli.api.IVariableProvider; import vazkii.patchouli.api.PatchouliAPI; @@ -13,12 +12,13 @@ public class ProcessorTreeRitual implements IComponentProcessor { @Override public void setup(IVariableProvider provider) { - ResourceLocation res = new ResourceLocation(provider.get("recipe")); - this.recipe = NaturesAuraAPI.TREE_RITUAL_RECIPES.get(res); + this.recipe = PatchouliCompat.getRecipe(NaturesAuraAPI.TREE_RITUAL_RECIPES, provider.get("recipe")); } @Override public String process(String key) { + if (this.recipe == null) + return null; if (key.startsWith("input")) { int id = Integer.parseInt(key.substring(5)) - 1; if (this.recipe.ingredients.length > id)