Search in sources :

Example 1 with TotalRawCalculator

use of com.demod.factorio.TotalRawCalculator in project Factorio-FBSR by demodude4u.

the class FBSR method generateTotalRawItems.

public static Map<String, Double> generateTotalRawItems(DataTable table, Map<String, RecipePrototype> recipes, Map<String, Double> totalItems) {
    Map<String, Double> ret = new LinkedHashMap<>();
    TotalRawCalculator calculator = new TotalRawCalculator(recipes);
    for (Entry<String, Double> entry : totalItems.entrySet()) {
        String recipeName = entry.getKey();
        double recipeAmount = entry.getValue();
        table.getRecipe(recipeName).ifPresent(r -> {
            double multiplier = recipeAmount / r.getOutputs().get(recipeName);
            Map<String, Double> totalRaw = calculator.compute(r);
            for (Entry<String, Double> entry2 : totalRaw.entrySet()) {
                String itemName = entry2.getKey();
                double itemAmount = entry2.getValue();
                addToItemAmount(ret, itemName, itemAmount * multiplier);
            }
        });
    }
    return ret;
}
Also used : TotalRawCalculator(com.demod.factorio.TotalRawCalculator) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

TotalRawCalculator (com.demod.factorio.TotalRawCalculator)1 LinkedHashMap (java.util.LinkedHashMap)1