From a797c65e91853fe99634127297baf1d58a699a41 Mon Sep 17 00:00:00 2001 From: Jared Date: Thu, 14 Sep 2017 19:16:24 +0200 Subject: [PATCH] Added TiC melting --- .../blamejared/compat/tconstruct/Melting.java | 108 ++++++++++++++++++ .../recipes/MeltingRecipeTweaker.java | 24 ++++ 2 files changed, 132 insertions(+) create mode 100644 src/main/java/com/blamejared/compat/tconstruct/Melting.java create mode 100644 src/main/java/com/blamejared/compat/tconstruct/recipes/MeltingRecipeTweaker.java diff --git a/src/main/java/com/blamejared/compat/tconstruct/Melting.java b/src/main/java/com/blamejared/compat/tconstruct/Melting.java new file mode 100644 index 00000000..f3eec83d --- /dev/null +++ b/src/main/java/com/blamejared/compat/tconstruct/Melting.java @@ -0,0 +1,108 @@ +package com.blamejared.compat.tconstruct; + +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 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 slimeknights.tconstruct.library.TinkerRegistry; +import slimeknights.tconstruct.library.events.TinkerRegisterEvent; +import stanhebben.zenscript.annotations.*; +import stanhebben.zenscript.annotations.Optional; + +import java.util.*; + +@ZenClass("mods.tconstruct.Melting") +@ZenRegister +@ModOnly("tconstruct") +public class Melting { + + public static final List REMOVED_RECIPES = new LinkedList<>(); + private static boolean init = false; + + private static void init() { + if(!init) { + MinecraftForge.EVENT_BUS.register(new Melting()); + init = true; + } + } + + @ZenMethod + public static void addRecipe(ILiquidStack output, IItemStack input, @Optional int temp) { + init(); + ModTweaker.LATE_ADDITIONS.add(new Melting.Add(InputHelper.toFluid(output), InputHelper.toStack(input), temp)); + } + + @ZenMethod + public static void removeRecipe(ILiquidStack output) { + init(); + CraftTweakerAPI.apply(new Melting.Remove(output)); + } + + private static class Add extends BaseUndoable { + + private FluidStack output; + private ItemStack input; + private int temp; + + public Add(FluidStack output, ItemStack input, int temp) { + super("Melting"); + this.output = output; + this.input = input; + this.temp = temp; + } + + @Override + public void apply() { + if(temp != 0) + TinkerRegistry.registerMelting(new MeltingRecipeTweaker(RecipeMatch.of(input, output.amount), output, temp)); + else + TinkerRegistry.registerMelting(new MeltingRecipeTweaker(RecipeMatch.of(input, output.amount), output)); + } + + @Override + protected String getRecipeInfo() { + return LogHelper.getStackDescription(output); + } + } + + private static class Remove extends BaseUndoable { + + private ILiquidStack output; + + protected Remove(ILiquidStack output) { + super("Melting"); + this.output = output; + } + + @Override + public void apply() { + REMOVED_RECIPES.add(output); + } + + @Override + protected String getRecipeInfo() { + return LogHelper.getStackDescription(output); + } + } + + @SubscribeEvent + public void onTinkerRegister(TinkerRegisterEvent.MeltingRegisterEvent event) { + if(event.getRecipe() instanceof MeltingRecipeTweaker) { + return; + } + for(ILiquidStack stack : REMOVED_RECIPES) { + if(event.getRecipe().getResult().isFluidEqual(((FluidStack) stack.getInternal()))) { + event.setCanceled(true); + } + } + } +} diff --git a/src/main/java/com/blamejared/compat/tconstruct/recipes/MeltingRecipeTweaker.java b/src/main/java/com/blamejared/compat/tconstruct/recipes/MeltingRecipeTweaker.java new file mode 100644 index 00000000..a2ecc083 --- /dev/null +++ b/src/main/java/com/blamejared/compat/tconstruct/recipes/MeltingRecipeTweaker.java @@ -0,0 +1,24 @@ +package com.blamejared.compat.tconstruct.recipes; + +import net.minecraftforge.fluids.*; +import slimeknights.mantle.util.RecipeMatch; +import slimeknights.tconstruct.library.smeltery.MeltingRecipe; + +public class MeltingRecipeTweaker extends MeltingRecipe { + + public MeltingRecipeTweaker(RecipeMatch input, Fluid output) { + super(input, output); + } + + public MeltingRecipeTweaker(RecipeMatch input, FluidStack output) { + super(input, output); + } + + public MeltingRecipeTweaker(RecipeMatch input, Fluid output, int temperature) { + super(input, output, temperature); + } + + public MeltingRecipeTweaker(RecipeMatch input, FluidStack output, int temperature) { + super(input, output, temperature); + } +}