Search in sources :

Example 6 with Recipe

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

the class RecipeMapFluidCanner method findRecipe.

@Override
@Nullable
public Recipe findRecipe(long voltage, NonNullList<ItemStack> inputs, List<FluidStack> fluidInputs) {
    Recipe recipe = super.findRecipe(voltage, inputs, fluidInputs);
    if (inputs.size() == 0 || inputs.get(0).isEmpty() || recipe != null)
        return recipe;
    ItemStack inputStack = inputs.get(0);
    // we call inputStack.copy() because interacting with capability changes stack itself
    IFluidHandlerItem fluidHandlerItem = inputStack.copy().getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
    if (fluidHandlerItem != 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(inputStack).outputs(fluidHandlerItem.getContainer()).fluidOutputs(containerFluid).cannotBeBuffered().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(inputStack).fluidInputs(inputFluid).outputs(fluidHandlerItem.getContainer()).build().getResult();
            }
        }
    }
    return null;
}
Also used : Recipe(gregtech.api.recipes.Recipe) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 7 with Recipe

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

the class RecipeMapFurnace method findRecipe.

@Override
@Nullable
public Recipe findRecipe(long voltage, NonNullList<ItemStack> inputs, List<FluidStack> fluidInputs) {
    Recipe normalRecipe = super.findRecipe(voltage, inputs, fluidInputs);
    if (inputs == null || inputs.size() <= 0 || inputs.get(0).isEmpty())
        return normalRecipe;
    ItemStack output = ModHandler.getSmeltingOutput(inputs.get(0));
    return output.isEmpty() ? normalRecipe : this.recipeBuilder().notOptimized().inputs(GTUtility.copyAmount(1, inputs.get(0))).outputs(output).duration(128).EUt(4).build().getResult();
}
Also used : Recipe(gregtech.api.recipes.Recipe) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 8 with Recipe

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

the class RecipeMapFormingPress 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() < 2 || inputs.get(0).isEmpty() || inputs.get(1).isEmpty()) {
        return recipe;
    }
    if (recipe == null) {
        ItemStack moldStack = ItemStack.EMPTY;
        ItemStack itemStack = ItemStack.EMPTY;
        for (ItemStack inputStack : inputs) {
            if (MetaItems.SHAPE_MOLD_NAME.getStackForm().isItemEqual(moldStack)) {
                moldStack = inputStack;
            } else {
                itemStack = inputStack;
            }
        }
        if (!moldStack.isEmpty() && !itemStack.isEmpty()) {
            ItemStack output = GTUtility.copyAmount(1, itemStack);
            output.setStackDisplayName(inputs.get(0).getDisplayName());
            return this.recipeBuilder().notConsumable(// recipe is reusable as long as mold stack matches
            new NBTIngredient(moldStack)).inputs(GTUtility.copyAmount(1, itemStack)).outputs(output).duration(40).EUt(4).build().getResult();
        }
        return null;
    }
    return recipe;
}
Also used : Recipe(gregtech.api.recipes.Recipe) NBTIngredient(gregtech.api.recipes.ingredients.NBTIngredient) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 9 with Recipe

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

the class RecipeMapBrewer method findRecipe.

@Nullable
@Override
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 (recipe != null || GTUtility.amountOfNonNullElements(fluidInputs) < 1 || GTUtility.amountOfNonEmptyStacks(inputs) < 1) {
        return recipe;
    }
    ItemStack ingredientStack = inputs.get(0);
    FluidStack potionFluid = fluidInputs.get(0);
    PotionType potionType = PotionFluids.getPotionForFluid(potionFluid.getFluid());
    if (potionType == null || potionFluid.amount < POTION_PER_INGREDIENT) {
        // do not return recipes if not enough fluid or fluid doesn't match
        return null;
    }
    ItemStack potionStack = new ItemStack(Items.POTIONITEM);
    PotionUtils.addPotionToItemStack(potionStack, potionType);
    ItemStack resultStack = BrewingRecipeRegistry.getOutput(potionStack, ingredientStack);
    if (resultStack.isEmpty() || resultStack.getItem() != Items.POTIONITEM) {
        // if no recipe matches, or output is not a simple potion, return null
        return null;
    }
    PotionType resultingType = PotionUtils.getPotionFromItem(resultStack);
    if (resultingType == null || resultingType == PotionTypes.EMPTY) {
        // if output is not a simple potion or empty potion, return null
        return null;
    }
    Fluid outputFluid = PotionFluids.getFluidForPotion(resultingType);
    if (outputFluid == null) {
        return null;
    }
    // otherwise, return recipe for fluid potion + ingredient -> new fluid potion
    return recipeBuilder().inputs(// we can reuse recipe only if ingredient fully matches,
    new CountableIngredient(new NBTIngredient(ingredientStack), 1)).fluidInputs(GTUtility.copyAmount(POTION_PER_INGREDIENT, potionFluid)).fluidOutputs(new FluidStack(outputFluid, POTION_PER_INGREDIENT)).build().getResult();
}
Also used : Recipe(gregtech.api.recipes.Recipe) FluidStack(net.minecraftforge.fluids.FluidStack) NBTIngredient(gregtech.api.recipes.ingredients.NBTIngredient) Fluid(net.minecraftforge.fluids.Fluid) PotionType(net.minecraft.potion.PotionType) ItemStack(net.minecraft.item.ItemStack) CountableIngredient(gregtech.api.recipes.CountableIngredient) Nullable(javax.annotation.Nullable)

Example 10 with Recipe

use of gregtech.api.recipes.Recipe 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

Recipe (gregtech.api.recipes.Recipe)13 ItemStack (net.minecraft.item.ItemStack)9 Nullable (javax.annotation.Nullable)7 FluidStack (net.minecraftforge.fluids.FluidStack)5 NBTIngredient (gregtech.api.recipes.ingredients.NBTIngredient)3 CountableIngredient (gregtech.api.recipes.CountableIngredient)2 IFluidHandlerItem (net.minecraftforge.fluids.capability.IFluidHandlerItem)2 IMultipleTankHandler (gregtech.api.capability.IMultipleTankHandler)1 RecipeLogicEnergy (gregtech.api.capability.impl.RecipeLogicEnergy)1 EnumDyeColor (net.minecraft.item.EnumDyeColor)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 PotionType (net.minecraft.potion.PotionType)1 FakePlayer (net.minecraftforge.common.util.FakePlayer)1 Fluid (net.minecraftforge.fluids.Fluid)1 IFluidTank (net.minecraftforge.fluids.IFluidTank)1 IItemHandlerModifiable (net.minecraftforge.items.IItemHandlerModifiable)1