Change in TiCon handlers, they now accept IIngredients (#605)

This commit is contained in:
kindlich 2018-02-18 14:31:24 +01:00 committed by Jared
parent f0de2f5a6c
commit cdcfa8c5ea
3 changed files with 59 additions and 30 deletions

View file

@ -6,12 +6,14 @@ import com.blamejared.mtlib.helpers.*;
import com.blamejared.mtlib.utils.BaseAction; import com.blamejared.mtlib.utils.BaseAction;
import crafttweaker.CraftTweakerAPI; import crafttweaker.CraftTweakerAPI;
import crafttweaker.annotations.*; import crafttweaker.annotations.*;
import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.*;
import crafttweaker.api.liquid.ILiquidStack; import crafttweaker.api.liquid.ILiquidStack;
import crafttweaker.api.minecraft.CraftTweakerMC;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.oredict.OreDictionary;
import slimeknights.mantle.util.RecipeMatch; import slimeknights.mantle.util.RecipeMatch;
import slimeknights.tconstruct.library.TinkerRegistry; import slimeknights.tconstruct.library.TinkerRegistry;
import slimeknights.tconstruct.library.events.TinkerRegisterEvent; import slimeknights.tconstruct.library.events.TinkerRegisterEvent;
@ -20,6 +22,7 @@ import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.*; import stanhebben.zenscript.annotations.*;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@ZenClass("mods.tconstruct.Casting") @ZenClass("mods.tconstruct.Casting")
@ZenRegister @ZenRegister
@ -39,15 +42,15 @@ public class Casting {
} }
@ZenMethod @ZenMethod
public static void addTableRecipe(IItemStack output, IItemStack cast, ILiquidStack fluid, int amount, @Optional boolean consumeCast, @Optional int time) { public static void addTableRecipe(IItemStack output, IIngredient cast, ILiquidStack fluid, int amount, @Optional boolean consumeCast, @Optional int time) {
init(); init();
ModTweaker.LATE_ADDITIONS.add(new Add(InputHelper.toStack(output), InputHelper.toStack(cast), InputHelper.toFluid(fluid), amount, true, consumeCast, time)); ModTweaker.LATE_ADDITIONS.add(new Add(InputHelper.toStack(output), cast, InputHelper.toFluid(fluid), amount, true, consumeCast, time));
} }
@ZenMethod @ZenMethod
public static void addBasinRecipe(IItemStack output, IItemStack cast, ILiquidStack fluid, int amount, @Optional boolean consumeCast, @Optional int time) { public static void addBasinRecipe(IItemStack output, IIngredient cast, ILiquidStack fluid, int amount, @Optional boolean consumeCast, @Optional int time) {
init(); init();
ModTweaker.LATE_ADDITIONS.add(new Add(InputHelper.toStack(output), InputHelper.toStack(cast), InputHelper.toFluid(fluid), amount, false, consumeCast, time)); ModTweaker.LATE_ADDITIONS.add(new Add(InputHelper.toStack(output), cast, InputHelper.toFluid(fluid), amount, false, consumeCast, time));
} }
@ZenMethod @ZenMethod
@ -140,14 +143,15 @@ public class Casting {
private static class Add extends BaseAction { private static class Add extends BaseAction {
private ItemStack output, cast; private ItemStack output;
IIngredient cast;
private FluidStack fluid; private FluidStack fluid;
private int amount; private int amount;
private boolean table; private boolean table;
private boolean consumeCast; private boolean consumeCast;
private int time; private int time;
public Add(ItemStack output, ItemStack cast, FluidStack fluid, int amount, boolean table, boolean consumeCast, int time) { public Add(ItemStack output, IIngredient cast, FluidStack fluid, int amount, boolean table, boolean consumeCast, int time) {
super("Casting"); super("Casting");
this.output = output; this.output = output;
this.cast = cast; this.cast = cast;
@ -161,8 +165,18 @@ public class Casting {
@Override @Override
public void apply() { public void apply() {
RecipeMatch rm = null; RecipeMatch rm = null;
if(cast != ItemStack.EMPTY) { if(cast != null) {
rm = RecipeMatch.ofNBT(cast); List<ItemStack> validCasts = cast.getItems().stream().map(CraftTweakerMC::getItemStack).collect(Collectors.toList());
if(validCasts.isEmpty())
CraftTweakerAPI.logInfo("Could not find matching items for " + cast.toString() + ". Substituting empty cast for recipe with output " + output.getDisplayName());
else if(validCasts.size() == 1) //Keep compat to old handler
if(validCasts.get(0).getMetadata() == OreDictionary.WILDCARD_VALUE) {
rm = RecipeMatch.of(validCasts, output.getCount());
} else {
rm = RecipeMatch.ofNBT(validCasts.get(0), output.getCount());
}
else
rm = RecipeMatch.of(validCasts, output.getCount());
} }
if(table) if(table)
TinkerRegistry.registerTableCasting(new CastingRecipeTweaker(output, rm, new FluidStack(fluid, amount), time, consumeCast, false)); TinkerRegistry.registerTableCasting(new CastingRecipeTweaker(output, rm, new FluidStack(fluid, amount), time, consumeCast, false));

View file

@ -6,18 +6,20 @@ import com.blamejared.mtlib.helpers.*;
import com.blamejared.mtlib.utils.BaseAction; import com.blamejared.mtlib.utils.BaseAction;
import crafttweaker.CraftTweakerAPI; import crafttweaker.CraftTweakerAPI;
import crafttweaker.annotations.*; import crafttweaker.annotations.*;
import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.*;
import crafttweaker.api.minecraft.CraftTweakerMC;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.mantle.util.RecipeMatch; import slimeknights.mantle.util.RecipeMatch;
import slimeknights.tconstruct.library.TinkerRegistry; import slimeknights.tconstruct.library.*;
import slimeknights.tconstruct.library.events.TinkerRegisterEvent; import slimeknights.tconstruct.library.events.TinkerRegisterEvent;
import stanhebben.zenscript.annotations.Optional; import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.*; import stanhebben.zenscript.annotations.*;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@ZenClass("mods.tconstruct.Drying") @ZenClass("mods.tconstruct.Drying")
@ZenRegister @ZenRegister
@ -35,9 +37,9 @@ public class Drying {
} }
@ZenMethod @ZenMethod
public static void addRecipe(IItemStack output, IItemStack input, int time) { public static void addRecipe(IItemStack output, IIngredient input, int time) {
init(); init();
ModTweaker.LATE_ADDITIONS.add(new Add(InputHelper.toStack(output), InputHelper.toStack(input), time)); ModTweaker.LATE_ADDITIONS.add(new Add(InputHelper.toStack(output), input, time));
} }
@ZenMethod @ZenMethod
@ -48,19 +50,24 @@ public class Drying {
private static class Add extends BaseAction { private static class Add extends BaseAction {
private ItemStack output, input; private final ItemStack output;
private int time; private final IIngredient ingredient;
private final int time;
public Add(ItemStack output, ItemStack input, int time) { public Add(ItemStack output, IIngredient input, int time) {
super("Drying"); super("Drying");
this.output = output; this.output = output;
this.input = input; this.ingredient = input;
this.time = time; this.time = time;
} }
@Override @Override
public void apply() { public void apply() {
TinkerRegistry.addDryingRecipe(new DryingRecipeTweaker(new RecipeMatch.Item(input, 1), output, time)); List<ItemStack> validIngredients = ingredient.getItems().stream().map(CraftTweakerMC::getItemStack).collect(Collectors.toList());
if(validIngredients.isEmpty())
CraftTweakerAPI.logInfo("Could not find matching items for " + ingredient.toString() + ". Ignoring " + name + " recipe for " + output.getDisplayName());
else
TinkerRegistry.addDryingRecipe(new DryingRecipeTweaker(RecipeMatch.of(validIngredients), output, time));
} }
@Override @Override

View file

@ -8,8 +8,9 @@ import com.google.common.collect.*;
import crafttweaker.CraftTweakerAPI; import crafttweaker.CraftTweakerAPI;
import crafttweaker.annotations.*; import crafttweaker.annotations.*;
import crafttweaker.api.entity.IEntityDefinition; import crafttweaker.api.entity.IEntityDefinition;
import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.*;
import crafttweaker.api.liquid.ILiquidStack; import crafttweaker.api.liquid.ILiquidStack;
import crafttweaker.api.minecraft.CraftTweakerMC;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
@ -19,10 +20,12 @@ import net.minecraftforge.fml.common.registry.EntityEntry;
import slimeknights.mantle.util.RecipeMatch; import slimeknights.mantle.util.RecipeMatch;
import slimeknights.tconstruct.library.TinkerRegistry; import slimeknights.tconstruct.library.TinkerRegistry;
import slimeknights.tconstruct.library.events.TinkerRegisterEvent; import slimeknights.tconstruct.library.events.TinkerRegisterEvent;
import slimeknights.tconstruct.library.smeltery.MeltingRecipe;
import stanhebben.zenscript.annotations.Optional; import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.*; import stanhebben.zenscript.annotations.*;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@ZenClass("mods.tconstruct.Melting") @ZenClass("mods.tconstruct.Melting")
@ZenRegister @ZenRegister
@ -42,9 +45,9 @@ public class Melting {
} }
@ZenMethod @ZenMethod
public static void addRecipe(ILiquidStack output, IItemStack input, @Optional int temp) { public static void addRecipe(ILiquidStack output, IIngredient input, @Optional int temp) {
init(); init();
ModTweaker.LATE_ADDITIONS.add(new Melting.Add(InputHelper.toFluid(output), InputHelper.toStack(input), temp)); ModTweaker.LATE_ADDITIONS.add(new Melting.Add(InputHelper.toFluid(output), input, temp));
} }
@ -68,23 +71,28 @@ public class Melting {
private static class Add extends BaseAction { private static class Add extends BaseAction {
private FluidStack output; private final FluidStack output;
private ItemStack input; private final IIngredient ingredient;
private int temp; private final int temp;
public Add(FluidStack output, ItemStack input, int temp) { public Add(FluidStack output, IIngredient ingredient, int temp) {
super("Melting"); super("Melting");
this.output = output; this.output = output;
this.input = input;
this.temp = temp; this.temp = temp;
this.ingredient = ingredient;
} }
@Override @Override
public void apply() { public void apply() {
if(temp != 0) List<ItemStack> validIngredients = ingredient.getItems().stream().map(CraftTweakerMC::getItemStack).collect(Collectors.toList());
TinkerRegistry.registerMelting(new MeltingRecipeTweaker(RecipeMatch.of(input, output.amount), output, temp)); if(validIngredients.isEmpty())
else CraftTweakerAPI.logInfo("Could not find matching items for " + ingredient.toString() + ". Ignoring Melting recipe for " + output.getLocalizedName());
TinkerRegistry.registerMelting(new MeltingRecipeTweaker(RecipeMatch.of(input, output.amount), output));
else if(temp == 0) {
TinkerRegistry.registerMelting(new MeltingRecipeTweaker(RecipeMatch.of(validIngredients, output.amount), output));
} else {
TinkerRegistry.registerMelting(new MeltingRecipeTweaker(RecipeMatch.of(validIngredients, output.amount), output, temp));
}
} }
@Override @Override