================================================================================
BUG REPORT 2: OCs Mods (OCs_base_assets, OCs_stone_casting, OCs_foundary_expansion, OCs_ammo_casting)
Author: OC1024
Target Mod Portal Pages:
- https://mods.factorio.com/mod/OCs_base_assets/discussion
- https://mods.factorio.com/mod/OCs_stone_casting/discussion
- https://mods.factorio.com/mod/OCs_foundary_expansion/discussion
- https://mods.factorio.com/mod/OCs_ammo_casting/discussion
================================================================================
Subject: Startup crash (independent_probability > 1) and compatibility bugs across OCs Base Assets / Stone Casting / Foundry Expansion / Ammo Casting
Hi OC1024! I ran into a startup crash and a few bugs across the OCs mod suite when playing with Space Age, Krastorio 2 Spaced Out, Maraxsis, Moshine, and Crushing Industry. Here are the details and fixes for each:
1. OCs_base_assets (0.6.5) — independent_probability > 1.0 Startup Crash
- File:
prototypes/utils/oc_recipe.lua (lines 16–51, oc_recipe.approximate_from_expected_value)
- Error:
Error while loading recipe prototype "oc-casting-maraxsis-glass-panes" (recipe): independent_probability must be in range [0, 1], but 1.003000 was given in property tree at ROOT.recipe.oc-casting-maraxsis-glass-panes.results[2]
- Cause:
approximate_from_expected_value(E, epsilon) computes local a_out = math.floor(E + 0.5) (rounding to nearest integer instead of ceiling) and also tests candidate_a = a_out - 1 without checking candidate_p <= 1. Whenever E is slightly above an integer (e.g., 1.003), a_out becomes 1 and p_out = E / a_out = 1.003, which exceeds Factorio's [0, 1] limit for independent_probability.
-
Fix:
Use math.ceil(E) for a_out, only test candidate_a >= math.ceil(E), and clamp p_out / candidate_p with math.min(1, ...):
```lua
function oc_recipe.approximate_from_expected_value(E, epsilon)
if E == nil or E <= 0 then return nil, nil end
local a_out = math.ceil(E)
if a_out <= 0 then return nil, nil end
local precision = 10 ^ 3
local p_out = math.min(1, math.floor((E / a_out) * precision + 0.5) / precision)
...
```
2. OCs_stone_casting (0.9.4) — Priority Collisions, Icon Key, and Recipe Name Typo
- Files:
prototypes/compatibility/maraxsis.lua (lines 74–76 & 101)
prototypes/compatibility/moshine.lua (lines 74–81)
prototypes/compatibility/crushing-industry.lua (lines 73–96)
- Issues & Fixes:
- Priority 40 collision on
"sand" and "glass":
OCs_base_assets already registers "sand" at priority 40 and "glass" at priority 40 in data.lua. When OCs_stone_casting calls generator_api.register_category_alt_recipes("metallurgy", ...) with [40] = "lava-to-sand" and [40] = "oc-casting-glass", register_alt_recipe_entry logs Priority 40 for 'sand' already occupied by 'sand'. Registration skipped. Using priority [60] (or overwrite_alt_recipe_entry) allows lava-to-sand and oc-casting-glass to be registered properly.
- Typo in
prototypes/compatibility/maraxsis.lua (line 101):
oc_tech.add_productivity_bonus(tech_name, "oc-casting-maraxsis-glass-planes", 0.1) has a typo ("planes" instead of "panes" -> "oc-casting-maraxsis-glass-panes").
- Invalid icon size key in
prototypes/compatibility/crushing-industry.lua (lines 88 & 92):
In recipe "molten-glass-from-lava", the icons table uses size = 64 instead of icon_size = 64.
3. OCs_foundary_expansion (0.6.8) — Undefined Global & Table instead of String in Recipe Dict
- Files:
prototypes/entity.lua (lines 202–209)
prototypes/recipe.lua (line 358)
- Issues & Fixes:
- Undefined global
crafting_categories in prototypes/entity.lua (lines 203 & 207):
lua
if data.raw["recipe-category"]["metallurgy-or-quality-assembling"] then
table.insert(crafting_categories, "metallurgy-or-quality-assembling")
crafting_categories is nil in global scope here (causes bad argument #1 to 'insert' (table expected, got nil) if any mod defines those categories). It should be:
table.insert(data.raw["assembling-machine"]["advanced-foundry"].crafting_categories, ...)
- Table instead of string in
prototypes/recipe.lua (line 358):
lua
if mods["OCs_stone_casting"] then
new_recipes_dict["burner-mining-drill"] = "metallurgy"
new_recipes_dict["electric-mining-drill"] = "metallurgy"
new_recipes_dict["electric-furnace"] = { "metallurgy" }
end
Because { "metallurgy" } is a table instead of "metallurgy", batch_generator rejects "electric-furnace" (elseif type(cat) ~= "string" then failed_recipes[r_name] = cat).
4. OCs_ammo_casting (0.11.8) — K2SO Item Name Prefix Typo
- File:
data-final-fixes.lua (line 7)
- Issue & Fix:
lua
if mods["Krastorio2-spaced-out"] then
oc_recipe.replace_ingredient("tungsten-rounds-magazine", "ammo", "piercing-rounds-magazine", "ammo",
"k2-armor-piercing-rifle-magazine", true)
end
The K2/K2SO item name prefix is "kr-", not "k2-" ("kr-armor-piercing-rifle-magazine"). With "k2-", oc_recipe.replace_ingredient fails to find the prototype in data.raw["ammo"] and skips the replacement.