diff --git a/src/main/java/modtweaker/mods/bloodmagic/BloodMagic.java b/src/main/java/modtweaker/mods/bloodmagic/BloodMagic.java index 46cd36b..d7d7019 100644 --- a/src/main/java/modtweaker/mods/bloodmagic/BloodMagic.java +++ b/src/main/java/modtweaker/mods/bloodmagic/BloodMagic.java @@ -1,6 +1,8 @@ package modtweaker.mods.bloodmagic; import minetweaker.MineTweakerAPI; +import modtweaker.mods.bloodmagic.handlers.AlchemyTable; +import modtweaker.mods.bloodmagic.handlers.Altar; import modtweaker.mods.bloodmagic.handlers.SoulForge; public class BloodMagic @@ -8,5 +10,7 @@ public class BloodMagic public BloodMagic() { MineTweakerAPI.registerClass(SoulForge.class); + MineTweakerAPI.registerClass(AlchemyTable.class); + MineTweakerAPI.registerClass(Altar.class); } } diff --git a/src/main/java/modtweaker/mods/bloodmagic/BloodMagicHelper.java b/src/main/java/modtweaker/mods/bloodmagic/BloodMagicHelper.java index 2eb434b..f314112 100644 --- a/src/main/java/modtweaker/mods/bloodmagic/BloodMagicHelper.java +++ b/src/main/java/modtweaker/mods/bloodmagic/BloodMagicHelper.java @@ -1,7 +1,12 @@ package modtweaker.mods.bloodmagic; +import WayofTime.bloodmagic.api.ItemStackWrapper; +import WayofTime.bloodmagic.api.recipe.AlchemyTableRecipe; import WayofTime.bloodmagic.api.recipe.TartaricForgeRecipe; +import WayofTime.bloodmagic.api.registry.AlchemyTableRecipeRegistry; +import WayofTime.bloodmagic.api.registry.AltarRecipeRegistry; import WayofTime.bloodmagic.api.registry.TartaricForgeRecipeRegistry; +import com.google.common.collect.BiMap; import modtweaker.helpers.ReflectionHelper; import java.util.List; @@ -9,11 +14,15 @@ import java.util.List; public class BloodMagicHelper { public static List soulForgeList = null; + public static List alchemyTableList = null; + public static BiMap, AltarRecipeRegistry.AltarRecipe> altarBiMap = null; static { try { soulForgeList = ReflectionHelper.getStaticObject(TartaricForgeRecipeRegistry.class, "recipeList"); + alchemyTableList = ReflectionHelper.getStaticObject(AlchemyTableRecipeRegistry.class, "recipeList"); + altarBiMap = ReflectionHelper.getStaticObject(AltarRecipeRegistry.class, "recipes"); } catch (Exception e) { diff --git a/src/main/java/modtweaker/mods/bloodmagic/handlers/AlchemyTable.java b/src/main/java/modtweaker/mods/bloodmagic/handlers/AlchemyTable.java new file mode 100644 index 0000000..537048b --- /dev/null +++ b/src/main/java/modtweaker/mods/bloodmagic/handlers/AlchemyTable.java @@ -0,0 +1,85 @@ +package modtweaker.mods.bloodmagic.handlers; + +import WayofTime.bloodmagic.api.recipe.AlchemyTableRecipe; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import modtweaker.helpers.LogHelper; +import modtweaker.mods.bloodmagic.BloodMagicHelper; +import modtweaker.utils.BaseListAddition; +import modtweaker.utils.BaseListRemoval; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import static modtweaker.helpers.InputHelper.*; +import static modtweaker.helpers.StackHelper.matches; + +import java.util.LinkedList; +import java.util.List; + +@ZenClass("mods.bloodmagic.AlchemyTable") +public class AlchemyTable +{ + protected static final String name = "Blood Magic Alchemy Table"; + + @ZenMethod + public static void addRecipe(IItemStack output, int lpDrained, int ticksRequired, int tierRequired, IIngredient[] input) + { + MineTweakerAPI.apply(new Add(new AlchemyTableRecipe(toStack(output), lpDrained, ticksRequired, tierRequired, toObjects(input)), BloodMagicHelper.alchemyTableList)); + } + + private static class Add extends BaseListAddition { + public Add(AlchemyTableRecipe recipe, List list) { + super(SoulForge.name, list); + this.recipes.add(recipe); + } + + @Override + public String getRecipeInfo(AlchemyTableRecipe recipe) + { + return LogHelper.getStackDescription(recipe.getRecipeOutput(null)); + } + } + + @ZenMethod + public static void removeRecipe(IIngredient output) + { + remove(output, BloodMagicHelper.alchemyTableList); + } + + public static void remove(IIngredient output, List list) { + if (output == null) { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name)); + return; + } + + List recipes = new LinkedList(); + + for(AlchemyTableRecipe recipe : list) + { + if(matches(output, toIItemStack(recipe.getRecipeOutput(null)))) + recipes.add(recipe); + } + + if(!recipes.isEmpty()) + { + MineTweakerAPI.apply(new Remove(list, recipes)); + } + else + { + LogHelper.logWarning(String.format("No %s Recipe found for output %s. Command ignored!", SoulForge.name, output.toString())); + } + + } + + private static class Remove extends BaseListRemoval { + public Remove(List list, List recipes) { + super(SoulForge.name, list, recipes); + } + + @Override + protected String getRecipeInfo(AlchemyTableRecipe recipe) { + return LogHelper.getStackDescription(recipe.getRecipeOutput(null)); + } + } +} diff --git a/src/main/java/modtweaker/mods/bloodmagic/handlers/Altar.java b/src/main/java/modtweaker/mods/bloodmagic/handlers/Altar.java new file mode 100644 index 0000000..d32238c --- /dev/null +++ b/src/main/java/modtweaker/mods/bloodmagic/handlers/Altar.java @@ -0,0 +1,56 @@ +package modtweaker.mods.bloodmagic.handlers; + +import WayofTime.bloodmagic.api.ItemStackWrapper; +import WayofTime.bloodmagic.api.altar.EnumAltarTier; +import WayofTime.bloodmagic.api.registry.AltarRecipeRegistry; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import modtweaker.helpers.LogHelper; +import modtweaker.helpers.ReflectionHelper; +import modtweaker.mods.bloodmagic.BloodMagicHelper; +import modtweaker.utils.BaseMapAddition; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import net.minecraft.item.ItemStack; + +import static modtweaker.helpers.InputHelper.*; +import static modtweaker.helpers.StackHelper.matches; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +@ZenClass("mods.bloodmagic.Altar") +public class Altar +{ + protected static final String name = "Blood Magic Altar"; + + private static final EnumAltarTier[] altarTiers = EnumAltarTier.values(); + + @ZenMethod + public static void addRecipe(IItemStack output, int minTier, int syphon, int consumeRate, int drainRate, IItemStack[] input) + { + List inputs = Arrays.asList(toStacks(input)); + AltarRecipeRegistry.AltarRecipe temp = new AltarRecipeRegistry.AltarRecipe(inputs, toStack(output), altarTiers[minTier-1], syphon, consumeRate, drainRate); + MineTweakerAPI.apply(new Add(temp.getInput(), temp, BloodMagicHelper.altarBiMap)); + } + + private static class Add extends BaseMapAddition, AltarRecipeRegistry.AltarRecipe> + { + public Add(List inputs, AltarRecipeRegistry.AltarRecipe altarRecipe, Map, AltarRecipeRegistry.AltarRecipe> list) + { + super(Altar.name, list); + this.recipes.put(inputs, altarRecipe); + } + + @Override + public String getRecipeInfo(Entry, AltarRecipeRegistry.AltarRecipe> recipe) + { + ItemStack output = ReflectionHelper.getFinalObject(recipe.getValue(), "output"); + return LogHelper.getStackDescription(output); + } + } +} diff --git a/src/main/java/modtweaker/mods/bloodmagic/handlers/SoulForge.java b/src/main/java/modtweaker/mods/bloodmagic/handlers/SoulForge.java index e16bec5..c85cd74 100644 --- a/src/main/java/modtweaker/mods/bloodmagic/handlers/SoulForge.java +++ b/src/main/java/modtweaker/mods/bloodmagic/handlers/SoulForge.java @@ -1,6 +1,5 @@ package modtweaker.mods.bloodmagic.handlers; -import WayofTime.bloodmagic.api.registry.TartaricForgeRecipeRegistry; import minetweaker.MineTweakerAPI; import minetweaker.api.item.IIngredient; import minetweaker.api.item.IItemStack; @@ -21,7 +20,7 @@ import java.util.List; @ZenClass("mods.bloodmagic.SoulForge") public class SoulForge { - protected static final String name = "BloodMagic Soul Forge"; + protected static final String name = "Blood Magic Soul Forge"; @ZenMethod public static void addRecipe(IItemStack output, double minimumSouls, double drain, IIngredient[] input)