Learning to mod

Place to get help with not working mods / modding interface.
Jakademous
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sat Aug 23, 2025 7:24 pm
Contact:

Learning to mod

Post by Jakademous »

im trying to change a recipe in the base game, the basic firearm magazine ( yellow ammo ) im struggling to understand what files i actually need to make this mod work, please help
eugenekay
Filter Inserter
Filter Inserter
Posts: 671
Joined: Tue May 15, 2018 2:14 am
Contact:

Re: Learning to mod

Post by eugenekay »

Filter Mining Drills is a good example of a "minimal mod" - it consists of only four files:
  • info.json contains metadata about the Mod
  • README.md explains the mod in plain text
  • thumbnail.png is a visual aid
  • data-updates.lua is the actual "working content" of the Mod
The code itself is simple enough to explain:

Code: Select all

local blacklist = { -- Allows for some Drills to be excluded in the future; currently unused/empty list
}

for _, prototype in pairs(data.raw["mining-drill"]) do -- Loop through all "mining-drill" that are already defined
  if not blacklist[prototype.name] then -- Check the blacklist to see if it should be skipped
    if not prototype.filter_count then  -- Mods can specify filter_count and this mod won't override it
      prototype.filter_count = 5 -- Modify the "filter_count" property
    end
  end
end
...and that's it! Good Luck!
User avatar
EvilPLa
Inserter
Inserter
Posts: 48
Joined: Sat Nov 14, 2020 7:26 am
Contact:

Re: Learning to mod

Post by EvilPLa »

Wise men speak because they have something to say Fools because they have to say something. (Plato)
Jakademous
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sat Aug 23, 2025 7:24 pm
Contact:

Re: Learning to mod

Post by Jakademous »

im trying to do a recipe change and the code shown does not show an example of what else i need besides this






local multiplier = settings.startup["cheaper-ammo-multiplier"].value

local recipe = data.raw.recipe["firearm_magazine"]

if recipe then
recipe.ingredients = {
{ type = "item", name = "iron_plate", amount = 1 }
{ type = "item", name = "coal", amount = 1 }
}

if recipe.result then
recipe.result_count = multiplier
elseif recipe.results then
for _, r in pairs(recipe.results) do
if r.name == "firearm_magazine" then
r.amount = multiplier
end
end
end
end
vjbone
Fast Inserter
Fast Inserter
Posts: 149
Joined: Sun Feb 14, 2016 10:02 am
Contact:

Re: Learning to mod

Post by vjbone »

To start out, create a folder in your user data directory/mods folder. This folder must have a specific name, mod name. You don't need to zip anything for now, that will come later when you're done working on the mod. When you're finished, the mod directory should look like this:

(user data directory, sometimes called .factorio)
mods
mod name
Then, inside fire-armor, create two files, info.json and data.lua. The directory should now look like:

(user data directory, sometimes called .factorio)
mods
mod name
  • data.lua
  • info.json
The info.json file

Code: Select all

{
  "name": "mod name",
  "version": "0.1.0",
  "title": "Mod Name",
  "author": "You",
  "factorio_version": "2.0",
  "dependencies": ["base >= 2.0"],
  "description": "This mod changes something"
}
for your code you need additional file settings.lua
--in settings.lua:

Code: Select all

data:extend({
    {
        type = "int-setting",
        name = "cheaper-ammo-multiplier",
        setting_type = "startup",
        minimum_value = 1,
        default_value = 1
    }
})
--in data.lua:
your code
Pi-C
Smart Inserter
Smart Inserter
Posts: 1762
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Learning to mod

Post by Pi-C »

Jakademous wrote: Sun Aug 24, 2025 2:42 pm

Code: Select all

  if recipe.result then
    recipe.result_count = multiplier
  elseif recipe.results then
    for _, r in pairs(recipe.results) do
      if r.name == "firearm_magazine" then
        r.amount = multiplier
      end
    end
  end
end
You shouldn't assume that recipe.result_count or r.amount are set to 1, other mods may have changed that! Instead, use the multiplier as multipier:

Code: Select all

  if recipe.result then
    recipe.result_count = recipe.result_count * multiplier
  elseif recipe.results then
    for _, r in pairs(recipe.results) do
      if r.name == "firearm_magazine" then
        r.amount = r.amount * multiplier
      end
    end
  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”