How Do I Delete a Recipe or Item From Vanilla?

Place to get help with not working mods / modding interface.
Post Reply
TheLastRonin
Inserter
Inserter
Posts: 23
Joined: Thu Jan 22, 2015 8:22 pm
Contact:

How Do I Delete a Recipe or Item From Vanilla?

Post by TheLastRonin »

If I wanted to completely remove the stone furnace from the game through a mod how would I go about doing that? Is it possible?

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: How Do I Delete a Recipe or Item From Vanilla?

Post by FreeER »

Sure it's possible, for the entity use

Code: Select all

data.raw.furnace["stone-furnace"] = nil
data.raw is where the prototypes are stored after data:extend is done. furnace is the type of the prototype and ["stone-furnace"] is the name of the prototype, of course you'd need to do something similar for any recipes and any technologies that may reference it. And either hope that no mods expect it to exist, don't use those mods, or use a for loop to check every recipe and tech and remove references (of course that only works if your mod is loaded AFTER all of the mods that might reference the stone-furnace). AND when it comes to their control.lua referencing it you'd have to manually find that code and remove it, or again, not use that mod :)

Honestly, I don't recommend it but, it IS possible.
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me :)
Or drop into #factorio on irc.esper.net

TheLastRonin
Inserter
Inserter
Posts: 23
Joined: Thu Jan 22, 2015 8:22 pm
Contact:

Re: How Do I Delete a Recipe or Item From Vanilla?

Post by TheLastRonin »

I like to tinker and I was thinking about bringing the game back to bare bones as far as crafting was concerned (no craftables), so I could personalize a tech tree. Sometimes I find modding more fun than playing. While I am generally good at doing the easy stuff like writing new objects, etc, I don't really know any LUA so thanks for the help, much appreciated :D.

PS - I just realized you are the guy that wrote the really helpful step-by-step on modding, you're a legend :).

TheLastRonin
Inserter
Inserter
Posts: 23
Joined: Thu Jan 22, 2015 8:22 pm
Contact:

Re: How Do I Delete a Recipe or Item From Vanilla?

Post by TheLastRonin »

FreeER wrote:Sure it's possible, for the entity use

Code: Select all

data.raw.furnace["stone-furnace"] = nil
data.raw is where the prototypes are stored after data:extend is done. furnace is the type of the prototype and ["stone-furnace"] is the name of the prototype, of course you'd need to do something similar for any recipes and any technologies that may reference it. And either hope that no mods expect it to exist, don't use those mods, or use a for loop to check every recipe and tech and remove references (of course that only works if your mod is loaded AFTER all of the mods that might reference the stone-furnace). AND when it comes to their control.lua referencing it you'd have to manually find that code and remove it, or again, not use that mod :)

Honestly, I don't recommend it but, it IS possible.
I attempted this and it won't recognize stone.furnace?

Kexík
Long Handed Inserter
Long Handed Inserter
Posts: 71
Joined: Mon Dec 01, 2014 12:52 pm
Contact:

Re: How Do I Delete a Recipe or Item From Vanilla?

Post by Kexík »

You can simply disable recipe so noone will be able create it, try

Code: Select all

data.raw.recipe["stone-furnace"].enabled = false

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: How Do I Delete a Recipe or Item From Vanilla?

Post by FreeER »

TheLastRonin wrote:I attempted this and it won't recognize stone.furnace?
"stone.furnace"? not sure where you got that from :)
the entity would be data.raw.furnace["stone-furnace"], the recipe would be data.raw.recipe["stone-furnace"] and the item would be data.raw.item["stone-furnace"]
remember data.raw["the_type"]["the_name"], if the_type or the_name don't have spaces or '-' (etc.) then you can use the '.' syntax (like data.raw) instead of the [""] bracket syntax.
If you want more specific help with your code then please add the exact code as well :)
Kexík wrote:You can simply disable recipe so noone will be able create it
This would work for the stone-furnace since it's enabled by default, but to do it for other items that ARE unlocked you'd either need to do so in-game with control.lua after the onresearchfinished event (and checking if that researched unlocked something you want removed, also using game.players[1].force.recipes[name].disabled = true, assuming player 1 always exists, if not then using a loop to get a player) or remove those items from the technology prototype during loading like shown below.

Code: Select all

