[Solved]Hide a recipe/item from inside technology

Place to get help with not working mods / modding interface.
User avatar
dtoxic
Long Handed Inserter
Long Handed Inserter
Posts: 82
Joined: Fri Apr 01, 2016 8:40 pm
Contact:

[Solved]Hide a recipe/item from inside technology

Post by dtoxic »

So i wanted to change the steam engine from unlocking in one technology and unlock in another witch i managed to do like this

Code: Select all

table.insert(data.raw["technology"]["steam-power"].effects,{type = "unlock-recipe",recipe = "steam-engine"})
But now i have two recipes inside the "steam-power" and from another mod technology "electric-machinery" i would like to hide the recipe for the steam engine from "electric-machinery" technology

is there a Wizard who could point me on an adventure of coding land,and what is to be done so i can complete this quest?
Last edited by dtoxic on Wed Oct 18, 2023 1:51 pm, edited 1 time in total.
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Hide a recipe/item from inside technology

Post by FuryoftheStars »

It's gonna be hours before I can open up my own mod code to refresh my memory on this, but if you take a look at the code in my Classic Factorio Basic Oil Processing mod, I move a bunch of recipes around in the techs, so there are examples of inserting and removing in there. The code shouldn't be overly complex, either, as it's just moving recipes and changing a few recipes based on settings. Nothing truly new or complex.
Last edited by FuryoftheStars on Wed Oct 18, 2023 11:14 am, edited 1 time in total.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
User avatar
dtoxic
Long Handed Inserter
Long Handed Inserter
Posts: 82
Joined: Fri Apr 01, 2016 8:40 pm
Contact:

Re: Hide a recipe/item from inside technology

Post by dtoxic »

Will check that out now,thank you kindly
User avatar
dtoxic
Long Handed Inserter
Long Handed Inserter
Posts: 82
Joined: Fri Apr 01, 2016 8:40 pm
Contact:

Re: Hide a recipe/item from inside technology

Post by dtoxic »

Nope,cant make a sense of the code,all i see changing the prerequisite for technologies and adding/removing? ingredients...but thank you anyway,will wait for some other explanation
Pi-C
Smart Inserter
Smart Inserter
Posts: 1730
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Hide a recipe/item from inside technology

Post by Pi-C »

dtoxic wrote: Wed Oct 18, 2023 9:25 am So i wanted to change the steam engine from unlocking in one technology and unlock in another witch i managed to do like this

Code: Select all

table.insert(data.raw["technology"]["steam-power"].effects,{type = "unlock-recipe",recipe = "steam-engine"})
But now i have two recipes inside the "steam-power" and from another mod technology "electric-machinery" i would like to hide the recipe for the steam engine from "electric-machinery" technology

Code: Select all

local tech = data.raw.technology["electric-machinery"]
if tech and tech.effects then
	local new_effects = {}
	for e, effect in pairs(tech.effects) do
		if not (effect.type == "unlock-recipe" and effect.recipe == "steam-engine") then
			table.insert(new_effects, effect)
		end
	end
	tech.effects = next(new_effects) and table.deepcopy(new_effects) or nil
end
Technology effects are optional, so this will only run if the technology exists and has effects. Even if technology.effects does exist, you don't know what other mods may have changed before yours, so there is a chance that tech.effects contains the same unlock recipe more than once. Therefore, we go over all effects and copy every effect that is not an unlock-recipe for the steam-engine to the table new_effects. When that is done, we use next(new_effects) to check whether the table contains any elements. If it does, we overwrite tech.effects with new_effects; if it's empty, we remove tech.effects by setting it to nil.

Does that help, or did I miss something?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
User avatar
dtoxic
Long Handed Inserter
Long Handed Inserter
Posts: 82
Joined: Fri Apr 01, 2016 8:40 pm
Contact:

Re: Hide a recipe/item from inside technology

Post by dtoxic »

Just one question will this now also remove the "steam-engine" from technology "steam-power" witch i added with my code?
Pi-C
Smart Inserter
Smart Inserter
Posts: 1730
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Hide a recipe/item from inside technology

Post by Pi-C »

No. As tech has been defined as

Code: Select all

local tech = data.raw.technology["electric-machinery"]
the "steam-engine" recipe will be removed only from the effects of "electric-machinery".
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
User avatar
dtoxic
Long Handed Inserter
Long Handed Inserter
Posts: 82
Joined: Fri Apr 01, 2016 8:40 pm
Contact:

Re: Hide a recipe/item from inside technology

Post by dtoxic »

ahh great...every day one learns more,thank you
Pi-C
Smart Inserter
Smart Inserter
Posts: 1730
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: [Solved]Hide a recipe/item from inside technology

Post by Pi-C »

You're welcome, glad I could help! :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
User avatar
dtoxic
Long Handed Inserter
Long Handed Inserter
Posts: 82
Joined: Fri Apr 01, 2016 8:40 pm
Contact:

Re: [Solved]Hide a recipe/item from inside technology

Post by dtoxic »

btw,i put it data-final-fixes to make it work because in data-updates it would not stick...
Pi-C
Smart Inserter
Smart Inserter
Posts: 1730
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: [Solved]Hide a recipe/item from inside technology

Post by Pi-C »

Looks like some other mod changed it after your mod was done in data-updates.lua. Hover over the "electric-machinery" tech in the tech tree, and you'll see the mods that have modified the tech. If you'd find the mod that adds the unlock, you could add a dependency on it to force it to load before your mod. This way, you could keep your changes in data-updates.lua.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
User avatar
dtoxic
Long Handed Inserter
Long Handed Inserter
Posts: 82
Joined: Fri Apr 01, 2016 8:40 pm
Contact:

Re: [Solved]Hide a recipe/item from inside technology

Post by dtoxic »

Thx will check it out
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Hide a recipe/item from inside technology

Post by FuryoftheStars »

dtoxic wrote: Wed Oct 18, 2023 11:38 am Nope,cant make a sense of the code,all i see changing the prerequisite for technologies and adding/removing? ingredients...but thank you anyway,will wait for some other explanation
Ah, sorry about that. I could've sworn I did some recipe moving in there too, but maybe not. It has been a while since I've needed to look at that mod's code.

Glad Pi-C was able to help you out and you got your problem solved, though.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
User avatar
dtoxic
Long Handed Inserter
Long Handed Inserter
Posts: 82
Joined: Fri Apr 01, 2016 8:40 pm
Contact:

Re: [Solved]Hide a recipe/item from inside technology

Post by dtoxic »

No problem,also my coding skills are not that good but thanks for trying :)
Post Reply

Return to “Modding help”