Skip to content

Commit

Permalink
fix: Check for some item misbehavior in Py's synthetic items.
Browse files Browse the repository at this point in the history
  • Loading branch information
DaleStan committed Jan 23, 2025
1 parent 12104da commit 03296cf
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Yafc.Parser/Data/FactorioDataDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,13 @@ private void CalculateItemWeights() {
if (item.weight != 0) {
continue;
}
if (item.stackSize == 0) {
continue; // Py's synthetic items sometimes have a stack size of 0.
}

Recipe? recipe = allObjects.OfType<Recipe>().FirstOrDefault(r => r.name == item.name);
// Hidden recipes appear to be ignored by Factorio; a pistol weighs 100g, not the 200kg that would be expected from its stack size.
if (recipe?.products.Length > 0 && !recipe.hidden) {
if (recipe?.products.Length > 0 && recipe.ingredients.Length > 0 && !recipe.hidden) {
float weight = 0;
foreach (Ingredient ingredient in recipe.ingredients) {
if (ingredient.goods is Item i) {
Expand Down Expand Up @@ -543,9 +547,11 @@ private void CalculateItemWeights() {
item.weight = rocketCapacity / (rocketCapacity / item.weight / item.stackSize) / item.stackSize;
}

foreach (Item product in dependencies[item]) {
if (product.weight == 0) {
queue.Enqueue(product);
if (dependencies.TryGetValue(item, out List<Item>? products)) {
foreach (Item product in dependencies[item]) {
if (product.weight == 0) {
queue.Enqueue(product);
}
}
}
}
Expand Down

0 comments on commit 03296cf

Please sign in to comment.