Search in sources :

Example 11 with IngredientHelper

use of mekanism.common.integration.projecte.IngredientHelper in project Mekanism by mekanism.

the class PressurizedReactionRecipeMapper method handleRecipe.

@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
    if (!(iRecipe instanceof PressurizedReactionRecipe)) {
        // Double check that we have a type of recipe we know how to handle
        return false;
    }
    boolean handled = false;
    PressurizedReactionRecipe recipe = (PressurizedReactionRecipe) iRecipe;
    List<@NonNull ItemStack> itemRepresentations = recipe.getInputSolid().getRepresentations();
    List<@NonNull FluidStack> fluidRepresentations = recipe.getInputFluid().getRepresentations();
    List<@NonNull GasStack> gasRepresentations = recipe.getInputGas().getRepresentations();
    for (ItemStack itemRepresentation : itemRepresentations) {
        NormalizedSimpleStack nssItem = NSSItem.createItem(itemRepresentation);
        for (FluidStack fluidRepresentation : fluidRepresentations) {
            NormalizedSimpleStack nssFluid = NSSFluid.createFluid(fluidRepresentation);
            for (GasStack gasRepresentation : gasRepresentations) {
                NormalizedSimpleStack nssGas = NSSGas.createGas(gasRepresentation);
                Pair<@NonNull ItemStack, @NonNull GasStack> output = recipe.getOutput(itemRepresentation, fluidRepresentation, gasRepresentation);
                ItemStack itemOutput = output.getLeft();
                GasStack gasOutput = output.getRight();
                IngredientHelper ingredientHelper = new IngredientHelper(mapper);
                ingredientHelper.put(nssItem, itemRepresentation.getCount());
                ingredientHelper.put(nssFluid, fluidRepresentation.getAmount());
                ingredientHelper.put(nssGas, gasRepresentation.getAmount());
                if (itemOutput.isEmpty()) {
                    // We only have a gas output
                    if (!gasOutput.isEmpty() && ingredientHelper.addAsConversion(gasOutput)) {
                        handled = true;
                    }
                } else if (gasOutput.isEmpty()) {
                    // We only have an item output
                    if (ingredientHelper.addAsConversion(itemOutput)) {
                        handled = true;
                    }
                } else {
                    NormalizedSimpleStack nssItemOutput = NSSItem.createItem(itemOutput);
                    NormalizedSimpleStack nssGasOutput = NSSGas.createGas(gasOutput);
                    // We have both so do our best guess
                    // Add trying to calculate the item output (using it as if we needed negative of gas output)
                    ingredientHelper.put(nssGasOutput, -gasOutput.getAmount());
                    if (ingredientHelper.addAsConversion(nssItemOutput, itemOutput.getCount())) {
                        handled = true;
                    }
                    // Add trying to calculate gas output (using it as if we needed negative of item output)
                    ingredientHelper.resetHelper();
                    ingredientHelper.put(nssItem, itemRepresentation.getCount());
                    ingredientHelper.put(nssFluid, fluidRepresentation.getAmount());
                    ingredientHelper.put(nssGas, gasRepresentation.getAmount());
                    ingredientHelper.put(nssItemOutput, -itemOutput.getCount());
                    if (ingredientHelper.addAsConversion(nssGasOutput, gasOutput.getAmount())) {
                        handled = true;
                    }
                }
            }
        }
    }
    return handled;
}
Also used : PressurizedReactionRecipe(mekanism.api.recipes.PressurizedReactionRecipe) NormalizedSimpleStack(moze_intel.projecte.api.nss.NormalizedSimpleStack) FluidStack(net.minecraftforge.fluids.FluidStack) GasStack(mekanism.api.chemical.gas.GasStack) ItemStack(net.minecraft.item.ItemStack) IngredientHelper(mekanism.common.integration.projecte.IngredientHelper)

Example 12 with IngredientHelper

use of mekanism.common.integration.projecte.IngredientHelper in project Mekanism by mekanism.

the class RotaryRecipeMapper method handleRecipe.

