From dbeb2914f18081ddff1dce445c89cdc4a553237f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 11 Nov 2018 16:50:51 +0100 Subject: [PATCH] add crafttweaker compat --- build.gradle | 7 +- .../de/ellpeck/naturesaura/NaturesAura.java | 3 +- .../naturesaura/api/recipes/AltarRecipe.java | 3 + .../api/recipes/TreeRitualRecipe.java | 3 + .../de/ellpeck/naturesaura/compat/Compat.java | 14 +++- .../compat/crafttweaker/AltarTweaker.java | 74 +++++++++++++++++++ .../crafttweaker/CraftTweakerCompat.java | 19 +++++ .../crafttweaker/TreeRitualTweaker.java | 72 ++++++++++++++++++ .../naturesaura/recipes/ModRecipes.java | 18 ++--- 9 files changed, 199 insertions(+), 14 deletions(-) create mode 100644 src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AltarTweaker.java create mode 100644 src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/CraftTweakerCompat.java create mode 100644 src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/TreeRitualTweaker.java diff --git a/build.gradle b/build.gradle index 82c7be8c..7a623a3e 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,7 @@ compileJava { } repositories { + mavenCentral() maven { url = "http://dvs1.progwml6.com/files/maven" } @@ -33,9 +34,13 @@ repositories { } dependencies { + compile "vazkii.patchouli:Patchouli:1.0-6.8" + deobfCompile "mezz.jei:jei_1.12.2:4.13.1.220" deobfCompile "com.azanor.baubles:Baubles:1.12-1.5.2" - compile "vazkii.patchouli:Patchouli:1.0-6.8" + + compile "com.blamejared:MTLib:3.0.4.8" + compile "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.11.494" } diff --git a/src/main/java/de/ellpeck/naturesaura/NaturesAura.java b/src/main/java/de/ellpeck/naturesaura/NaturesAura.java index 997e450d..81676e59 100644 --- a/src/main/java/de/ellpeck/naturesaura/NaturesAura.java +++ b/src/main/java/de/ellpeck/naturesaura/NaturesAura.java @@ -63,7 +63,7 @@ public final class NaturesAura { new ModBlocks(); new ModItems(); - Compat.init(); + Compat.preInit(); PacketHandler.init(); ModRegistry.preInit(event); new Multiblocks(); @@ -86,6 +86,7 @@ public final class NaturesAura { @EventHandler public void postInit(FMLPostInitializationEvent event) { ModRegistry.postInit(event); + Compat.postInit(); proxy.postInit(event); if (ModConfig.general.removeDragonBreathContainerItem) { diff --git a/src/main/java/de/ellpeck/naturesaura/api/recipes/AltarRecipe.java b/src/main/java/de/ellpeck/naturesaura/api/recipes/AltarRecipe.java index 7d3dc83d..13c0aecb 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/recipes/AltarRecipe.java +++ b/src/main/java/de/ellpeck/naturesaura/api/recipes/AltarRecipe.java @@ -21,7 +21,10 @@ public class AltarRecipe { this.catalyst = catalyst; this.aura = aura; this.time = time; + } + public AltarRecipe register(){ NaturesAuraAPI.ALTAR_RECIPES.put(this.name, this); + return this; } } diff --git a/src/main/java/de/ellpeck/naturesaura/api/recipes/TreeRitualRecipe.java b/src/main/java/de/ellpeck/naturesaura/api/recipes/TreeRitualRecipe.java index a1579ea9..492fb5c7 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/recipes/TreeRitualRecipe.java +++ b/src/main/java/de/ellpeck/naturesaura/api/recipes/TreeRitualRecipe.java @@ -18,7 +18,10 @@ public class TreeRitualRecipe { this.items = items; this.result = result; this.time = time; + } + public TreeRitualRecipe register() { NaturesAuraAPI.TREE_RITUAL_RECIPES.put(this.name, this); + return this; } } diff --git a/src/main/java/de/ellpeck/naturesaura/compat/Compat.java b/src/main/java/de/ellpeck/naturesaura/compat/Compat.java index 0d242859..0f130d74 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/Compat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/Compat.java @@ -1,16 +1,24 @@ package de.ellpeck.naturesaura.compat; +import de.ellpeck.naturesaura.compat.crafttweaker.CraftTweakerCompat; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Loader; public final class Compat { public static boolean baubles; + public static boolean craftTweaker; - public static void init() { + public static void preInit() { baubles = Loader.isModLoaded("baubles"); - if (baubles) { + craftTweaker = Loader.isModLoaded("crafttweaker"); + + if (baubles) MinecraftForge.EVENT_BUS.register(new BaublesCompat()); - } + } + + public static void postInit() { + if (craftTweaker) + CraftTweakerCompat.postInit(); } } diff --git a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AltarTweaker.java b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AltarTweaker.java new file mode 100644 index 00000000..3943ce40 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/AltarTweaker.java @@ -0,0 +1,74 @@ +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.IItemStack; +import de.ellpeck.naturesaura.Helper; +import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import de.ellpeck.naturesaura.api.recipes.AltarRecipe; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.util.ResourceLocation; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +@ZenRegister +@ZenClass("mods." + NaturesAura.MOD_ID + ".Altar") +public final class AltarTweaker { + + @ZenMethod + public static void addRecipe(String name, IItemStack input, IItemStack output, IItemStack catalyst, int aura, int time) { + CraftTweakerCompat.SCHEDULED_ACTIONS.add(() -> { + Block block = Block.getBlockFromItem(InputHelper.toStack(catalyst).getItem()); + ResourceLocation res = new ResourceLocation(name); + return new Add(Collections.singletonMap(res, new AltarRecipe(res, + InputHelper.toStack(input), + InputHelper.toStack(output), + block == Blocks.AIR ? null : block, + aura, time))); + }); + } + + @ZenMethod + 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); + } + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/CraftTweakerCompat.java b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/CraftTweakerCompat.java new file mode 100644 index 00000000..9f13c253 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/CraftTweakerCompat.java @@ -0,0 +1,19 @@ +package de.ellpeck.naturesaura.compat.crafttweaker; + +import crafttweaker.CraftTweakerAPI; +import crafttweaker.IAction; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; + +public final class CraftTweakerCompat { + + public static final List> SCHEDULED_ACTIONS = new ArrayList<>(); + + public static void postInit() { + for (Supplier action : SCHEDULED_ACTIONS) + CraftTweakerAPI.apply(action.get()); + SCHEDULED_ACTIONS.clear(); + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/TreeRitualTweaker.java b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/TreeRitualTweaker.java new file mode 100644 index 00000000..f07655b8 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/TreeRitualTweaker.java @@ -0,0 +1,72 @@ +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.IItemStack; +import de.ellpeck.naturesaura.Helper; +import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import de.ellpeck.naturesaura.api.recipes.TreeRitualRecipe; +import net.minecraft.util.ResourceLocation; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +@ZenRegister +@ZenClass("mods." + NaturesAura.MOD_ID + ".TreeRitual") +public final class TreeRitualTweaker { + + @ZenMethod + public static void addRecipe(String name, IItemStack saplingType, IItemStack result, int time, IItemStack[] items) { + CraftTweakerCompat.SCHEDULED_ACTIONS.add(() -> { + ResourceLocation res = new ResourceLocation(name); + return new Add(Collections.singletonMap(res, new TreeRitualRecipe(res, + InputHelper.toStack(saplingType), + InputHelper.toStack(result), + time, + InputHelper.toStacks(items) + ))); + }); + } + + @ZenMethod + 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); + } + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java b/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java index c5612fc5..700127f0 100644 --- a/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java +++ b/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java @@ -20,7 +20,7 @@ public final class ModRecipes { new ItemStack(Items.SPIDER_EYE), new ItemStack(Items.GOLD_INGOT), new ItemStack(ModItems.GOLD_LEAF), - new ItemStack(ModItems.GOLD_LEAF)); + new ItemStack(ModItems.GOLD_LEAF)).register(); new TreeRitualRecipe(new ResourceLocation(NaturesAura.MOD_ID, "nature_altar"), new ItemStack(Blocks.SAPLING), new ItemStack(ModBlocks.NATURE_ALTAR), 500, new ItemStack(Blocks.STONE), @@ -28,7 +28,7 @@ public final class ModRecipes { new ItemStack(Blocks.STONE), new ItemStack(ModItems.GOLD_LEAF), new ItemStack(Items.GOLD_INGOT), - ItemAuraBottle.setType(new ItemStack(ModItems.AURA_BOTTLE), AuraType.OVERWORLD)); + ItemAuraBottle.setType(new ItemStack(ModItems.AURA_BOTTLE), AuraType.OVERWORLD)).register(); new TreeRitualRecipe(new ResourceLocation(NaturesAura.MOD_ID, "ancient_sapling"), new ItemStack(Blocks.SAPLING), new ItemStack(ModBlocks.ANCIENT_SAPLING), 200, new ItemStack(Blocks.SAPLING), @@ -36,7 +36,7 @@ public final class ModRecipes { new ItemStack(Blocks.RED_FLOWER), new ItemStack(Items.WHEAT_SEEDS), new ItemStack(Items.REEDS), - new ItemStack(ModItems.GOLD_LEAF)); + new ItemStack(ModItems.GOLD_LEAF)).register(); new TreeRitualRecipe(new ResourceLocation(NaturesAura.MOD_ID, "furnace_heater"), new ItemStack(Blocks.SAPLING), new ItemStack(ModBlocks.FURNACE_HEATER), 600, new ItemStack(ModBlocks.INFUSED_STONE), @@ -46,7 +46,7 @@ public final class ModRecipes { new ItemStack(Items.FIRE_CHARGE), new ItemStack(Items.FLINT), new ItemStack(Blocks.MAGMA), - ItemAuraBottle.setType(new ItemStack(ModItems.AURA_BOTTLE), AuraType.NETHER)); + ItemAuraBottle.setType(new ItemStack(ModItems.AURA_BOTTLE), AuraType.NETHER)).register(); new TreeRitualRecipe(new ResourceLocation(NaturesAura.MOD_ID, "conversion_catalyst"), new ItemStack(Blocks.SAPLING, 1, 3), new ItemStack(ModBlocks.CONVERSION_CATALYST), 600, new ItemStack(Blocks.STONEBRICK, 1, 1), @@ -54,20 +54,20 @@ public final class ModRecipes { new ItemStack(Items.BREWING_STAND), new ItemStack(Items.GOLD_INGOT), new ItemStack(ModItems.GOLD_LEAF), - new ItemStack(Blocks.GLOWSTONE)); + new ItemStack(Blocks.GLOWSTONE)).register(); new AltarRecipe(new ResourceLocation(NaturesAura.MOD_ID, "infused_iron"), new ItemStack(Items.IRON_INGOT), new ItemStack(ModItems.INFUSED_IRON), - null, 300, 80); + null, 300, 80).register(); new AltarRecipe(new ResourceLocation(NaturesAura.MOD_ID, "infused_stone"), new ItemStack(Blocks.STONE), new ItemStack(ModBlocks.INFUSED_STONE), - null, 150, 40); + null, 150, 40).register(); new AltarRecipe(new ResourceLocation(NaturesAura.MOD_ID, "chorus"), ItemAuraBottle.setType(new ItemStack(ModItems.AURA_BOTTLE), AuraType.END), new ItemStack(Items.DRAGON_BREATH), - ModBlocks.CONVERSION_CATALYST, 350, 80); + ModBlocks.CONVERSION_CATALYST, 350, 80).register(); new AltarRecipe(new ResourceLocation(NaturesAura.MOD_ID, "leather"), new ItemStack(Items.ROTTEN_FLESH), new ItemStack(Items.LEATHER), - ModBlocks.CONVERSION_CATALYST, 400, 50); + ModBlocks.CONVERSION_CATALYST, 400, 50).register(); } }