Search in sources :

Example 1 with ChanceEntry

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

the class RecipeBuilder method chancedOutput.

public R chancedOutput(ItemStack stack, int chance, int tierChanceBoost) {
    if (stack == null || stack.isEmpty()) {
        return (R) this;
    }
    if (0 >= chance || chance > Recipe.getMaxChancedValue()) {
        GTLog.logger.error("Chance cannot be less or equal to 0 or more than {}. Actual: {}.", Recipe.getMaxChancedValue(), chance);
        GTLog.logger.error("Stacktrace:", new IllegalArgumentException());
        recipeStatus = EnumValidationResult.INVALID;
        return (R) this;
    }
    this.chancedOutputs.add(new ChanceEntry(stack.copy(), chance, tierChanceBoost));
    return (R) this;
}
Also used : ChanceEntry(gregtech.api.recipes.Recipe.ChanceEntry)

Example 2 with ChanceEntry

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

the class GTRecipeWrapper method getIngredients.

@Override
public void getIngredients(IIngredients ingredients) {
    if (!recipe.getInputs().isEmpty()) {
        List<CountableIngredient> recipeInputs = recipe.getInputs();
        List<List<ItemStack>> matchingInputs = new ArrayList<>(recipeInputs.size());
        for (CountableIngredient ingredient : recipeInputs) {
            List<ItemStack> ingredientValues = Arrays.stream(ingredient.getIngredient().getMatchingStacks()).map(ItemStack::copy).sorted(OreDictUnifier.getItemStackComparator()).collect(Collectors.toList());
            ingredientValues.forEach(stack -> {
                if (ingredient.getCount() == 0) {
                    notConsumedInput.add(stack);
                    stack.setCount(1);
                } else
                    stack.setCount(ingredient.getCount());
            });
            matchingInputs.add(ingredientValues);
        }
        ingredients.setInputLists(VanillaTypes.ITEM, matchingInputs);
    }
    if (!recipe.getFluidInputs().isEmpty()) {
        List<FluidStack> recipeInputs = recipe.getFluidInputs().stream().map(FluidStack::copy).collect(Collectors.toList());
        recipeInputs.forEach(stack -> {
            if (stack.amount == 0) {
                notConsumedFluidInput.add(stack);
                stack.amount = 1;
            }
        });
        ingredients.setInputs(VanillaTypes.FLUID, recipeInputs);
    }
    if (!recipe.getOutputs().isEmpty() || !recipe.getChancedOutputs().isEmpty()) {
        List<ItemStack> recipeOutputs = recipe.getOutputs().stream().map(ItemStack::copy).collect(Collectors.toList());
        List<ChanceEntry> chancedOutputs = recipe.getChancedOutputs();
        for (ChanceEntry chancedEntry : chancedOutputs) {
            ItemStack chancedStack = chancedEntry.getItemStack();
            chanceOutput.put(chancedStack, chancedEntry);
            recipeOutputs.add(chancedStack);
        }
        recipeOutputs.sort(Comparator.comparingInt(stack -> {
            ChanceEntry chanceEntry = chanceOutput.get(stack);
            if (chanceEntry == null)
                return 0;
            return chanceEntry.getChance();
        }));
        ingredients.setOutputs(VanillaTypes.ITEM, recipeOutputs);
    }
    if (!recipe.getFluidOutputs().isEmpty()) {
        List<FluidStack> recipeOutputs = recipe.getFluidOutputs().stream().map(FluidStack::copy).collect(Collectors.toList());
        ingredients.setOutputs(VanillaTypes.FLUID, recipeOutputs);
    }
}
Also used : Recipe(gregtech.api.recipes.Recipe) OreDictUnifier(gregtech.api.unification.OreDictUnifier) java.util(java.util) Hash(it.unimi.dsi.fastutil.Hash) IIngredients(mezz.jei.api.ingredients.IIngredients) Object2ObjectOpenCustomHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap) IRecipeWrapper(mezz.jei.api.recipe.IRecipeWrapper) Collectors(java.util.stream.Collectors) RecipeProperty(gregtech.api.recipes.recipeproperties.RecipeProperty) I18n(net.minecraft.client.resources.I18n) ItemStack(net.minecraft.item.ItemStack) ObjectOpenCustomHashSet(it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet) ItemStackHashStrategy(gregtech.api.util.ItemStackHashStrategy) JEIHelpers(gregtech.integration.jei.utils.JEIHelpers) Minecraft(net.minecraft.client.Minecraft) VanillaTypes(mezz.jei.api.ingredients.VanillaTypes) FluidStack(net.minecraftforge.fluids.FluidStack) ChanceEntry(gregtech.api.recipes.Recipe.ChanceEntry) RecipeMap(gregtech.api.recipes.RecipeMap) CountableIngredient(gregtech.api.recipes.CountableIngredient) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack) ChanceEntry(gregtech.api.recipes.Recipe.ChanceEntry) CountableIngredient(gregtech.api.recipes.CountableIngredient)

Example 3 with ChanceEntry

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

the class GTRecipeWrapper method addTooltip.

public void addTooltip(int slotIndex, boolean input, Object ingredient, List<String> tooltip) {
    boolean notConsumed = false;
    ChanceEntry entry = null;
    if (ingredient instanceof FluidStack) {
        FluidStack fluidStack = ((FluidStack) ingredient);
        if (notConsumedFluidInput.contains(fluidStack))
            notConsumed = true;
    } else if (ingredient instanceof ItemStack) {
        ItemStack itemStack = ((ItemStack) ingredient);
        if (notConsumedInput.contains(itemStack))
            notConsumed = true;
        else
            entry = chanceOutput.get(itemStack);
    } else {
        throw new IllegalArgumentException("Unknown ingredient type: " + ingredient.getClass());
    }
    if (entry != null && !input) {
        double chance = entry.getChance() / 100.0;
        double boost = entry.getBoostPerTier() / 100.0;
        tooltip.add(I18n.format("gregtech.recipe.chance", chance, boost));
    } else if (notConsumed && input) {
        tooltip.add(I18n.format("gregtech.recipe.not_consumed"));
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) ChanceEntry(gregtech.api.recipes.Recipe.ChanceEntry) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ChanceEntry (gregtech.api.recipes.Recipe.ChanceEntry)3 ItemStack (net.minecraft.item.ItemStack)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 CountableIngredient (gregtech.api.recipes.CountableIngredient)1 Recipe (gregtech.api.recipes.Recipe)1 RecipeMap (gregtech.api.recipes.RecipeMap)1 RecipeProperty (gregtech.api.recipes.recipeproperties.RecipeProperty)1 OreDictUnifier (gregtech.api.unification.OreDictUnifier)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 ObjectOpenCustomHashSet (it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 IIngredients (mezz.jei.api.ingredients.IIngredients)1 VanillaTypes (mezz.jei.api.ingredients.VanillaTypes)1 IRecipeWrapper (mezz.jei.api.recipe.IRecipeWrapper)1 Minecraft (net.minecraft.client.Minecraft)1 I18n (net.minecraft.client.resources.I18n)1