From 33c71a34f11a0b8e4afa17230c6b9cb5e7def188 Mon Sep 17 00:00:00 2001 From: Jared Date: Thu, 28 Dec 2017 21:47:00 +0200 Subject: [PATCH] Added Tcomplement support closes #541 --- build.gradle | 5 + .../compat/tcomplement/Blacklist.java | 103 +++++++++++++++ .../compat/tcomplement/Overrides.java | 117 ++++++++++++++++++ 3 files changed, 225 insertions(+) create mode 100644 src/main/java/com/blamejared/compat/tcomplement/Blacklist.java create mode 100644 src/main/java/com/blamejared/compat/tcomplement/Overrides.java diff --git a/build.gradle b/build.gradle index d4481b3..003b3a2 100644 --- a/build.gradle +++ b/build.gradle @@ -53,6 +53,7 @@ repositories { maven { url = "https://dl.bintray.com/raoulvdberge/dev/" } + } dependencies { @@ -86,6 +87,10 @@ dependencies { deobfCompile("refinedstorage:refinedstorage:1.5.9-1242+") { exclude group: 'mezz.jei' } + + deobfCompile("knightminer.tcomplement:TinkersComplement:1.12.1-0.2.1.3") { + + } } processResources { diff --git a/src/main/java/com/blamejared/compat/tcomplement/Blacklist.java b/src/main/java/com/blamejared/compat/tcomplement/Blacklist.java new file mode 100644 index 0000000..113f84d --- /dev/null +++ b/src/main/java/com/blamejared/compat/tcomplement/Blacklist.java @@ -0,0 +1,103 @@ +package com.blamejared.compat.tcomplement; + +import com.blamejared.ModTweaker; +import com.blamejared.compat.tconstruct.recipes.MeltingRecipeTweaker; +import com.blamejared.mtlib.helpers.*; +import com.blamejared.mtlib.utils.BaseUndoable; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.*; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.liquid.ILiquidStack; +import knightminer.tcomplement.library.TCompRegistry; +import knightminer.tcomplement.library.events.TCompRegisterEvent; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import slimeknights.mantle.util.RecipeMatch; +import stanhebben.zenscript.annotations.*; + +import java.util.*; + +@ZenClass("mods.tcomplement.Blacklist") +@ZenRegister +@ModOnly("tcomplement") +public class Blacklist { + + + public static final List REMOVED_RECIPES = new LinkedList<>(); + private static boolean init = false; + + private static void init() { + if(!init) { + MinecraftForge.EVENT_BUS.register(new Blacklist()); + init = true; + } + } + + @ZenMethod + public static void addRecipe(ILiquidStack output, IItemStack input) { + init(); + ModTweaker.LATE_ADDITIONS.add(new Blacklist.Add(InputHelper.toFluid(output), InputHelper.toStack(input))); + } + + @ZenMethod + public static void removeRecipe(IItemStack input) { + init(); + CraftTweakerAPI.apply(new Blacklist.Remove(input)); + } + + private static class Add extends BaseUndoable { + + private FluidStack output; + private ItemStack input; + + public Add(FluidStack output, ItemStack input) { + super("Blacklist"); + this.output = output; + this.input = input; + } + + @Override + public void apply() { + TCompRegistry.registerMelterBlacklist(RecipeMatch.of(input, output.amount)); + } + + @Override + protected String getRecipeInfo() { + return LogHelper.getStackDescription(output); + } + } + + private static class Remove extends BaseUndoable { + + private IItemStack input; + + protected Remove(IItemStack input) { + super("Blacklist"); + this.input = input; + } + + @Override + public void apply() { + REMOVED_RECIPES.add(input); + } + + @Override + protected String getRecipeInfo() { + return LogHelper.getStackDescription(input); + } + } + + @SubscribeEvent + public void onTinkerRegister(TCompRegisterEvent.MelterBlackListRegisterEvent event) { + if(event.getRecipe() instanceof MeltingRecipeTweaker) { + return; + } + for(IItemStack ent : REMOVED_RECIPES) { + if(event.getRecipe().matches(InputHelper.toStack(ent))) { + event.setCanceled(true); + } + } + } +} diff --git a/src/main/java/com/blamejared/compat/tcomplement/Overrides.java b/src/main/java/com/blamejared/compat/tcomplement/Overrides.java new file mode 100644 index 0000000..1456356 --- /dev/null +++ b/src/main/java/com/blamejared/compat/tcomplement/Overrides.java @@ -0,0 +1,117 @@ +package com.blamejared.compat.tcomplement; + +import com.blamejared.ModTweaker; +import com.blamejared.compat.tconstruct.recipes.MeltingRecipeTweaker; +import com.blamejared.mtlib.helpers.*; +import com.blamejared.mtlib.utils.BaseUndoable; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.*; +import crafttweaker.api.item.IItemStack; +import crafttweaker.api.liquid.ILiquidStack; +import knightminer.tcomplement.library.TCompRegistry; +import knightminer.tcomplement.library.events.TCompRegisterEvent; +import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import slimeknights.mantle.util.RecipeMatch; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.*; + +import java.util.*; + +@ZenClass("mods.tcomplement.Overrides") +@ZenRegister +@ModOnly("tcomplement") +public class Overrides { + + + public static final Map REMOVED_RECIPES = new LinkedHashMap<>(); + private static boolean init = false; + + private static void init() { + if(!init) { + MinecraftForge.EVENT_BUS.register(new Overrides()); + init = true; + } + } + + @ZenMethod + public static void addRecipe(ILiquidStack output, IItemStack input, @Optional int temp) { + init(); + ModTweaker.LATE_ADDITIONS.add(new Overrides.Add(InputHelper.toFluid(output), InputHelper.toStack(input), temp)); + } + + @ZenMethod + public static void removeRecipe(ILiquidStack output, @Optional IItemStack input) { + init(); + CraftTweakerAPI.apply(new Overrides.Remove(output, input)); + } + + private static class Add extends BaseUndoable { + + private FluidStack output; + private ItemStack input; + private int temp; + + public Add(FluidStack output, ItemStack input, int temp) { + super("Overrides"); + this.output = output; + this.input = input; + this.temp = temp; + } + + @java.lang.Override + public void apply() { + if(temp != 0) + TCompRegistry.registerMelterOverride(new MeltingRecipeTweaker(RecipeMatch.of(input, output.amount), output, temp)); + else + TCompRegistry.registerMelterOverride(new MeltingRecipeTweaker(RecipeMatch.of(input, output.amount), output)); + } + + @java.lang.Override + protected String getRecipeInfo() { + return LogHelper.getStackDescription(output); + } + } + + private static class Remove extends BaseUndoable { + + private ILiquidStack output; + private IItemStack input; + + protected Remove(ILiquidStack output, IItemStack input) { + super("Overrides"); + this.output = output; + this.input = input; + } + + @Override + public void apply() { + REMOVED_RECIPES.put(output, input); + } + + @Override + protected String getRecipeInfo() { + return LogHelper.getStackDescription(output); + } + } + + @SubscribeEvent + public void onTinkerRegister(TCompRegisterEvent.MelterOverrideRegisterEvent event) { + if(event.getRecipe() instanceof MeltingRecipeTweaker) { + return; + } + for(Map.Entry ent : REMOVED_RECIPES.entrySet()) { + if(event.getRecipe().getResult().isFluidEqual(((FluidStack) ent.getKey().getInternal()))) { + if(ent.getValue() != null) { + if(event.getRecipe().input.matches(NonNullList.withSize(1, (ItemStack) ent.getValue().getInternal())).isPresent()) { + event.setCanceled(true); + } + } else + event.setCanceled(true); + } + } + } +}