From 304834893e007f6cefa1613f5a6a8e7b39b28561 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 14 Dec 2018 00:33:39 +0100 Subject: [PATCH] Added offering tweaker for CraftTweaker --- .../compat/crafttweaker/OfferingTweaker.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/OfferingTweaker.java diff --git a/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/OfferingTweaker.java b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/OfferingTweaker.java new file mode 100644 index 00000000..e99895ac --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/compat/crafttweaker/OfferingTweaker.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.OfferingRecipe; +import de.ellpeck.naturesaura.api.recipes.ing.AmountIngredient; +import net.minecraft.item.crafting.Ingredient; +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 + ".Offering") +public final class OfferingTweaker { + + @ZenMethod + public static void addRecipe(String name, IItemStack input, IItemStack startItem, IItemStack output) { + CraftTweakerCompat.SCHEDULED_ACTIONS.add(() -> { + ResourceLocation res = new ResourceLocation(name); + return new Add(Collections.singletonMap(res, new OfferingRecipe(res, + new AmountIngredient(InputHelper.toStack(input)), + Ingredient.fromStacks(InputHelper.toStack(startItem)), + InputHelper.toStack(output)))); + }); + } + + @ZenMethod + 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("Tree Ritual", NaturesAuraAPI.OFFERING_RECIPES, map); + } + + @Override + protected String getRecipeInfo(Map.Entry recipe) { + return LogHelper.getStackDescription(recipe.getValue().output); + } + } +}