Lead

by brevven

Adds lead ore and plates to the base game as an early game resource. Lead is used in ammunition, pipes, batteries and a few other places. Compatible with RSO, Krastorio 2, Space Exploration and other mods. A standalone piece of BZ Mods. With graphics by snouz.

Content
2 months ago
1.1 - 2.0
45.9K
Mining Manufacturing

b [Done] Recycling compatibility

8 months ago
(updated 8 months ago)

OK actually last one, I noticed that, when combined with Roc's Rusting Iron, I noticed that recycling recipes sometimes behaved oddly. And after scratching my head about it, I realized it's probably due to the third line from this snippet of the quality module's data-updates script:

for name, recipe in pairs(data.raw.recipe) do
  recycling.generate_recycling_recipe(recipe)
  recipe.auto_recycle = nil
end

So unfortunately it seems like you should only call recycling.generate_recycling_recipe() on recipes you know need an update, rather than iterating over all recipes. Frankly I'm not entirely sure why only some recycling recipes are affected by this, but hey.

This also affects some of my mods, e.g. Resin from Wooden Industry (I've noticed some issues with recycling recipes from my mods' end too, cleaning those up now).

8 months ago

Thanks for pointing that out. That third line is unfortunate. Looks like some folks are discussing this exact issue on the forum too

I think bookkeeping which recipes (from any other mod) should be recycled to this level will be very fragile and frequently break, so relying on metadata is the way to go.

Since the metadata is being deleted by the quality mod, Here's what I'm going to change in my mods for the moment:

-- Save recycling metadata that is later removed by quality mod. Call near end of data.lua
function util.prepare_recycling_helper()
  if mods.quality then
    for _, recipe in pairs(data.raw.recipe) do
      recipe.auto_recycle_helper = recipe.auto_recycle
    end
  end
end

-- Recalculate recycling recipes, call near end of data-updates.lua, after calling
-- util.prepare_recycling_helper from data.lua
function util.redo_recycling()
  if mods.quality then
    local recycling = require("__quality__.prototypes.recycling")
    for _, recipe in pairs(data.raw.recipe) do
      recipe.auto_recycle = recipe.auto_recycle_helper
      recycling.generate_recycling_recipe(recipe)
      recipe.auto_recycle = nil -- probably not necessary
    end
  end
end

Unfortunately, since quality clears the metadata in the data-update phase, it means that I can't fully handle this on my side if your mods depend on mine (or in the case of an "unlucky" mod load order when there are no explicit dependencies). For example, resin would still be broken in many cases. For your mods that depend on some of mine, you could either run a function similar util.prepare_recycling_helper() or just explictly set auto_recycle_helper alongside auto_recycle.

8 months ago
(updated 8 months ago)

Thanks for linking that thread, I added my two cents there. I do worry about the auto_recycle_helper approach, since e.g. the mod developer for AAI Industry is currently taking a hiatus, so I wouldn't expect them to account for any changes we make.

Maybe instead of running generate_recycle_recipe() on all recipes, we should modify our recipe-modifying utilities to set a metadata redo_recycle = true and only run generate_recycle_recipe() on recipes that have it set? Just an idea, haven't thought it through fully and my head is killing me so I'm gonna blow up some bugs with a tank.

8 months ago
(updated 8 months ago)

Yeah that's a great idea. I'll add a redo_recycling flag to .... a lot of my helper functions, and then have redo_recycling only perform it on those recipes.

edit to add: This still isn't a 100% guarantee, but it's a definite reduction in chance that we add a recycling recipe we weren't supposed to.

7 months ago
(updated 7 months ago)

This seems to be still not working as intended in my playtrough. It changes all more complicated recycling recipies like red or blue circuits or LDS to recycling into themselves. This is probably not intended, as it kills the Fulgora experience with no access to basic resources like lead, silicon and all the other cool stuff from bzmods. I could trace the issue to the lead mod (deactivating resolves the issue), but, maybe it is an issue with alternative (recycling) recipes.

I did some additional testing. I could not identify a incompability with other mods that modify the recipies. Problems is always resolved when I deactivate lead. In that case, recycling red circuts gives me back silicium and solder. So, the recycling for the silica and tin mods does work. Brevven, maybe that helps and you know what you do different there.

7 months ago

Thanks for the details, jpcwc. Definitely not intended, but unfortunately I can't reproduce on my side. Complicated enough that I may need a save file to examine if you are able to share one.

7 months ago
(updated 7 months ago)

I was afraid that it is a me-problem. I kind of tracked it down to the molten-tungsten mod. More-casting seems to be working. If you still need a save then tell me how I can send you a link. It looks a bit random and happens when a mod with alternative recipies gets loaded. simply lead and deadlock stacking results in blue chips that recycle to stacks of blue chips. so, it is probably the problem that the wrong recycling recipe gets picked combined with the race condition from the load order

7 months ago

Ok, I can reproduce the issue with Lead and Deadlock's Stacking Beltboxes.

I'll take a look.

7 months ago

Alright I was able to fix the issue with deadlock's and that should also fix many other similar issues.

7 months ago

I confirm that it is working. Brevven, big thanks for the quick fix. Fugoria will be mine now!

New response