DRY411S / Recycling-Machines

A factorio mod that adds Recycling Machines to the game. These disassemble products back into their original ingredients.
GNU General Public License v3.0
10 stars 2 forks source link

Missing starter vanilla item recycles #69

Closed embermctillhawk closed 4 years ago

embermctillhawk commented 4 years ago

Yes, this is similar to previous issues. I have done the groundwork and diagnosed the specific cause, however.

If any mod calls reset_technology_effects() in its own control.lua for every force from an on_configuration_changed event then any vanilla starting crafts will no longer be recycleable. Modded starting crafts appear to survive without issue.

Reproduction steps:

Locally altering the other mod to check if the ZRecycling global exists and if it does then skipping its own reset_technology_effects() code does cause the issue to disappear, or simply starting a new save file for every configuration change is also a workaround, or using the console to re-enable the desired recipes until the next configuration change.

If it's still a wontfix then alright, but I figured you ought to hear about my discovery.

EDIT: I created a stub mod which has only the reset_technology_effects() code and it doesn't break anything. I guess I'll go bother Bob about it then.

DRY411S commented 4 years ago

Thanks for the report.

The mod does not call reset_technology_effects(). Once upon a time it did, I don't remember when I removed it. I note the latest code (v0.18.2) still makes reference to it, but it is not called. Instead, in control.lua on_init and on_configuration_changed() events, the mod enables the reverse recipe (the Recycling recipe) for every recipe that is itself enabled.

At https://lua-api.factorio.com/latest/LuaForce.html#LuaForce.reset_technologies reset_technology_effects() is documented as

Reapplies all possible research effects, including unlocked recipes. Any custom changes are lost. Preserves research state of technologies.

I don't see therefore why any starter vanilla items should not be recyclable. If the vanilla recipe is enabled, then my code on_init and on_configuration_changed handlers enables the reverse_recipe for every recipe that is enabled.

embermctillhawk commented 4 years ago

Update: The patch that I wrote into bobplates and tested a dozen times has now stopped working for no apparent reason. The only information that I can still give you is that it's specifically bobplates that this is happening with, and that my computer is cursed.

DRY411S commented 4 years ago

Hmm. See https://github.com/DRY411S/Recycling-Machines/issues/43

It was bob's plates use of reset _technology_effects that caused me to make significant changes to this mod, to add all recycling recipes to technologies, so that his call to reset_technology_effects() did not blat my recipes.

DRY411S commented 4 years ago

I can see that the recycling of vanilla recipes that are available at start of game is not possible when bobplates is present. I'm not ready to accept that this is a bug in my mod.

DRY411S commented 4 years ago

Confirmed as a bug in my mod.

embermctillhawk commented 4 years ago

I think I figured it out! According to Data.raw, all the starter recipes don't have an enabled entry.

Modded starter recipes usually specify enabled=true for their starter recipes, but it looks like the vanilla starter recipes just don't specify enabled=true or enabled=false, so in the code when it checks for v.enabled==true you get nil==true which is false, so it doesn't know to re-enable it.

Hmm. Or not. Or maybe my computer actually is just cursed.

DRY411S commented 4 years ago

I have diagnosed the cause and fixed it. It will be in the next release.

You're right about the starter recipes having enabled = nil.

The enablement of the starter recipes is achieved by the game 'soft researching' the "basic-foo" technologies (in the /data/base/prototypes/technology/demo-technology.lua). These technologies never appear in the research UI. The technology-effects attributed to the technologies unlocks the starter recipes. Because their enabled property is nil, this seems to cause the game to set them to true.

On the other hand, my mod was creating technology-effects for the recycling recipes for those 'basic-foo' starter recipes with enabled=false. My mod was enabling the recycling recipes using the on_configuration_changed event. Bob's plates on_configuration_changed event was being called by the game after my mod's code and calls reset_technology_effects() thus disabling the starter recycling recipes again.

This appears to be an issue with technology prototypes that were defined by the devs but are 'unresearchable'. Enabled = false is change to enabled = true for researchable technologies, but not these starter technologies. (In my view, this is a bug in the vanilla product).

Modifying my mod code to set enabled = nil for startup recycling recipes has cured the problem.

The reason I was doing it the way I was, is because the starter recycling recipes were appearing in the player's crafting menu BEFORE recycling machines had been researched! Now that recycling recipes no longer appear in player crafting menus, I can implement this fix.