-- noted untested
removed_items = {"item_name_1", "item_name_2"} -- list of all item/fluid names to be removed
disabled_recipes = {} -- table to store name of disabled recipes in, for technologies
-- this loop handles disabling recipes that have ingredients in the removed_items table
for name, recipe in pairs(data.raw.recipe) do
    if recipe.result then
      for _, removeName in ipairs(removed_items) do
          if recipe.result == removeName then
              recipe.enabled = false
              disabled_recipes[name] = name -- remember that we disabled this one
          end
      end
    elseif recipe.results then
      for ingredientIndex, ingredient in pairs(recipe.results) do
        for _, removeName in ipairs(removed_items) do
          -- fluids will be indexed by name, items typically by numeric index
          if (ingredient.name and ingredient.name == removeName) or (ingredient[1] and ingredient[1] == removeName ) then
              recipe.enabled = false
              disabled_recipes[name] = name -- remember that we disabled this one
              -- you might want to be more generous here and simply set
              -- recipe.results[ingredientIndex] = nil
              -- though, in that case there should probably be a check after
              -- the loop for if #recipe.results == 0 then disable the recipe
              -- if that caused any issues you'd likely need to loop over
              -- recipe.results backwards and use table.remove like I do below
              -- though I wouldn't expect it to cause issues, I'm not 100% certain
          end
        end
      end
    end
end

for name, technology in pairs(data.raw.technology) do
  if technology.effects then -- if there is an effects table, most do, not all
    -- loop through effects table backwards, since indexes are numeric
    -- and we will be deleting things the indexes would change
    -- though if nils are ignored, as I would expect, then that could be
    -- done here instead, just wanted it this way for reference mainly
    -- fyi, table = {}; table[1] = nil; results in #table == 1
    -- whereas table = {}; table['something'] = nil; results in #table == 0
    for index=#technology.effects,1,-1 do
      local effect = technology.effects[index]
      if effect.type == "unlock_recipe" then
        if disabled_recipes[effect.recipe] then -- we disabled this recipe
            table.remove(technology.effects, index) -- remove it from the table
        end
      end
    end
  end
end

cartmen180
Filter Inserter
Filter Inserter
Posts: 358
Joined: Fri Jul 25, 2014 2:53 pm
Contact:

Re: How Do I Delete a Recipe or Item From Vanilla?

Post by cartmen180 »

completely removing the stone furnace has some complications though, the burner miner requires it so that will throw an error.
Check out my mods

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: How Do I Delete a Recipe or Item From Vanilla?

Post by FreeER »

cartmen180 wrote:completely removing the stone furnace has some complications though, the burner miner requires it so that will throw an error.
um, cartmen180 did you read my reply? I mean it is the first reply so it isn't like it was hard to see, but it certainly seems like you didn't because
FreeER wrote:...of course you'd need to do something similar for any recipes and any technologies that may reference it. ...
And then there's the fact that the later posts mentioned simply disabling the recipe (and I provided some relatively decent code for something along those lines). Not that I'm trying to be rude here, but your post wouldn't have been particularly helpful even if no one else had posted (no possible solutions or ways to avoid it) and with the posts that are already here, well kind of just seems like you didn't care enough about helping to even see what has been suggested already.
TheLastRonin wrote:PS - I just realized you are the guy that wrote the really helpful step-by-step on modding, you're a legend :).
well, that's nice to hear :P Oh, wait, I should be humble and slightly embarrassed at being 'recognized' right? :oops: uh, yeah. thanks... :lol:
I still need to get that updated though, haven't had the time to really figure out how to redo the graphics for it though.

cartmen180
Filter Inserter
Filter Inserter
Posts: 358
Joined: Fri Jul 25, 2014 2:53 pm
Contact:

Re: How Do I Delete a Recipe or Item From Vanilla?

Post by cartmen180 »

i simply read over it as i am using a small phone to catch up on some topics here. As i didn't see that particular bit of information i thought it worth mentioning.

As the op said it wants to completely remove the stone-furnace from the game, simply disabling the recipe is not the solution to his request.
Check out my mods

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: How Do I Delete a Recipe or Item From Vanilla?

Post by FreeER »

cartmen180 wrote:i simply read over it as i am using a small phone to catch up on some topics here. As i didn't see that particular bit of information i thought it worth mentioning.
Understandable, though I personally would have waited until I could give a more detailed response about how to accomplish the goal rather than just one difficulty in doing so :)
cartmen180 wrote:As the op said it wants to completely remove the stone-furnace from the game, simply disabling the recipe is not the solution to his request.
True, and my first post covered the step needed for individual items (though not a nice way to loop through and do it automatically for multiple), however the code provided for disabling recipes could be modified to delete items as well as recipes/techs without much trouble (assuming basic understanding of Lua, or someone with that understanding willing to help. And that I didn't make any mistakes writing it since it's untested lol).

