Search in sources :

Example 11 with GasStack

use of mekanism.api.chemical.gas.GasStack in project Mekanism by mekanism.

the class RotaryInputRecipeCache method findFirstRecipe.

/**
 * Finds the first recipe that matches the given gas input.
 *
 * @param world World.
 * @param input Recipe input.
 *
 * @return Recipe matching the given gas input, or {@code null} if no recipe matches.
 */
@Nullable
public RotaryRecipe findFirstRecipe(@Nullable World world, GasStack input) {
    if (gasInputCache.isEmpty(input)) {
        // Don't allow empty inputs
        return null;
    }
    initCacheIfNeeded(world);
    Predicate<RotaryRecipe> matchPredicate = recipe -> recipe.test(input);
    RotaryRecipe recipe = gasInputCache.findFirstRecipe(input, matchPredicate);
    return recipe == null ? findFirstRecipe(complexGasInputRecipes, matchPredicate) : recipe;
}
Also used : Gas(mekanism.api.chemical.gas.Gas) RotaryRecipe(mekanism.api.recipes.RotaryRecipe) MekanismRecipeType(mekanism.common.recipe.MekanismRecipeType) Predicate(java.util.function.Predicate) World(net.minecraft.world.World) Set(java.util.Set) ChemicalInputCache(mekanism.common.recipe.lookup.cache.type.ChemicalInputCache) FluidInputCache(mekanism.common.recipe.lookup.cache.type.FluidInputCache) HashSet(java.util.HashSet) List(java.util.List) GasStack(mekanism.api.chemical.gas.GasStack) FluidStack(net.minecraftforge.fluids.FluidStack) Nullable(javax.annotation.Nullable) RotaryRecipe(mekanism.api.recipes.RotaryRecipe) Nullable(javax.annotation.Nullable)

Example 12 with GasStack

use of mekanism.api.chemical.gas.GasStack in project Mekanism by mekanism.

the class ChemicalInfuserRecipeMapper method handleRecipe.

@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
    if (!(iRecipe instanceof ChemicalInfuserRecipe)) {
        // Double check that we have a type of recipe we know how to handle
        return false;
    }
    boolean handled = false;
    ChemicalInfuserRecipe recipe = (ChemicalInfuserRecipe) iRecipe;
    List<@NonNull GasStack> leftInputRepresentations = recipe.getLeftInput().getRepresentations();
    List<@NonNull GasStack> rightInputRepresentations = recipe.getRightInput().getRepresentations();
    for (GasStack leftRepresentation : leftInputRepresentations) {
        NormalizedSimpleStack nssLeft = NSSGas.createGas(leftRepresentation);
        for (GasStack rightRepresentation : rightInputRepresentations) {
            GasStack 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) ChemicalInfuserRecipe(mekanism.api.recipes.ChemicalInfuserRecipe) GasStack(mekanism.api.chemical.gas.GasStack) IngredientHelper(mekanism.common.integration.projecte.IngredientHelper)

Example 13 with GasStack

use of mekanism.api.chemical.gas.GasStack in project Mekanism by mekanism.

the class ElectrolysisRecipeMapper method handleRecipe.

@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
    if (!(iRecipe instanceof ElectrolysisRecipe)) {
        // Double check that we have a type of recipe we know how to handle
        return false;
    }
    boolean handled = false;
    ElectrolysisRecipe recipe = (ElectrolysisRecipe) iRecipe;
    FluidStackIngredient input = recipe.getInput();
    for (FluidStack representation : input.getRepresentations()) {
        Pair<@NonNull GasStack, @NonNull GasStack> output = recipe.getOutput(representation);
        GasStack leftOutput = output.getLeft();
        GasStack rightOutput = output.getRight();
        if (!leftOutput.isEmpty() && !rightOutput.isEmpty()) {
            NormalizedSimpleStack nssInput = NSSFluid.createFluid(representation);
            NormalizedSimpleStack nssLeftOutput = NSSGas.createGas(leftOutput);
            NormalizedSimpleStack nssRightOutput = NSSGas.createGas(rightOutput);
            // Add trying to calculate left output (using it as if we needed negative of right output)
            IngredientHelper ingredientHelper = new IngredientHelper(mapper);
            ingredientHelper.put(nssInput, representation.getAmount());
            ingredientHelper.put(nssRightOutput, -rightOutput.getAmount());
            if (ingredientHelper.addAsConversion(nssLeftOutput, leftOutput.getAmount())) {
                handled = true;
            }
            // Add trying to calculate right output (using it as if we needed negative of left output)
            ingredientHelper.resetHelper();
            ingredientHelper.put(nssInput, representation.getAmount());
            ingredientHelper.put(nssLeftOutput, -leftOutput.getAmount());
            if (ingredientHelper.addAsConversion(nssRightOutput, rightOutput.getAmount())) {
                handled = true;
            }
        }
    }
    return handled;
}
Also used : NormalizedSimpleStack(moze_intel.projecte.api.nss.NormalizedSimpleStack) FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) ElectrolysisRecipe(mekanism.api.recipes.ElectrolysisRecipe) FluidStack(net.minecraftforge.fluids.FluidStack) GasStack(mekanism.api.chemical.gas.GasStack) IngredientHelper(mekanism.common.integration.projecte.IngredientHelper)

