diff --git a/CraftTweakerCompat.md b/CraftTweakerCompat.md index ee5e17b1..f4bb6ca5 100644 --- a/CraftTweakerCompat.md +++ b/CraftTweakerCompat.md @@ -1,5 +1,7 @@ # Editing Nature's Aura recipes with CraftTweaker -Note that both [CraftTweaker](https://minecraft.curseforge.com/projects/crafttweaker) and [MTLib](https://minecraft.curseforge.com/projects/mtlib) are required for this compatibility. +Note that [CraftTweaker](https://minecraft.curseforge.com/projects/crafttweaker) is required for this compatibility. + +***This documentation is for 1.15. For the 1.12 documentation, [click here](https://github.com/Ellpeck/NaturesAura/blob/1.12/CraftTweakerCompat.md).*** 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. @@ -14,37 +16,54 @@ __The replacement recipe that is added for any given item inside of Nature's Aur 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", , [, ]); +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)` +```zs +mods.naturesaura.Altar.addRecipe(String name, IIngredient input, IItemStack output, String auraType, int aura, int time, IIngredient catalyst) +``` +- `auraType` is the type of aura required for this recipe. For the regular Natural Altar, use `naturesaura:overworld`. For the nether variant of the altar, use `naturesaura:nether`. - `catalyst` is the catalyst block that is placed on one of the four corner blocks, can be `null` -`mods.naturesaura.Altar.removeRecipe(IItemStack output)` +```zs +mods.naturesaura.Altar.removeRecipe(IItemStack output) +``` ## Altar of Birthing -`mods.naturesaura.AnimalSpawner.addRecipe(String name, String entity, int aura, int time, IIngredient[] ingredients)` +```zs +mods.naturesaura.AnimalSpawner.addRecipe(String name, String entity, int aura, int time, IIngredient[] ingredients) +``` - `entity` is the registry name of the entity that you want to spawn -`mods.naturesaura.AnimalSpawner.removeRecipe(String name)` +```zs +mods.naturesaura.AnimalSpawner.removeRecipe(String name) +``` - `entity` is the registry name of the entity whose spawning recipe should be removed ## Offering to the Gods -`mods.naturesaura.Offering.addRecipe(String name, IIngredient input, int inputAmount, IIngredient startItem, IItemStack output)` +```zs +mods.naturesaura.Offering.addRecipe(String name, IIngredient input, int inputAmount, IIngredient startItem, IItemStack output) +``` - `inputAmount` is the amount of items required for the input. Note that this means that the amount of the `input` variable is ignored - `startItem` is the item required to start the offering, should pretty much always be `naturesaura:calling_spirit` -`mods.naturesaura.Offering.removeRecipe(IItemStack output)` +```zs +mods.naturesaura.Offering.removeRecipe(IItemStack output) +``` ## Ritual of the Forest -`mods.naturesaura.TreeRitual.addRecipe(String name, IIngredient saplingType, IItemStack result, int time, IIngredient[] items)` +```zs +mods.naturesaura.TreeRitual.addRecipe(String name, IIngredient saplingType, IItemStack result, int time, IIngredient[] items) +``` - `saplingType` is an item representation of the sapling that needs to be placed and grown into a tree - `items` are the items that need to be placed on the wooden stands -`mods.naturesaura.TreeRitual.removeRecipe(IItemStack output)` \ No newline at end of file +```zs +mods.naturesaura.TreeRitual.removeRecipe(IItemStack output) +``` \ No newline at end of file diff --git a/src/main/java/de/ellpeck/naturesaura/NaturesAura.java b/src/main/java/de/ellpeck/naturesaura/NaturesAura.java index 1cbd325f..c1df17d0 100644 --- a/src/main/java/de/ellpeck/naturesaura/NaturesAura.java +++ b/src/main/java/de/ellpeck/naturesaura/NaturesAura.java @@ -68,7 +68,7 @@ public final class NaturesAura { Helper.registerCap(IAuraChunk.class); Helper.registerCap(IWorldData.class); - Compat.preInit(); + Compat.setup(); PacketHandler.init(); new Multiblocks(); @@ -87,7 +87,6 @@ public final class NaturesAura { } private void postInit(FMLCommonSetupEvent event) { - Compat.postInit(); proxy.postInit(event); } diff --git a/src/main/java/de/ellpeck/naturesaura/compat/Compat.java b/src/main/java/de/ellpeck/naturesaura/compat/Compat.java index bcae9af6..94de3002 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/Compat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/Compat.java @@ -2,7 +2,6 @@ package de.ellpeck.naturesaura.compat; import com.google.common.collect.ImmutableMap; import de.ellpeck.naturesaura.NaturesAura; -import de.ellpeck.naturesaura.compat.crafttweaker.CraftTweakerCompat; import de.ellpeck.naturesaura.compat.enchantibility.EnchantibilityCompat; import de.ellpeck.naturesaura.compat.patchouli.PatchouliCompat; import de.ellpeck.naturesaura.data.ItemTagProvider; @@ -18,22 +17,17 @@ public final class Compat { private static final Map> MODULE_TYPES = ImmutableMap.>builder() .put("patchouli", PatchouliCompat::new) .put("curios", CuriosCompat::new) - .put("crafttweaker", CraftTweakerCompat::new) .put("enchantability", EnchantibilityCompat::new) .build(); private static final Map MODULES = new HashMap<>(); - public static void preInit() { + public static void setup() { populateModules(ModList.get()::isLoaded); - MODULES.values().forEach(ICompat::preInit); + MODULES.values().forEach(ICompat::setup); } - public static void preInitClient() { - MODULES.values().forEach(ICompat::preInitClient); - } - - public static void postInit() { - MODULES.values().forEach(ICompat::postInit); + public static void setupClient() { + MODULES.values().forEach(ICompat::setupClient); } public static boolean hasCompat(String mod) { diff --git a/src/main/java/de/ellpeck/naturesaura/compat/CuriosCompat.java b/src/main/java/de/ellpeck/naturesaura/compat/CuriosCompat.java index 4780d9ae..acd4a8e0 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/CuriosCompat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/CuriosCompat.java @@ -41,11 +41,16 @@ public class CuriosCompat implements ICompat { .build(); @Override - public void preInit() { + public void setup() { FMLJavaModLoadingContext.get().getModEventBus().register(this); // inter mod comms MinecraftForge.EVENT_BUS.register(this); // capabilities } + @Override + public void setupClient() { + + } + @SubscribeEvent public void sendImc(InterModEnqueueEvent event) { TYPES.values().stream().distinct().forEach(t -> { @@ -85,16 +90,6 @@ public class CuriosCompat implements ICompat { } } - @Override - public void preInitClient() { - - } - - @Override - public void postInit() { - - } - @Override public void addItemTags(ItemTagProvider provider) { for (Map.Entry> entry : TYPES.entrySet()) diff --git a/src/main/java/de/ellpeck/naturesaura/compat/ICompat.java b/src/main/java/de/ellpeck/naturesaura/compat/ICompat.java index 22854a9f..4408a006 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/ICompat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/ICompat.java @@ -4,11 +4,9 @@ import de.ellpeck.naturesaura.data.ItemTagProvider; public interface ICompat { - void preInit(); + void setup(); - void preInitClient(); - - void postInit(); + void setupClient(); void addItemTags(ItemTagProvider provider); } diff --git a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AddAction.java b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AddAction.java new file mode 100644 index 00000000..c692318f --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AddAction.java @@ -0,0 +1,29 @@ +package de.ellpeck.naturesaura.compat.crafttweaker; + +import com.blamejared.crafttweaker.api.actions.IAction; +import net.minecraft.util.ResourceLocation; + +import java.util.Map; + +public class AddAction implements IAction { + + private final Map registry; + private final ResourceLocation res; + private final T recipe; + + public AddAction(Map registry, ResourceLocation res, T recipe) { + this.registry = registry; + this.res = res; + this.recipe = recipe; + } + + @Override + public void apply() { + this.registry.put(this.res, this.recipe); + } + + @Override + public String describe() { + return "Adding recipe " + this.res; + } +} 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 8ea99358..46415cac 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AltarTweaker.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AltarTweaker.java @@ -1,70 +1,40 @@ -/* TODO crafttweaker or whatever package de.ellpeck.naturesaura.compat.crafttweaker; +import com.blamejared.crafttweaker.api.CraftTweakerAPI; import com.blamejared.crafttweaker.api.annotations.ZenRegister; import com.blamejared.crafttweaker.api.item.IIngredient; import com.blamejared.crafttweaker.api.item.IItemStack; -import com.blamejared.crafttweaker.api.minecraft.CraftTweakerMC; 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.item.crafting.Ingredient; import net.minecraft.util.ResourceLocation; +import org.openzen.zencode.java.ZenCodeType; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; +import java.util.*; @ZenRegister -@Zen("mods." + NaturesAura.MOD_ID + ".Altar") +@ZenCodeType.Name("mods." + NaturesAura.MOD_ID + ".Altar") 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(Compat.CRAFT_TWEAKER, name); - return new Add(Collections.singletonMap(res, new AltarRecipe(res, - CraftTweakerMC.getIngredient(input), - InputHelper.toStack(output), - CraftTweakerMC.getIngredient(catalyst), - aura, time))); - }); + @ZenCodeType.Method + public static void addRecipe(String name, IIngredient input, IItemStack output, String auraType, int aura, int time, @ZenCodeType.Optional IIngredient catalyst) { + ResourceLocation res = new ResourceLocation("crafttweaker", name); + CraftTweakerAPI.apply(new AddAction<>(NaturesAuraAPI.ALTAR_RECIPES, res, new AltarRecipe(res, + input.asVanillaIngredient(), + output.getInternal(), + NaturesAuraAPI.AURA_TYPES.get(new ResourceLocation(auraType)), + catalyst == null ? Ingredient.EMPTY : catalyst.asVanillaIngredient(), + aura, time))); } - @ZenMethod + @ZenCodeType.Method public static void removeRecipe(IItemStack output) { - CraftTweakerCompat.SCHEDULED_ACTIONS.add(() -> { - Map recipes = new HashMap<>(); - for (AltarRecipe recipe : NaturesAuraAPI.ALTAR_RECIPES.values()) - if (Helper.areItemsEqual(recipe.output, InputHelper.toStack(output), true)) - recipes.put(recipe.name, recipe); - return new Remove(recipes); - }); - } - - private static class Add extends BaseMapAddition { - - protected Add(Map map) { - super("Natural Altar", NaturesAuraAPI.ALTAR_RECIPES, map); - } - - @Override - protected String getRecipeInfo(Map.Entry recipe) { - return LogHelper.getStackDescription(recipe.getValue().output); - } - } - - private static class Remove extends BaseMapRemoval { - - protected Remove(Map map) { - super("Natural Altar", NaturesAuraAPI.ALTAR_RECIPES, map); - } - - @Override - protected String getRecipeInfo(Map.Entry recipe) { - return LogHelper.getStackDescription(recipe.getValue().output); - } + List recipes = new ArrayList<>(); + for (AltarRecipe recipe : NaturesAuraAPI.ALTAR_RECIPES.values()) + if (Helper.areItemsEqual(recipe.output, output.getInternal(), true)) + recipes.add(recipe.name); + CraftTweakerAPI.apply(new RemoveAction(NaturesAuraAPI.ALTAR_RECIPES, recipes)); } } -*/ 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 c66dcf0a..6d06b2ff 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AnimalSpawnerTweaker.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AnimalSpawnerTweaker.java @@ -1,68 +1,35 @@ -/* TODO crafttweaker package de.ellpeck.naturesaura.compat.crafttweaker; -import com.blamejared.mtlib.utils.BaseMapAddition; -import com.blamejared.mtlib.utils.BaseMapRemoval; -import crafttweaker.annotations.ZenRegister; -import crafttweaker.api.item.IIngredient; -import crafttweaker.api.minecraft.CraftTweakerMC; +import com.blamejared.crafttweaker.api.CraftTweakerAPI; +import com.blamejared.crafttweaker.api.annotations.ZenRegister; +import com.blamejared.crafttweaker.api.item.IIngredient; 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; -import stanhebben.zenscript.annotations.ZenMethod; +import net.minecraftforge.registries.ForgeRegistries; +import org.openzen.zencode.java.ZenCodeType; import java.util.Arrays; import java.util.Collections; import java.util.Map; @ZenRegister -@ZenClass("mods." + NaturesAura.MOD_ID + ".AnimalSpawner") +@ZenCodeType.Name("mods." + NaturesAura.MOD_ID + ".AnimalSpawner") public final class AnimalSpawnerTweaker { - @ZenMethod + @ZenCodeType.Method public static void addRecipe(String name, String entity, int aura, int time, IIngredient[] ingredients) { - CraftTweakerCompat.SCHEDULED_ACTIONS.add(() -> { - 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) - ))); - }); + ResourceLocation res = new ResourceLocation("crafttweaker", name); + CraftTweakerAPI.apply(new AddAction<>(NaturesAuraAPI.ANIMAL_SPAWNER_RECIPES, res, new AnimalSpawnerRecipe(res, + ForgeRegistries.ENTITIES.getValue(new ResourceLocation(entity)), aura, time, + Arrays.stream(ingredients).map(IIngredient::asVanillaIngredient).toArray(Ingredient[]::new)))); } - @ZenMethod + @ZenCodeType.Method public static void removeRecipe(String name) { - CraftTweakerCompat.SCHEDULED_ACTIONS.add(() -> { - ResourceLocation res = new ResourceLocation(name); - return new Remove(Collections.singletonMap(res, NaturesAuraAPI.ANIMAL_SPAWNER_RECIPES.get(res))); - }); - } - - private static class Add extends BaseMapAddition { - - protected Add(Map map) { - super("AnimalSpawner", NaturesAuraAPI.ANIMAL_SPAWNER_RECIPES, map); - } - - @Override - protected String getRecipeInfo(Map.Entry recipe) { - return recipe.getValue().name.toString(); - } - } - - private static class Remove extends BaseMapRemoval { - - protected Remove(Map map) { - super("AnimalSpawner", NaturesAuraAPI.ANIMAL_SPAWNER_RECIPES, map); - } - - @Override - protected String getRecipeInfo(Map.Entry recipe) { - return recipe.getValue().name.toString(); - } + CraftTweakerAPI.apply(new RemoveAction(NaturesAuraAPI.ANIMAL_SPAWNER_RECIPES, Collections.singletonList(new ResourceLocation(name)))); } } -*/ diff --git a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/CraftTweakerCompat.java b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/CraftTweakerCompat.java deleted file mode 100644 index 95aef4fb..00000000 --- a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/CraftTweakerCompat.java +++ /dev/null @@ -1,40 +0,0 @@ -package de.ellpeck.naturesaura.compat.crafttweaker; - -import com.blamejared.crafttweaker.api.CraftTweakerAPI; -import com.blamejared.crafttweaker.api.actions.IAction; -import de.ellpeck.naturesaura.compat.ICompat; -import de.ellpeck.naturesaura.data.ItemTagProvider; -import net.minecraftforge.fml.DeferredWorkQueue; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Supplier; - -public class CraftTweakerCompat implements ICompat { - - public static final List> SCHEDULED_ACTIONS = new ArrayList<>(); - - @Override - public void preInit() { - - } - - @Override - public void preInitClient() { - - } - - @Override - public void postInit() { - DeferredWorkQueue.runLater(() -> { - for (Supplier action : SCHEDULED_ACTIONS) - CraftTweakerAPI.apply(action.get()); - SCHEDULED_ACTIONS.clear(); - }); - } - - @Override - public void addItemTags(ItemTagProvider provider) { - - } -} 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 afae3d09..51616ee9 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/OfferingTweaker.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/OfferingTweaker.java @@ -1,14 +1,9 @@ -/* TODO crafttweaker package de.ellpeck.naturesaura.compat.crafttweaker; -import com.blamejared.mtlib.helpers.InputHelper; -import com.blamejared.mtlib.helpers.LogHelper; -import com.blamejared.mtlib.utils.BaseMapAddition; -import com.blamejared.mtlib.utils.BaseMapRemoval; -import crafttweaker.annotations.ZenRegister; -import crafttweaker.api.item.IIngredient; -import crafttweaker.api.item.IItemStack; -import crafttweaker.api.minecraft.CraftTweakerMC; +import com.blamejared.crafttweaker.api.CraftTweakerAPI; +import com.blamejared.crafttweaker.api.annotations.ZenRegister; +import com.blamejared.crafttweaker.api.item.IIngredient; +import com.blamejared.crafttweaker.api.item.IItemStack; import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.api.NaturesAuraAPI; @@ -16,61 +11,29 @@ 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; +import org.openzen.zencode.java.ZenCodeType; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; +import java.util.*; @ZenRegister -@ZenClass("mods." + NaturesAura.MOD_ID + ".Offering") +@ZenCodeType.Name("mods." + NaturesAura.MOD_ID + ".Offering") public final class OfferingTweaker { - @ZenMethod + @ZenCodeType.Method public static void addRecipe(String name, IIngredient input, int inputAmount, IIngredient startItem, IItemStack output) { - CraftTweakerCompat.SCHEDULED_ACTIONS.add(() -> { - 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), - InputHelper.toStack(output)))); - }); + ResourceLocation res = new ResourceLocation("crafttweaker", name); + CraftTweakerAPI.apply(new AddAction<>(NaturesAuraAPI.OFFERING_RECIPES, res, new OfferingRecipe(res, + new AmountIngredient(input.asVanillaIngredient(), inputAmount), + startItem.asVanillaIngredient(), + output.getInternal()))); } - @ZenMethod + @ZenCodeType.Method public static void removeRecipe(IItemStack output) { - CraftTweakerCompat.SCHEDULED_ACTIONS.add(() -> { - Map recipes = new HashMap<>(); - for (OfferingRecipe recipe : NaturesAuraAPI.OFFERING_RECIPES.values()) - if (Helper.areItemsEqual(recipe.output, InputHelper.toStack(output), true)) - recipes.put(recipe.name, recipe); - return new Remove(recipes); - }); - } - - private static class Add extends BaseMapAddition { - - protected Add(Map map) { - super("Offering", NaturesAuraAPI.OFFERING_RECIPES, map); - } - - @Override - protected String getRecipeInfo(Map.Entry recipe) { - return LogHelper.getStackDescription(recipe.getValue().output); - } - } - - private static class Remove extends BaseMapRemoval { - - protected Remove(Map map) { - super("Offering", NaturesAuraAPI.OFFERING_RECIPES, map); - } - - @Override - protected String getRecipeInfo(Map.Entry recipe) { - return LogHelper.getStackDescription(recipe.getValue().output); - } + List recipes = new ArrayList<>(); + for (OfferingRecipe recipe : NaturesAuraAPI.OFFERING_RECIPES.values()) + if (Helper.areItemsEqual(recipe.output, output.getInternal(), true)) + recipes.add(recipe.name); + CraftTweakerAPI.apply(new RemoveAction(NaturesAuraAPI.OFFERING_RECIPES, recipes)); } } -*/ diff --git a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/RemoveAction.java b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/RemoveAction.java new file mode 100644 index 00000000..9ffec172 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/RemoveAction.java @@ -0,0 +1,30 @@ +package de.ellpeck.naturesaura.compat.crafttweaker; + +import com.blamejared.crafttweaker.api.actions.IAction; +import net.minecraft.util.ResourceLocation; +import org.apache.commons.lang3.tuple.Pair; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +public class RemoveAction implements IAction { + private final Map registry; + private final List recipes; + + public RemoveAction(Map registry, List recipes) { + this.registry = registry; + this.recipes = recipes; + } + + @Override + public void apply() { + for (ResourceLocation recipe : this.recipes) + this.registry.remove(recipe); + } + + @Override + public String describe() { + return "Removing recipes " + this.recipes; + } +} 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 62a650f0..27da29a3 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/TreeRitualTweaker.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/TreeRitualTweaker.java @@ -1,14 +1,9 @@ -/* package de.ellpeck.naturesaura.compat.crafttweaker; -import com.blamejared.mtlib.helpers.InputHelper; -import com.blamejared.mtlib.helpers.LogHelper; -import com.blamejared.mtlib.utils.BaseMapAddition; -import com.blamejared.mtlib.utils.BaseMapRemoval; -import crafttweaker.annotations.ZenRegister; -import crafttweaker.api.item.IIngredient; -import crafttweaker.api.item.IItemStack; -import crafttweaker.api.minecraft.CraftTweakerMC; +import com.blamejared.crafttweaker.api.CraftTweakerAPI; +import com.blamejared.crafttweaker.api.annotations.ZenRegister; +import com.blamejared.crafttweaker.api.item.IIngredient; +import com.blamejared.crafttweaker.api.item.IItemStack; import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.api.NaturesAuraAPI; @@ -16,64 +11,31 @@ 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; -import stanhebben.zenscript.annotations.ZenMethod; +import org.openzen.zencode.java.ZenCodeType; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; +import java.util.*; @ZenRegister -@ZenClass("mods." + NaturesAura.MOD_ID + ".TreeRitual") +@ZenCodeType.Name("mods." + NaturesAura.MOD_ID + ".TreeRitual") public final class TreeRitualTweaker { - @ZenMethod + @ZenCodeType.Method public static void addRecipe(String name, IIngredient saplingType, IItemStack result, int time, IIngredient[] items) { - CraftTweakerCompat.SCHEDULED_ACTIONS.add(() -> { - ResourceLocation res = new ResourceLocation(Compat.CRAFT_TWEAKER, name); - return new Add(Collections.singletonMap(res, new TreeRitualRecipe(res, - CraftTweakerMC.getIngredient(saplingType), - InputHelper.toStack(result), - time, - Arrays.stream(items).map(CraftTweakerMC::getIngredient).toArray(Ingredient[]::new) - ))); - }); + ResourceLocation res = new ResourceLocation("crafttweaker", name); + CraftTweakerAPI.apply(new AddAction<>(NaturesAuraAPI.TREE_RITUAL_RECIPES, res, new TreeRitualRecipe(res, + saplingType.asVanillaIngredient(), + result.getInternal(), + time, + Arrays.stream(items).map(IIngredient::asVanillaIngredient).toArray(Ingredient[]::new) + ))); } - @ZenMethod + @ZenCodeType.Method public static void removeRecipe(IItemStack output) { - CraftTweakerCompat.SCHEDULED_ACTIONS.add(() -> { - Map recipes = new HashMap<>(); - for (TreeRitualRecipe recipe : NaturesAuraAPI.TREE_RITUAL_RECIPES.values()) - if (Helper.areItemsEqual(recipe.result, InputHelper.toStack(output), true)) - recipes.put(recipe.name, recipe); - return new Remove(recipes); - }); - } - - private static class Add extends BaseMapAddition { - - protected Add(Map map) { - super("Tree Ritual", NaturesAuraAPI.TREE_RITUAL_RECIPES, map); - } - - @Override - protected String getRecipeInfo(Map.Entry recipe) { - return LogHelper.getStackDescription(recipe.getValue().result); - } - } - - private static class Remove extends BaseMapRemoval { - - protected Remove(Map map) { - super("Tree Ritual", NaturesAuraAPI.TREE_RITUAL_RECIPES, map); - } - - @Override - protected String getRecipeInfo(Map.Entry recipe) { - return LogHelper.getStackDescription(recipe.getValue().result); - } + List recipes = new ArrayList<>(); + for (TreeRitualRecipe recipe : NaturesAuraAPI.TREE_RITUAL_RECIPES.values()) + if (Helper.areItemsEqual(recipe.result, output.getInternal(), true)) + recipes.add(recipe.name); + CraftTweakerAPI.apply(new RemoveAction(NaturesAuraAPI.TREE_RITUAL_RECIPES, recipes)); } } -*/ diff --git a/src/main/java/de/ellpeck/naturesaura/compat/enchantibility/EnchantibilityCompat.java b/src/main/java/de/ellpeck/naturesaura/compat/enchantibility/EnchantibilityCompat.java index 8535fab5..06c0c5d3 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/enchantibility/EnchantibilityCompat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/enchantibility/EnchantibilityCompat.java @@ -12,7 +12,7 @@ import java.util.Collections; public class EnchantibilityCompat implements ICompat { @Override - public void preInit() { + public void setup() { DeferredWorkQueue.runLater(() -> { IInternals api = EnchantabilityApi.getInstance(); api.registerEnchantEffect(EnchantibilityAuraMending.RES, ModEnchantments.AURA_MENDING, EnchantibilityAuraMending::new); @@ -21,12 +21,7 @@ public class EnchantibilityCompat implements ICompat { } @Override - public void preInitClient() { - - } - - @Override - public void postInit() { + public void setupClient() { } 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 dba88ecc..4bf2c7cd 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/patchouli/PatchouliCompat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/patchouli/PatchouliCompat.java @@ -56,7 +56,7 @@ public class PatchouliCompat implements ICompat { } @Override - public void preInit() { + public void setup() { DeferredWorkQueue.runLater(() -> { PatchouliAPI.instance.setConfigFlag(NaturesAura.MOD_ID + ":rf_converter", ModConfig.instance.rfConverter.get()); PatchouliAPI.instance.setConfigFlag(NaturesAura.MOD_ID + ":chunk_loader", ModConfig.instance.chunkLoader.get()); @@ -64,7 +64,7 @@ public class PatchouliCompat implements ICompat { } @Override - public void preInitClient() { + public void setupClient() { MinecraftForge.EVENT_BUS.register(this); } @@ -73,11 +73,6 @@ public class PatchouliCompat implements ICompat { } - @Override - public void postInit() { - - } - @SubscribeEvent @OnlyIn(Dist.CLIENT) public void onBookDraw(BookDrawScreenEvent event) { diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java index cadd4201..c8dde9f9 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java @@ -39,7 +39,7 @@ public class ClientProxy implements IProxy { @Override public void preInit(FMLCommonSetupEvent event) { MinecraftForge.EVENT_BUS.register(new ClientEvents()); - Compat.preInitClient(); + Compat.setupClient(); ScreenManager.registerFactory(ModContainers.ENDER_CRATE, GuiEnderCrate::new); ScreenManager.registerFactory(ModContainers.ENDER_ACCESS, GuiEnderCrate::new); }