@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
    if (!(iRecipe instanceof RotaryRecipe)) {
        // Double check that we have a type of recipe we know how to handle
        return false;
    }
    RotaryRecipe recipe = (RotaryRecipe) iRecipe;
    boolean handled = false;
    if (recipe.hasFluidToGas()) {
        for (FluidStack representation : recipe.getFluidInput().getRepresentations()) {
            GasStack output = recipe.getGasOutput(representation);
            if (!output.isEmpty()) {
                IngredientHelper ingredientHelper = new IngredientHelper(mapper);
                ingredientHelper.put(representation);
                if (ingredientHelper.addAsConversion(output)) {
                    handled = true;
                }
            }
        }
    }
    if (recipe.hasGasToFluid()) {
        for (GasStack representation : recipe.getGasInput().getRepresentations()) {
            FluidStack output = recipe.getFluidOutput(representation);
            if (!output.isEmpty()) {
                IngredientHelper ingredientHelper = new IngredientHelper(mapper);
                ingredientHelper.put(representation);
                if (ingredientHelper.addAsConversion(output)) {
                    handled = true;
                }
            }
        }
    }
    return handled;
}
Also used : RotaryRecipe(mekanism.api.recipes.RotaryRecipe) FluidStack(net.minecraftforge.fluids.FluidStack) GasStack(mekanism.api.chemical.gas.GasStack) IngredientHelper(mekanism.common.integration.projecte.IngredientHelper)

Example 13 with IngredientHelper

use of mekanism.common.integration.projecte.IngredientHelper in project Mekanism by mekanism.

the class ChemicalCrystallizerRecipeMapper method handleRecipe.

@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
    if (!(iRecipe instanceof ChemicalCrystallizerRecipe)) {
        // Double check that we have a type of recipe we know how to handle
        return false;
    }
    boolean handled = false;
    ChemicalCrystallizerRecipe recipe = (ChemicalCrystallizerRecipe) iRecipe;
    for (ChemicalStack<?> representation : recipe.getInput().getRepresentations()) {
        ItemStack output = recipe.getOutput(BoxedChemicalStack.box(representation));
        if (!output.isEmpty()) {
            IngredientHelper ingredientHelper = new IngredientHelper(mapper);
            ingredientHelper.put(representation);
            if (ingredientHelper.addAsConversion(output)) {
                handled = true;
            }
        }
    }
    return handled;
}
Also used : ItemStack(net.minecraft.item.ItemStack) IngredientHelper(mekanism.common.integration.projecte.IngredientHelper) ChemicalCrystallizerRecipe(mekanism.api.recipes.ChemicalCrystallizerRecipe)

Example 14 with IngredientHelper

use of mekanism.common.integration.projecte.IngredientHelper in project Mekanism by mekanism.

the class ItemStackToPigmentRecipeMapper method handleRecipe.

@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
    if (!(iRecipe instanceof ItemStackToPigmentRecipe)) {
        // Double check that we have a type of recipe we know how to handle
        return false;
    }
    boolean handled = false;
    ItemStackToPigmentRecipe recipe = (ItemStackToPigmentRecipe) iRecipe;
    for (ItemStack representation : recipe.getInput().getRepresentations()) {
        PigmentStack output = recipe.getOutput(representation);
        if (!output.isEmpty()) {
            IngredientHelper ingredientHelper = new IngredientHelper(mapper);
            ingredientHelper.put(representation);
            if (ingredientHelper.addAsConversion(output)) {
                handled = true;
            }
        }
    }
    return handled;
}
Also used : ItemStackToPigmentRecipe(mekanism.api.recipes.ItemStackToPigmentRecipe) PigmentStack(mekanism.api.chemical.pigment.PigmentStack) ItemStack(net.minecraft.item.ItemStack) IngredientHelper(mekanism.common.integration.projecte.IngredientHelper)

Example 15 with IngredientHelper

use of mekanism.common.integration.projecte.IngredientHelper in project Mekanism by mekanism.

the class SawmillRecipeMapper method handleRecipe.