Example 14 with GasStack

use of mekanism.api.chemical.gas.GasStack in project Mekanism by mekanism.

the class GasToGasRecipeMapper method handleRecipe.

@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
    if (!(iRecipe instanceof GasToGasRecipe)) {
        // Double check that we have a type of recipe we know how to handle
        return false;
    }
    boolean handled = false;
    GasToGasRecipe recipe = (GasToGasRecipe) iRecipe;
    for (GasStack representation : recipe.getInput().getRepresentations()) {
        GasStack 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 : GasStack(mekanism.api.chemical.gas.GasStack) IngredientHelper(mekanism.common.integration.projecte.IngredientHelper) GasToGasRecipe(mekanism.api.recipes.GasToGasRecipe)

Example 15 with GasStack

use of mekanism.api.chemical.gas.GasStack in project Mekanism by mekanism.

the class ItemStackGasToItemStackRecipeMapper method handleRecipe.

@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
    if (!(iRecipe instanceof ItemStackGasToItemStackRecipe)) {
        // Double check that we have a type of recipe we know how to handle
        return false;
    }
    boolean handled = false;
    ItemStackGasToItemStackRecipe recipe = (ItemStackGasToItemStackRecipe) iRecipe;
    List<@NonNull ItemStack> itemRepresentations = recipe.getItemInput().getRepresentations();
    List<@NonNull GasStack> gasRepresentations = recipe.getChemicalInput().getRepresentations();
    for (GasStack gasRepresentation : gasRepresentations) {
        NSSGas nssGas = NSSGas.createGas(gasRepresentation);
        long gasAmount = gasRepresentation.getAmount() * TileEntityAdvancedElectricMachine.BASE_TICKS_REQUIRED;
        for (ItemStack itemRepresentation : itemRepresentations) {
            ItemStack output = recipe.getOutput(itemRepresentation, gasRepresentation);
            if (!output.isEmpty()) {
                IngredientHelper ingredientHelper = new IngredientHelper(mapper);
                ingredientHelper.put(itemRepresentation);
                ingredientHelper.put(nssGas, gasAmount);
                if (ingredientHelper.addAsConversion(output)) {
                    handled = true;
                }
            }
        }
    }
    return handled;
}
Also used : ItemStackGasToItemStackRecipe(mekanism.api.recipes.ItemStackGasToItemStackRecipe) NSSGas(mekanism.common.integration.projecte.NSSGas) GasStack(mekanism.api.chemical.gas.GasStack) ItemStack(net.minecraft.item.ItemStack) IngredientHelper(mekanism.common.integration.projecte.IngredientHelper)

Aggregations

GasStack (mekanism.api.chemical.gas.GasStack)44 ItemStack (net.minecraft.item.ItemStack)17 JsonSyntaxException (com.google.gson.JsonSyntaxException)8 IngredientHelper (mekanism.common.integration.projecte.IngredientHelper)8 FluidStackIngredient (mekanism.api.recipes.inputs.FluidStackIngredient)7 FluidStack (net.minecraftforge.fluids.FluidStack)7 List (java.util.List)6 IGasHandler (mekanism.api.chemical.gas.IGasHandler)6 PigmentStack (mekanism.api.chemical.pigment.PigmentStack)6 FloatingLong (mekanism.api.math.FloatingLong)6 GasStackIngredient (mekanism.api.recipes.inputs.chemical.GasStackIngredient)6 NonNull (mekanism.api.annotations.NonNull)5 InfusionStack (mekanism.api.chemical.infuse.InfusionStack)5 SlurryStack (mekanism.api.chemical.slurry.SlurryStack)5 Nonnull (javax.annotation.Nonnull)4 JsonElement (com.google.gson.JsonElement)3 Collections (java.util.Collections)3 Nullable (javax.annotation.Nullable)3 ChemicalType (mekanism.api.chemical.ChemicalType)3 BoxedChemicalStack (mekanism.api.chemical.merged.BoxedChemicalStack)3