Search in sources :

Example 6 with NormalizedSimpleStack

use of moze_intel.projecte.api.nss.NormalizedSimpleStack in project Mekanism by mekanism.

the class PaintingMachineRecipeMapper method handleRecipe.

@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
    if (!(iRecipe instanceof PaintingRecipe)) {
        // Double check that we have a type of recipe we know how to handle
        return false;
    }
    boolean handled = false;
    PaintingRecipe recipe = (PaintingRecipe) iRecipe;
    List<@NonNull PigmentStack> pigmentRepresentations = recipe.getChemicalInput().getRepresentations();
    List<@NonNull ItemStack> itemRepresentations = recipe.getItemInput().getRepresentations();
    for (PigmentStack pigmentRepresentation : pigmentRepresentations) {
        NormalizedSimpleStack nssPigment = NSSPigment.createPigment(pigmentRepresentation);
        for (ItemStack itemRepresentation : itemRepresentations) {
            ItemStack output = recipe.getOutput(itemRepresentation, pigmentRepresentation);
            if (!output.isEmpty()) {
                IngredientHelper ingredientHelper = new IngredientHelper(mapper);
                ingredientHelper.put(nssPigment, pigmentRepresentation.getAmount());
                ingredientHelper.put(itemRepresentation);
                if (ingredientHelper.addAsConversion(output)) {
                    handled = true;
                }
            }
        }
    }
    return handled;
}
Also used : NormalizedSimpleStack(moze_intel.projecte.api.nss.NormalizedSimpleStack) PigmentStack(mekanism.api.chemical.pigment.PigmentStack) ItemStack(net.minecraft.item.ItemStack) IngredientHelper(mekanism.common.integration.projecte.IngredientHelper) PaintingRecipe(mekanism.api.recipes.PaintingRecipe)

Example 7 with NormalizedSimpleStack

use of moze_intel.projecte.api.nss.NormalizedSimpleStack in project Mekanism by mekanism.

the class PigmentMixerRecipeMapper method handleRecipe.

@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
    if (!(iRecipe instanceof PigmentMixingRecipe)) {
        // Double check that we have a type of recipe we know how to handle
        return false;
    }
    boolean handled = false;
    PigmentMixingRecipe recipe = (PigmentMixingRecipe) iRecipe;
    List<@NonNull PigmentStack> leftInputRepresentations = recipe.getLeftInput().getRepresentations();
    List<@NonNull PigmentStack> rightInputRepresentations = recipe.getRightInput().getRepresentations();
    for (PigmentStack leftRepresentation : leftInputRepresentations) {
        NormalizedSimpleStack nssLeft = NSSPigment.createPigment(leftRepresentation);
        for (PigmentStack rightRepresentation : rightInputRepresentations) {
            PigmentStack output = recipe.getOutput(leftRepresentation, rightRepresentation);
            if (!output.isEmpty()) {
                IngredientHelper ingredientHelper = new IngredientHelper(mapper);
                ingredientHelper.put(nssLeft, leftRepresentation.getAmount());
                ingredientHelper.put(rightRepresentation);
                if (ingredientHelper.addAsConversion(output)) {
                    handled = true;
                }
            }
        }
    }
    return handled;
}
Also used : NormalizedSimpleStack(moze_intel.projecte.api.nss.NormalizedSimpleStack) PigmentStack(mekanism.api.chemical.pigment.PigmentStack) IngredientHelper(mekanism.common.integration.projecte.IngredientHelper) PigmentMixingRecipe(mekanism.api.recipes.PigmentMixingRecipe)

Example 8 with NormalizedSimpleStack

use of moze_intel.projecte.api.nss.NormalizedSimpleStack 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 9 with NormalizedSimpleStack

use of moze_intel.projecte.api.nss.NormalizedSimpleStack 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)9 NormalizedSimpleStack (moze_intel.projecte.api.nss.NormalizedSimpleStack)9 ItemStack (net.minecraft.item.ItemStack)5 GasStack (mekanism.api.chemical.gas.GasStack)3 FluidStack (net.minecraftforge.fluids.FluidStack)3 PigmentStack (mekanism.api.chemical.pigment.PigmentStack)2 InfusionStack (mekanism.api.chemical.infuse.InfusionStack)1 SlurryStack (mekanism.api.chemical.slurry.SlurryStack)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 MetallurgicInfuserRecipe (mekanism.api.recipes.MetallurgicInfuserRecipe)1 PaintingRecipe (mekanism.api.recipes.PaintingRecipe)1 PigmentMixingRecipe (mekanism.api.recipes.PigmentMixingRecipe)1 PressurizedReactionRecipe (mekanism.api.recipes.PressurizedReactionRecipe)1 SawmillRecipe (mekanism.api.recipes.SawmillRecipe)1 ChanceOutput (mekanism.api.recipes.SawmillRecipe.ChanceOutput)1 FluidStackIngredient (mekanism.api.recipes.inputs.FluidStackIngredient)1 ItemStackIngredient (mekanism.api.recipes.inputs.ItemStackIngredient)1