1
0
mirror of https://github.com/demodude4u/Factorio-FBSR.git synced 2024-11-24 08:12:21 +02:00

Ignoring invalid modules on entities.

This commit is contained in:
Weston Rye (Demod) 2018-05-14 12:27:41 -04:00
parent 03cd6fecad
commit ee6f9a1fe8
3 changed files with 15 additions and 22 deletions

View File

@ -212,7 +212,7 @@ public class EntityRendererFactory {
public void createModuleIcons(Consumer<Renderer> register, WorldMap map, DataTable table, BlueprintEntity entity,
EntityPrototype prototype) {
Optional<Multiset<String>> modulesOpt = RenderUtils.getModules(entity);
Optional<Multiset<String>> modulesOpt = RenderUtils.getModules(entity, table);
if (modulesOpt.isPresent()) {
Multiset<String> modules = modulesOpt.get();
@ -272,7 +272,7 @@ public class EntityRendererFactory {
Map<String, Double> beaconModules = new LinkedHashMap<>();
for (BlueprintEntity beacon : beacons) {
double distributionEffectivity = beacon.json().getDouble("distribution_effectivity");
Optional<Multiset<String>> modulesOpt2 = RenderUtils.getModules(beacon);
Optional<Multiset<String>> modulesOpt2 = RenderUtils.getModules(beacon, table);
if (modulesOpt2.isPresent()) {
Multiset<String> modules = modulesOpt2.get();
for (Multiset.Entry<String> entry : modules.entrySet()) {

View File

@ -35,9 +35,7 @@ import java.util.function.Consumer;
import javax.imageio.ImageIO;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.demod.factorio.DataTable;
import com.demod.factorio.FactorioData;
@ -539,23 +537,10 @@ public class FBSR {
addToItemAmount(ret, i.getName(), 1);
});
if (entity.json().has("items")) {
Object itemsJson = entity.json().get("items");
if (itemsJson instanceof JSONObject) {
Utils.forEach(entity.json().getJSONObject("items"), (String moduleName, Integer count) -> {
if (!table.getItem(moduleName).isPresent()) {
return;
}
addToItemAmount(ret, moduleName, count);
});
} else if (itemsJson instanceof JSONArray) {
Utils.<JSONObject>forEach(entity.json().getJSONArray("items"), j -> {
String moduleName = j.getString("item");
if (!table.getItem(moduleName).isPresent()) {
return;
}
addToItemAmount(ret, moduleName, j.getInt("count"));
});
Optional<Multiset<String>> modules = RenderUtils.getModules(entity, table);
if (modules.isPresent()) {
for (Multiset.Entry<String> entry : modules.get().entrySet()) {
addToItemAmount(ret, entry.getElement(), entry.getCount());
}
}
}

View File

@ -20,9 +20,11 @@ import org.json.JSONArray;
import org.json.JSONObject;
import org.luaj.vm2.LuaValue;
import com.demod.factorio.DataTable;
import com.demod.factorio.FactorioData;
import com.demod.factorio.Utils;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.factorio.prototype.ItemPrototype;
import com.demod.factorio.prototype.TilePrototype;
import com.demod.fbsr.Renderer.Layer;
import com.google.common.collect.ImmutableList;
@ -139,7 +141,7 @@ public final class RenderUtils {
return new Color(sumR / sumA, sumG / sumA, sumB / sumA);
}
public static Optional<Multiset<String>> getModules(BlueprintEntity entity) {
public static Optional<Multiset<String>> getModules(BlueprintEntity entity, DataTable table) {
if (!entity.json().has("items")) {
return Optional.empty();
}
@ -156,6 +158,12 @@ public final class RenderUtils {
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);
}