Search in sources :

Example 1 with Recipe

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

the class RecipeMapWorkableHandler method update.

@Override
public void update() {
    if (getMetaTileEntity().getWorld().isRemote)
        return;
    if (progressTime == 0) {
        long maxVoltage = getMaxVoltage();
        Recipe pickedRecipe = recipeMap.findRecipe(previousRecipe, maxVoltage, metaTileEntity.getImportItems(), metaTileEntity.getImportFluids());
        if (pickedRecipe != null && setupAndConsumeRecipeInputs(pickedRecipe)) {
            if (pickedRecipe.canBeBuffered()) {
                this.previousRecipe = pickedRecipe;
            } else
                this.previousRecipe = null;
            setupRecipe(pickedRecipe);
        }
    } else if (workingEnabled) {
        if (drawEnergy(recipeEUt)) {
            if (++progressTime >= maxProgressTime) {
                completeRecipe();
            }
        }
    }
}
Also used : Recipe(gregtech.api.recipes.Recipe)

Example 2 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, NonNullList<ItemStack> inputs, List<FluidStack> fluidInputs) {
    Recipe recipe = super.findRecipe(voltage, inputs, fluidInputs);
    if (inputs.size() < 2 || inputs.get(0).isEmpty() || inputs.get(1).isEmpty())
        return recipe;
    if (recipe == null) {
        if (MetaItems.SHAPE_MOLD_NAME.getStackForm().isItemEqual(inputs.get(0))) {
            ItemStack output = GTUtility.copyAmount(1, inputs.get(1));
            output.setStackDisplayName(inputs.get(0).getDisplayName());
            return this.recipeBuilder().cannotBeBuffered().notOptimized().notConsumable(MetaItems.SHAPE_MOLD_NAME).inputs(GTUtility.copyAmount(1, inputs.get(1))).outputs(output).duration(128).EUt(8).build().getResult();
        }
        if (MetaItems.SHAPE_MOLD_NAME.getStackForm().isItemEqual(inputs.get(1))) {
            ItemStack output = GTUtility.copyAmount(1, inputs.get(0));
            output.setStackDisplayName(inputs.get(1).getDisplayName());
            return this.recipeBuilder().cannotBeBuffered().notOptimized().notConsumable(MetaItems.SHAPE_MOLD_NAME).inputs(GTUtility.copyAmount(1, inputs.get(0))).outputs(output).duration(128).EUt(8).build().getResult();
        }
        return null;
    }
    for (ItemStack mold : inputs) {
        if (MetaItems.SCHEMATIC_CRAFTING.getStackForm().isItemEqual(mold)) {
            NBTTagCompound tag = mold.getTagCompound();
            if (tag == null)
                tag = new NBTTagCompound();
            if (!tag.hasKey("credit_security_id"))
                tag.setLong("credit_security_id", System.nanoTime());
            mold.setTagCompound(tag);
            RecipeBuilder<?> builder = this.recipeBuilder().fromRecipe(recipe).cannotBeBuffered();
            List<ItemStack> outputs = builder.getOutputs();
            ItemStack stack = outputs.get(0);
            stack.setTagCompound(tag);
            outputs.set(0, stack);
            return builder.build().getResult();
        }
    }
    return recipe;
}
Also used : Recipe(gregtech.api.recipes.Recipe) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 3 with Recipe

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

the class RecipeMapPrinter method findRecipe.

@Override
@Nullable
public Recipe findRecipe(long voltage, NonNullList<ItemStack> inputs, List<FluidStack> fluidInputs) {
    Recipe recipe = super.findRecipe(voltage, inputs, fluidInputs);
    if (recipe != null || inputs.size() == 0 || inputs.get(0).isEmpty())
        return recipe;
    ItemStack firstInputItem = inputs.get(0);
    if (fluidInputs.size() != 0 && fluidInputs.get(0) != null) {
        FluidStack fluidStack = fluidInputs.get(0);
        EnumDyeColor dyeColor = GregTechAPI.LIQUID_DYE_MAP.get(fluidStack.getFluid());
        if (dyeColor != null && fluidStack.amount >= GTValues.L) {
            ItemStack dyeItemStack = new ItemStack(Items.DYE, 1, dyeColor.getDyeDamage());
            ItemStack colouredItem = ModHandler.getRecipeOutput(null, dyeItemStack, firstInputItem);
            if (colouredItem.isEmpty())
                return null;
            return recipeBuilder().inputs(GTUtility.copyAmount(1, firstInputItem)).fluidInputs(GTUtility.copyAmount(GTValues.L, fluidStack)).outputs(colouredItem).EUt(2).duration(32).build().getResult();
        }
    }
    return null;
}
Also used : Recipe(gregtech.api.recipes.Recipe) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack) EnumDyeColor(net.minecraft.item.EnumDyeColor) Nullable(javax.annotation.Nullable)

Example 4 with Recipe

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

the class AbstractRecipeLogic method trySearchNewRecipe.

protected void trySearchNewRecipe() {
    long maxVoltage = getMaxVoltage();
    Recipe currentRecipe = null;
    IItemHandlerModifiable importInventory = getInputInventory();
    IMultipleTankHandler importFluids = getInputTank();
    if (previousRecipe != null && previousRecipe.matches(false, importInventory, importFluids)) {
        // if previous recipe still matches inputs, try to use it
        currentRecipe = previousRecipe;
    } else {
        boolean dirty = checkRecipeInputsDirty(importInventory, importFluids);
        if (dirty || forceRecipeRecheck) {
            this.forceRecipeRecheck = false;
            // else, try searching new recipe for given inputs
            currentRecipe = findRecipe(maxVoltage, importInventory, importFluids);
            if (currentRecipe != null) {
                this.previousRecipe = currentRecipe;
            }
        }
    }
    if (currentRecipe != null && setupAndConsumeRecipeInputs(currentRecipe)) {
        setupRecipe(currentRecipe);
    }
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) Recipe(gregtech.api.recipes.Recipe) IMultipleTankHandler(gregtech.api.capability.IMultipleTankHandler)

Example 5 with Recipe

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

the class ImplosionRecipeBuilder method build.

public ValidationResult<Recipe> build() {
    // Adjust the explosive type and the explosive amount. This is done here because it was null otherwise, for some reason
    int amount = Math.max(1, explosivesAmount / 2);
    if (explosivesType == null) {
        this.explosivesType = new ItemStack(Blocks.TNT, amount);
    } else {
        this.explosivesType = new ItemStack(explosivesType.getItem(), amount, explosivesType.getMetadata());
    }
    inputs.add(CountableIngredient.from(explosivesType));
    Recipe recipe = new Recipe(inputs, outputs, chancedOutputs, fluidInputs, fluidOutputs, duration, EUt, hidden);
    if (!recipe.getRecipePropertyStorage().store(ImmutableMap.of(ImplosionExplosiveProperty.getInstance(), explosivesType))) {
        return ValidationResult.newResult(EnumValidationResult.INVALID, recipe);
    }
    return ValidationResult.newResult(finalizeAndValidate(), recipe);
}
Also used : Recipe(gregtech.api.recipes.Recipe) ItemStack(net.minecraft.item.ItemStack)

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