Page 1 of 1

Remove unlock Item from MOd Tech

Posted: Tue Apr 19, 2022 9:39 am
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).

Re: Remove unlock Item from MOd Tech

Posted: Tue Apr 19, 2022 12:25 pm
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.)

Re: Remove unlock Item from MOd Tech

Posted: Fri Apr 22, 2022 7:09 am
by BOFan80
Thx after the Edit it works. You help me realy a lot

Re: Remove unlock Item from MOd Tech

Posted: Fri Apr 22, 2022 7:43 am
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