1
0
mirror of https://github.com/demodude4u/Factorio-FBSR.git synced 2024-11-27 08:20:57 +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, public void createModuleIcons(Consumer<Renderer> register, WorldMap map, DataTable table, BlueprintEntity entity,
EntityPrototype prototype) { EntityPrototype prototype) {
Optional<Multiset<String>> modulesOpt = RenderUtils.getModules(entity); Optional<Multiset<String>> modulesOpt = RenderUtils.getModules(entity, table);
if (modulesOpt.isPresent()) { if (modulesOpt.isPresent()) {
Multiset<String> modules = modulesOpt.get(); Multiset<String> modules = modulesOpt.get();
@ -272,7 +272,7 @@ public class EntityRendererFactory {
Map<String, Double> beaconModules = new LinkedHashMap<>(); Map<String, Double> beaconModules = new LinkedHashMap<>();
for (BlueprintEntity beacon : beacons) { for (BlueprintEntity beacon : beacons) {
double distributionEffectivity = beacon.json().getDouble("distribution_effectivity"); 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()) { if (modulesOpt2.isPresent()) {
Multiset<String> modules = modulesOpt2.get(); Multiset<String> modules = modulesOpt2.get();
for (Multiset.Entry<String> entry : modules.entrySet()) { for (Multiset.Entry<String> entry : modules.entrySet()) {

View File

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

View File

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