Sacredd
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Fri Mar 18, 2016 9:30 am
Contact:

Re: How Do I Delete a Recipe or Item From Vanilla?

Post by Sacredd »

Not sure if someone of you is looking for this, but I have found out how to remove an ingredient from a recipe.
Tested with 0.16.x.

For example we have in vanilla

Code: Select all

  {
    type = "recipe",
    name = "military-science-pack",
    enabled = false,
    energy_required = 10,
    ingredients =
    {
      {"piercing-rounds-magazine", 1},
      {"grenade", 1},
      {"gun-turret", 1}
    },
    result_count = 2,
    result = "military-science-pack"
  }
The command

Code: Select all

table.remove(data.raw["recipe"]["military-science-pack"].ingredients,1);
Would remove the first ingredient in the list of ingredients, so in this example "piercing-rounds-magazine".

Meanwhile

Code: Select all

table.remove(data.raw["recipe"]["military-science-pack"].ingredients,2);
Removes "grenade" and so on.

Now I am trying to figure out how to reduce the amount of items in a recipe, e.g. the "copper-cable" in

Code: Select all

  {
    type = "recipe",
    name = "high-tech-science-pack",
    enabled = false,
    energy_required = 14,
    ingredients =
    {
      {"battery", 1},
      {"processing-unit", 3},
      {"speed-module", 1},
      {"copper-cable", 30}
    },
    result_count = 2,
    result = "high-tech-science-pack"
  }
EDIT: a trick workaround could be to remove the ingredient and then add it with other amount:

Code: Select all

table.remove(data.raw["recipe"]["high-tech-science-pack"].ingredients,4);
table.insert(data.raw["recipe"]["high-tech-science-pack"].ingredients,{"copper-cable", 1});

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: How Do I Delete a Recipe or Item From Vanilla?

Post by FreeER »

Now I am trying to figure out how to reduce the amount of items in a recipe
Well, I haven't messed with Factorio in a long time now but, it should just be a lua table.
So data.raw["recipe"]["high-tech-science-pack"].ingredients is the table

Code: Select all

    {
      {"battery", 1},         -- index 1
      {"processing-unit", 3}, -- index 2
      {"speed-module", 1},    -- index 3
      {"copper-cable", 30}    -- index 4
    }
so the fourth element would be

Code: Select all

{"copper-cable", 30}
and it's second element is 30
so data.raw["recipe"]["high-tech-science-pack"].ingredients[4][2] would be the number 30 and you should be able to just change that to whatever you wanted.
For robustness however you may not want to use the index 4 to select the copper-cable, since if the order got shifted around then you'd be changing the wrong item count or if some mod removed an item then it wouldn't be at index 4 (there may not even be 4 ingredients). Instead you'd want to loop over the ingredients table and look for one who's first element (the name) matches what you care about.

Code: Select all

local ingredients = data.raw["recipe"]["high-tech-science-pack"].ingredients
local tofind = "copper-cable"
for k,v in ipairs(ingredients) do
  if v[1] == tofind then
    v[2] = 5 -- or whatever value you want
    break
  end
end
and of course you could create a function to make it simple to do for multiple eg

Code: Select all

local function changeRecipeIngredientCount(recipeName, ingedientName, newCount, isMultiplier, suppressError)
  local recipe = data.raw["recipe"][recipeName]
  if not recipe then if suppressError then return false else error("Failed to find recipe for " .. recipeName, 2) end end
  for k,v in ipairs(recipe.ingredients) do
    if v[1] == ingredientName then
      if isMultiplier then v[2] = v[2] * newCount
      else v[2] = newCount end
      return true -- don't check the rest and return success
    end
  end
end

-- nice names instead of just true/false
local DoMultiplyCount = true
local SetNewValue = false

-- example
changeRecipeIngredientCount('high-tech-science-pack", "copper-cable", 5)
changeRecipeIngredientCount('high-tech-science-pack", "copper-cable", 10, SetNewValue) -- alternative
changeRecipeIngredientCount('high-tech-science-pack", "battery", 10, DoMultiplyCount) -- multiply battery count by 10
changeRecipeIngredientCount('high-tech-science-pack", "battery", 1/5, DoMultiplyCount) -- divide count by 5 aka multiply by 1/5
Similarly for removing an ingredient you'd probably want to loop over the ingredients to find the index to make sure you're removing the right thing (what if two mods both wanted to remove whatever happened to be first? The first two ingredients would end up being removed).

and yeah, removing the element and readding it would work, but it may also change the order (so hopefully there's no other mods with code that depend on the order of things...)

Post Reply

Return to “Modding help”