use of com.demod.factorio.Utils in project Factorio-FBSR by demodude4u.
the class RenderUtils method getModules.
public static Optional<Multiset<String>> getModules(BlueprintEntity entity, DataTable table) {
if (!entity.json().has("items")) {
return Optional.empty();
}
Multiset<String> modules = LinkedHashMultiset.create();
Object itemsJson = entity.json().get("items");
if (itemsJson instanceof JSONObject) {
Utils.forEach(entity.json().getJSONObject("items"), (String itemName, Integer count) -> {
modules.add(itemName, count);
});
} else if (itemsJson instanceof JSONArray) {
Utils.<JSONObject>forEach(entity.json().getJSONArray("items"), j -> {
modules.add(j.getString("item"), j.getInt("count"));
});
}
modules.entrySet().removeIf(e -> {
Optional<ItemPrototype> item = table.getItem(e.getElement());
return !item.isPresent() || !item.get().getType().equals("module");
});
return Optional.of(modules);
}
Aggregations