Search in sources :

Example 1 with PressurizedReactionRecipe

use of mekanism.api.recipes.PressurizedReactionRecipe 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 2 with PressurizedReactionRecipe

use of mekanism.api.recipes.PressurizedReactionRecipe in project Mekanism by mekanism.

the class TileEntityPressurizedReactionChamber method onCachedRecipeChanged.

@Override
public void onCachedRecipeChanged(@Nullable CachedRecipe<PressurizedReactionRecipe> cachedRecipe, int cacheIndex) {
    int recipeDuration;
    if (cachedRecipe == null) {
        recipeDuration = BASE_DURATION;
        recipeEnergyRequired = FloatingLong.ZERO;
    } else {
        PressurizedReactionRecipe recipe = cachedRecipe.getRecipe();
        recipeDuration = recipe.getDuration();
        recipeEnergyRequired = recipe.getEnergyRequired();
    }
    boolean update = baseTicksRequired != recipeDuration;
    baseTicksRequired = recipeDuration;
    if (update) {
        recalculateUpgrades(Upgrade.SPEED);
    }
    // Ensure we take our recipe's energy per tick into account
    energyContainer.updateEnergyPerTick();
}
Also used : PressurizedReactionRecipe(mekanism.api.recipes.PressurizedReactionRecipe)

Aggregations

PressurizedReactionRecipe (mekanism.api.recipes.PressurizedReactionRecipe)2 GasStack (mekanism.api.chemical.gas.GasStack)1 IngredientHelper (mekanism.common.integration.projecte.IngredientHelper)1 NormalizedSimpleStack (moze_intel.projecte.api.nss.NormalizedSimpleStack)1 ItemStack (net.minecraft.item.ItemStack)1 FluidStack (net.minecraftforge.fluids.FluidStack)1