@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
    if (!(iRecipe instanceof SawmillRecipe)) {
        // Double check that we have a type of recipe we know how to handle
        return false;
    }
    SawmillRecipe recipe = (SawmillRecipe) iRecipe;
    ItemStackIngredient input = recipe.getInput();
    int primaryMultiplier = 1;
    int secondaryMultiplier = 1;
    if (recipe.getSecondaryChance() > 0 && recipe.getSecondaryChance() < 1) {
        Fraction multiplier;
        try {
            multiplier = Fraction.getFraction(recipe.getSecondaryChance()).invert();
        } catch (ArithmeticException e) {
            // If we couldn't turn it into a fraction, then note we failed to convert the recipe
            return false;
        }
        primaryMultiplier = multiplier.getNumerator();
        secondaryMultiplier = multiplier.getDenominator();
    }
    boolean handled = false;
    for (ItemStack representation : input.getRepresentations()) {
        ChanceOutput output = recipe.getOutput(representation);
        ItemStack mainOutput = output.getMainOutput();
        ItemStack secondaryOutput = output.getMaxSecondaryOutput();
        NormalizedSimpleStack nssInput = NSSItem.createItem(representation);
        IngredientHelper ingredientHelper = new IngredientHelper(mapper);
        if (secondaryOutput.isEmpty()) {
            // We only have a main output
            if (!mainOutput.isEmpty()) {
                ingredientHelper.put(nssInput, representation.getCount());
                if (ingredientHelper.addAsConversion(mainOutput)) {
                    handled = true;
                }
            }
        } else if (mainOutput.isEmpty()) {
            // We only have a secondary output
            ingredientHelper.put(nssInput, representation.getCount() * primaryMultiplier);
            if (ingredientHelper.addAsConversion(NSSItem.createItem(secondaryOutput), secondaryOutput.getCount() * secondaryMultiplier)) {
                handled = true;
            }
        } else {
            NormalizedSimpleStack nssMainOutput = NSSItem.createItem(mainOutput);
            NormalizedSimpleStack nssSecondaryOutput = NSSItem.createItem(secondaryOutput);
            // We have both so do our best guess by trying to subtract them from each other
            // Add trying to calculate the main output (using it as if we needed negative of secondary output)
            ingredientHelper.put(nssInput, representation.getCount() * primaryMultiplier);
            ingredientHelper.put(nssSecondaryOutput, -secondaryOutput.getCount() * secondaryMultiplier);
            if (ingredientHelper.addAsConversion(nssMainOutput, mainOutput.getCount() * primaryMultiplier)) {
                handled = true;
            }
            // Add trying to calculate secondary output (using it as if we needed negative of main output)
            ingredientHelper.resetHelper();
            ingredientHelper.put(nssInput, representation.getCount() * primaryMultiplier);
            ingredientHelper.put(nssMainOutput, -mainOutput.getCount() * primaryMultiplier);
            if (ingredientHelper.addAsConversion(nssSecondaryOutput, secondaryOutput.getCount() * secondaryMultiplier)) {
                handled = true;
            }
        }
    }
    return handled;
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) NormalizedSimpleStack(moze_intel.projecte.api.nss.NormalizedSimpleStack) ChanceOutput(mekanism.api.recipes.SawmillRecipe.ChanceOutput) SawmillRecipe(mekanism.api.recipes.SawmillRecipe) Fraction(org.apache.commons.lang3.math.Fraction) ItemStack(net.minecraft.item.ItemStack) IngredientHelper(mekanism.common.integration.projecte.IngredientHelper)

Aggregations

IngredientHelper (mekanism.common.integration.projecte.IngredientHelper)19 ItemStack (net.minecraft.item.ItemStack)12 NormalizedSimpleStack (moze_intel.projecte.api.nss.NormalizedSimpleStack)9 GasStack (mekanism.api.chemical.gas.GasStack)8 FluidStack (net.minecraftforge.fluids.FluidStack)5 PigmentStack (mekanism.api.chemical.pigment.PigmentStack)3 InfusionStack (mekanism.api.chemical.infuse.InfusionStack)2 NSSGas (mekanism.common.integration.projecte.NSSGas)2 BoxedChemicalStack (mekanism.api.chemical.merged.BoxedChemicalStack)1 SlurryStack (mekanism.api.chemical.slurry.SlurryStack)1 ChemicalCrystallizerRecipe (mekanism.api.recipes.ChemicalCrystallizerRecipe)1 ChemicalDissolutionRecipe (mekanism.api.recipes.ChemicalDissolutionRecipe)1 ChemicalInfuserRecipe (mekanism.api.recipes.ChemicalInfuserRecipe)1 CombinerRecipe (mekanism.api.recipes.CombinerRecipe)1 ElectrolysisRecipe (mekanism.api.recipes.ElectrolysisRecipe)1 FluidSlurryToSlurryRecipe (mekanism.api.recipes.FluidSlurryToSlurryRecipe)1 FluidToFluidRecipe (mekanism.api.recipes.FluidToFluidRecipe)1 GasToGasRecipe (mekanism.api.recipes.GasToGasRecipe)1 ItemStackGasToItemStackRecipe (mekanism.api.recipes.ItemStackGasToItemStackRecipe)1 ItemStackToGasRecipe (mekanism.api.recipes.ItemStackToGasRecipe)1