Page 1 of 1

Learning to mod

Posted: Sat Aug 23, 2025 7:27 pm
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

Re: Learning to mod

Posted: Sat Aug 23, 2025 10:02 pm
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!

Re: Learning to mod

Posted: Sun Aug 24, 2025 10:07 am
by EvilPLa

Re: Learning to mod

Posted: Sun Aug 24, 2025 2:42 pm
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

Re: Learning to mod

Posted: Sun Aug 24, 2025 3:47 pm
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

Re: Learning to mod

Posted: Sun Aug 24, 2025 4:06 pm
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