Remove unlock Item from MOd Tech

Place to get help with not working mods / modding interface.
Post Reply
BOFan80
Inserter
Inserter
Posts: 23
Joined: Thu Apr 21, 2016 6:44 pm
Contact:

Remove unlock Item from MOd Tech

Post by BOFan80 »

Is there any solution to remove an unlock item from a mod tech, without changeing the other mod?
Example.

In my case, an other mod will unlock an item with a tech. i want to remove this item, beacause my mod unlock this item before. And the other mod shows it up twice (in his Mod Categorie).
please notice that my natove language is german, so my english is not so good. Thx

Pi-C
Smart Inserter
Smart Inserter
Posts: 1645
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Remove unlock Item from MOd Tech

Post by Pi-C »

BOFan80 wrote:
Tue Apr 19, 2022 9:39 am
Is there any solution to remove an unlock item from a mod tech, without changeing the other mod?
You should change the other mod's technology prototype in data-updates.lua. What you're interested in is the "effects" property, which can be defined in technology.effects, technology.normal.effects, and technology.expensive.effects. Just look for effects of type "unlock-recipe" and remove those that unlock your item:

Code: Select all

local function remove_recipe_unlock(tech_name, recipe_name)
  local tech = tech_name and data.raw.technology[tech_name]

  if tech then
    local function remove(effects, recipe_name)
      if effects then
	for e = #effects, 1, -1 do
	  if effects[e].type == "unlock-recipe" and effects[e].recipe == recipe_name then
	    table.remove(effects, e)
	  end
	end
      end
    end
    
    remove(tech.effects, recipe_name)
    remove(tech.normal and tech.normal.effects, recipe_name)
    remove(tech.expensive and tech.expensive.effects, recipe_name)
  end
end

remove_recipe_unlock("steel-processing", "steel-plate")
(EDIT: Added the "-1" I've forgotten in the starting line of the for loop.)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

BOFan80
Inserter
Inserter
Posts: 23
Joined: Thu Apr 21, 2016 6:44 pm
Contact:

Re: Remove unlock Item from MOd Tech

Post by BOFan80 »

Thx after the Edit it works. You help me realy a lot
please notice that my natove language is german, so my english is not so good. Thx

Pi-C
Smart Inserter
Smart Inserter
Posts: 1645
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Remove unlock Item from MOd Tech

Post by Pi-C »

BOFan80 wrote:
Fri Apr 22, 2022 7:09 am
Thx after the Edit it works. You help me realy a lot
You're welcome! By the way, in case you wondered why I was going over the loop backwards: the ingredients list is a sorted array with subsequent indexes (1, 2, 3 …), no gaps between them. If you remove the second entry, everything following will be shifted down, so old element 3 would be new element 2, old 4 new 3 etc. But the loop wouldn't notice that. If you're at i=2 and remove that, you'd skip the old element 3 and jump directly to the old element 4 on the next iteration. So going backwards makes sure that you don't miss anything.

However, I must have confused ingredients with something else. Just noticed this::
Duplicate ingredients, e.g. two entries for the "wood" item, are not allowed.
So you can simplify the loop:

Code: Select all

	for e, effect in pairs(effects) do
	  if effects.type == "unlock-recipe" and effects.recipe == recipe_name then
	    table.remove(effects, e)
	    break
	  end
	end
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Modding help”