Search in sources :

Example 11 with Recipe

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

the class ToolUtility method applyHammerDrops.

public static void applyHammerDrops(Random random, IBlockState blockState, List<ItemStack> drops, int fortuneLevel, EntityPlayer player) {
    ItemStack itemStack = new ItemStack(blockState.getBlock(), 1, blockState.getBlock().getMetaFromState(blockState));
    Recipe recipe = RecipeMaps.FORGE_HAMMER_RECIPES.findRecipe(Long.MAX_VALUE, Collections.singletonList(itemStack), Collections.emptyList(), 0);
    if (recipe != null && !recipe.getOutputs().isEmpty()) {
        drops.clear();
        for (ItemStack outputStack : recipe.getResultItemOutputs(Integer.MAX_VALUE, random, 0)) {
            outputStack = outputStack.copy();
            if (!(player instanceof FakePlayer) && OreDictUnifier.getPrefix(outputStack) == OrePrefix.crushed) {
                int growAmount = Math.round(outputStack.getCount() * random.nextFloat());
                if (fortuneLevel > 0) {
                    int i = Math.max(0, random.nextInt(fortuneLevel + 2) - 1);
                    growAmount += outputStack.getCount() * i;
                }
                outputStack.grow(growAmount);
            }
            drops.add(outputStack);
        }
    }
}
Also used : Recipe(gregtech.api.recipes.Recipe) ItemStack(net.minecraft.item.ItemStack) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 12 with Recipe

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

the class WorkableTieredMetaTileEntity method canInputFluid.

protected boolean canInputFluid(FluidStack inputFluid) {
    RecipeMap<?> recipeMap = workable.recipeMap;
    if (recipeMap.canInputFluidForce(inputFluid.getFluid()))
        // if recipe map forces input of given fluid, return true
        return true;
    Set<Recipe> matchingRecipes = null;
    for (IFluidTank fluidTank : importFluids) {
        FluidStack fluidInTank = fluidTank.getFluid();
        if (fluidInTank != null) {
            if (matchingRecipes == null) {
                // if we didn't have a list of recipes with any fluids, obtain it from first tank with fluid
                matchingRecipes = new HashSet<>(recipeMap.getRecipesForFluid(fluidInTank));
            } else {
                // else, remove recipes that don't contain fluid in this tank from list
                matchingRecipes.removeIf(recipe -> !recipe.hasInputFluid(fluidInTank));
            }
        }
    }
    if (matchingRecipes == null) {
        // if all tanks are empty, generally fluid can be inserted if there are recipes for it
        return !recipeMap.getRecipesForFluid(inputFluid).isEmpty();
    } else {
        // otherwise, we can insert fluid only if one of recipes accept it as input
        return matchingRecipes.stream().anyMatch(recipe -> recipe.hasInputFluid(inputFluid));
    }
}
Also used : Recipe(gregtech.api.recipes.Recipe) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 13 with Recipe

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

the class MetaTileEntityMacerator method createWorkable.

@Override
protected RecipeLogicEnergy createWorkable(RecipeMap<?> recipeMap) {
    final RecipeLogicEnergy result = new RecipeLogicEnergy(this, recipeMap, () -> energyContainer) {

        @Override
        protected int getMachineTierForRecipe(Recipe recipe) {
            int tier = GTUtility.getTierByVoltage(getMaxVoltage());
            if (tier > GTValues.MV) {
                return tier - GTValues.MV;
            }
            return 0;
        }
    };
    result.enableOverclockVoltage();
    return result;
}
Also used : Recipe(gregtech.api.recipes.Recipe) RecipeLogicEnergy(gregtech.api.capability.impl.RecipeLogicEnergy)

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