Search in sources :

Example 11 with CountableIngredient

use of gregtech.api.recipes.CountableIngredient in project GregTech by GregTechCE.

the class RecipeMapFluidCanner method findRecipe.

@Override
@Nullable
public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack> fluidInputs, int outputFluidTankCapacity, MatchingMode mode) {
    Recipe recipe = super.findRecipe(voltage, inputs, fluidInputs, outputFluidTankCapacity, mode);
    if (inputs.size() == 0 || inputs.get(0).isEmpty() || recipe != null)
        return recipe;
    // Fail early if input isn't a fluid container
    if (!inputs.get(0).hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null))
        return null;
    // Make a copy to use for creating recipes
    ItemStack inputStack = inputs.get(0).copy();
    inputStack.setCount(1);
    // Make another copy to use for draining and filling
    ItemStack fluidHandlerItemStack = inputStack.copy();
    IFluidHandlerItem fluidHandlerItem = fluidHandlerItemStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
    if (fluidHandlerItem == null)
        return null;
    FluidStack containerFluid = fluidHandlerItem.drain(Integer.MAX_VALUE, true);
    if (containerFluid != null) {
        // if we actually drained something, then it's draining recipe
        return recipeBuilder().inputs(new CountableIngredient(new NBTIngredient(inputStack), 1)).outputs(fluidHandlerItem.getContainer()).fluidOutputs(containerFluid).duration(Math.max(16, containerFluid.amount / 64)).EUt(4).build().getResult();
    }
    // if we didn't drain anything, try filling container
    if (!fluidInputs.isEmpty() && fluidInputs.get(0) != null) {
        FluidStack inputFluid = fluidInputs.get(0).copy();
        inputFluid.amount = fluidHandlerItem.fill(inputFluid, true);
        if (inputFluid.amount > 0) {
            return recipeBuilder().inputs(new CountableIngredient(new NBTIngredient(inputStack), 1)).fluidInputs(inputFluid).outputs(fluidHandlerItem.getContainer()).duration(Math.max(16, inputFluid.amount / 64)).EUt(4).build().getResult();
        }
    }
    return null;
}
Also used : Recipe(gregtech.api.recipes.Recipe) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) FluidStack(net.minecraftforge.fluids.FluidStack) NBTIngredient(gregtech.api.recipes.ingredients.NBTIngredient) ItemStack(net.minecraft.item.ItemStack) CountableIngredient(gregtech.api.recipes.CountableIngredient) Nullable(javax.annotation.Nullable)

Aggregations

CountableIngredient (gregtech.api.recipes.CountableIngredient)11 ItemStack (net.minecraft.item.ItemStack)11 IntCircuitIngredient (gregtech.api.recipes.ingredients.IntCircuitIngredient)6 UnificationEntry (gregtech.api.unification.stack.UnificationEntry)5 Recipe (gregtech.api.recipes.Recipe)3 FluidStack (net.minecraftforge.fluids.FluidStack)3 NBTIngredient (gregtech.api.recipes.ingredients.NBTIngredient)2 Nullable (javax.annotation.Nullable)2 MetaItem (gregtech.api.items.metaitem.MetaItem)1 ChanceEntry (gregtech.api.recipes.Recipe.ChanceEntry)1 RecipeMap (gregtech.api.recipes.RecipeMap)1 BlastRecipeBuilder (gregtech.api.recipes.builders.BlastRecipeBuilder)1 RecipeProperty (gregtech.api.recipes.recipeproperties.RecipeProperty)1 OreDictUnifier (gregtech.api.unification.OreDictUnifier)1 IngotMaterial (gregtech.api.unification.material.type.IngotMaterial)1 MaterialStack (gregtech.api.unification.stack.MaterialStack)1 ItemStackHashStrategy (gregtech.api.util.ItemStackHashStrategy)1 JEIHelpers (gregtech.integration.jei.utils.JEIHelpers)1 Hash (it.unimi.dsi.fastutil.Hash)1 Object2ObjectOpenCustomHashMap (it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap)1