Implementing a new ore

Place to get help with not working mods / modding interface.
MrSmoothieHuman
Inserter
Inserter
Posts: 39
Joined: Sat Aug 05, 2023 1:20 am
Contact:

Implementing a new ore

Post by MrSmoothieHuman »

hello! this question has probably been asked to death but i need some help with creating a ore for my mod, currently in (very early :) ) development.

I have looked online and around the forums for any advice or how-to's on how to do this, but all of them have 'come up short' on how to actually implement it, if that makes sense. All i would really want to know is the basics of how to set it up, where to put things like icons or ore sprites, those kinds of things.

i do already have the basis of a mod set up, after following the modding tutorial on the wiki; i have the info.json, data.lua, control.lua, etc.

thank you for reading! :D

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

Re: Implementing a new ore

Post by Pi-C »

MrSmoothieHuman wrote:
Sat Aug 05, 2023 3:08 pm
hello! this question has probably been asked to death but i need some help with creating a ore for my mod, currently in (very early :) ) development.

I have looked online and around the forums for any advice or how-to's on how to do this, but all of them have 'come up short' on how to actually implement it, if that makes sense. All i would really want to know is the basics of how to set it up, where to put things like icons or ore sprites, those kinds of things.
Hi! Really the best way to get started is by looking at other mods that do something similar to what you want to achieve. There are a bunch of mods that create new ores; brevven, for example, has made some. Just download one and try to understand how it works! :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

vjbone
Fast Inserter
Fast Inserter
Posts: 143
Joined: Sun Feb 14, 2016 10:02 am
Contact:

Re: Implementing a new ore

Post by vjbone »

Mods or how it was made in factorio Base game https://github.com/wube/factorio-data/b ... ources.lua

MrSmoothieHuman
Inserter
Inserter
Posts: 39
Joined: Sat Aug 05, 2023 1:20 am
Contact:

Re: Implementing a new ore

Post by MrSmoothieHuman »

vjbone wrote:
Sun Aug 06, 2023 7:15 am
Mods or how it was made in factorio Base game https://github.com/wube/factorio-data/b ... ources.lua
im trying that right now actually! although, to no avail yet haha :lol: although, going through that file has defintely helped me learn and has progressed my mod a little; but the factorio server has been a huge help.

Thank you for replying though! :D
coder? i hardly know her!

MrSmoothieHuman
Inserter
Inserter
Posts: 39
Joined: Sat Aug 05, 2023 1:20 am
Contact:

Re: Implementing a new ore

Post by MrSmoothieHuman »

Pi-C wrote:
Sat Aug 05, 2023 5:36 pm
MrSmoothieHuman wrote:
Sat Aug 05, 2023 3:08 pm
hello! this question has probably been asked to death but i need some help with creating a ore for my mod, currently in (very early :) ) development.

I have looked online and around the forums for any advice or how-to's on how to do this, but all of them have 'come up short' on how to actually implement it, if that makes sense. All i would really want to know is the basics of how to set it up, where to put things like icons or ore sprites, those kinds of things.
Hi! Really the best way to get started is by looking at other mods that do something similar to what you want to achieve. There are a bunch of mods that create new ores; brevven, for example, has made some. Just download one and try to understand how it works! :-)
i will be sure to take a look! i was told to look at other mods to see how they implement ores, but im not really sure where to look. would i look in their files or on a site like github? :oops:
coder? i hardly know her!

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

Re: Implementing a new ore

Post by Pi-C »

MrSmoothieHuman wrote:
Sun Aug 06, 2023 9:33 am
i will be sure to take a look! i was told to look at other mods to see how they implement ores, but im not really sure where to look. would i look in their files or on a site like github? :oops:
Typically, the directory where you've installed Factorio will have a subdirectory "mods". If you use the game's mod installer, it will download mods into this subdirectory. The mods are just zip archives. Just unpack the mod (this should create a new subdirectory mods/unpacked_mod_name) and browse this local copy. :-)

By the way, if you make changes to an unpacked mod, there's no need to zip it again before running Factorio: unpacked mods will take precedence over zipped mods when the game is started.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

MrSmoothieHuman
Inserter
Inserter
Posts: 39
Joined: Sat Aug 05, 2023 1:20 am
Contact:

Re: Implementing a new ore

Post by MrSmoothieHuman »

Pi-C wrote:
Sun Aug 06, 2023 10:24 am
MrSmoothieHuman wrote:
Sun Aug 06, 2023 9:33 am
i will be sure to take a look! i was told to look at other mods to see how they implement ores, but im not really sure where to look. would i look in their files or on a site like github? :oops:
Typically, the directory where you've installed Factorio will have a subdirectory "mods". If you use the game's mod installer, it will download mods into this subdirectory. The mods are just zip archives. Just unpack the mod (this should create a new subdirectory mods/unpacked_mod_name) and browse this local copy. :-)

By the way, if you make changes to an unpacked mod, there's no need to zip it again before running Factorio: unpacked mods will take precedence over zipped mods when the game is started.
ah! that would have been useful to know before i cleared my mod folder out :lol: but no matter, im sure i can find something online.
and now, i do have it "mostly" working! i've got my actual resource spawning code to work, but now i have to deal with "Error AssignID: item with name "" cannot be found." :roll:

but thank you though, you have helped! :D
coder? i hardly know her!

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

Re: Implementing a new ore

Post by Pi-C »

MrSmoothieHuman wrote:
Sun Aug 06, 2023 10:33 am
[and now, i do have it "mostly" working! i've got my actual resource spawning code to work, but now i have to deal with "Error AssignID: item with name "" cannot be found." :roll:
You need a ResourceEntity (the thing that's visible as ore patch), but you also want the new resource to be minable, so you must define an item that players get as result of the mining.
but thank you though, you have helped! :D
You're welcome! :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

MrSmoothieHuman
Inserter
Inserter
Posts: 39
Joined: Sat Aug 05, 2023 1:20 am
Contact:

Re: Implementing a new ore

Post by MrSmoothieHuman »

Pi-C wrote:
Sun Aug 06, 2023 10:57 am
MrSmoothieHuman wrote:
Sun Aug 06, 2023 10:33 am
[and now, i do have it "mostly" working! i've got my actual resource spawning code to work, but now i have to deal with "Error AssignID: item with name "" cannot be found." :roll:
You need a ResourceEntity (the thing that's visible as ore patch), but you also want the new resource to be minable, so you must define an item that players get as result of the mining.
but thank you though, you have helped! :D
You're welcome! :-)
if i can be truly honest, i did go into resource.lua and maybe, possibly copy over the code for ores into my own and changed the name. However, i am looking to find define an item (in my item.lua) online. but that link you added will be helpful! i couldnt find anything on my own, so thank you. :D
coder? i hardly know her!

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

Re: Implementing a new ore

Post by Pi-C »

MrSmoothieHuman wrote:
Sun Aug 06, 2023 1:46 pm
if i can be truly honest, i did go into resource.lua and maybe, possibly copy over the code for ores into my own and changed the name.
To be truly honest: Most mod authors do that. Usually, they won't copy and paste the code verbatim, but use something like this:

Code: Select all

local my_item = table.deepcopy(data.raw.item["original-item-name"]
my_item.name = "new_name"
my_item.localised_name = new_localised_name
my_item.icon = "path_to_new_icon.png"
…
data:extend({my_item})
Check the prototype definitions, there you'll find the parameters that are relevant for your prototype.

However, i am looking to find define an item (in my item.lua) online. but that link you added will be helpful! i couldnt find anything on my own, so thank you. :D
This is the definition of vanilla iron-ore:

Code: Select all

  {
    type = "item",
    name = "iron-ore",
    icon = "__base__/graphics/icons/iron-ore.png",
    icon_size = 64,
    icon_mipmaps = 4,
    pictures =
    {
      { size = 64, filename = "__base__/graphics/icons/iron-ore.png",   scale = 0.25, mipmap_count = 4 },
      { size = 64, filename = "__base__/graphics/icons/iron-ore-1.png", scale = 0.25, mipmap_count = 4 },
      { size = 64, filename = "__base__/graphics/icons/iron-ore-2.png", scale = 0.25, mipmap_count = 4 },
      { size = 64, filename = "__base__/graphics/icons/iron-ore-3.png", scale = 0.25, mipmap_count = 4 }
    },
    subgroup = "raw-resource",
    order = "e[iron-ore]",
    stack_size = 50
  },
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

MrSmoothieHuman
Inserter
Inserter
Posts: 39
Joined: Sat Aug 05, 2023 1:20 am
Contact:

Re: Implementing a new ore

Post by MrSmoothieHuman »

Pi-C wrote:
Sun Aug 06, 2023 3:33 pm

This is the definition of vanilla iron-ore:

Code: Select all

  {
    type = "item",
    name = "iron-ore",
    icon = "__base__/graphics/icons/iron-ore.png",
    icon_size = 64,
    icon_mipmaps = 4,
    pictures =
    {
      { size = 64, filename = "__base__/graphics/icons/iron-ore.png",   scale = 0.25, mipmap_count = 4 },
      { size = 64, filename = "__base__/graphics/icons/iron-ore-1.png", scale = 0.25, mipmap_count = 4 },
      { size = 64, filename = "__base__/graphics/icons/iron-ore-2.png", scale = 0.25, mipmap_count = 4 },
      { size = 64, filename = "__base__/graphics/icons/iron-ore-3.png", scale = 0.25, mipmap_count = 4 }
    },
    subgroup = "raw-resource",
    order = "e[iron-ore]",
    stack_size = 50
  },
oh my god thank you :D i couldnt find just the items. but one question, whats the:

Code: Select all

{ size = 64, filename ="__base/graphics/icons/iron-ore.png", scale = 0.25, mipmap_count = 4},

used for? is it when you use an image for a tag in the map? :?:
coder? i hardly know her!

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

Re: Implementing a new ore

Post by Pi-C »

MrSmoothieHuman wrote:
Sun Aug 06, 2023 4:40 pm
whats the:

Code: Select all

{ size = 64, filename ="__base/graphics/icons/iron-ore.png", scale = 0.25, mipmap_count = 4},
used for? is it when you use an image for a tag in the map? :?:

Code: Select all

{
    …
    icon = "__base__/graphics/icons/iron-ore.png",
    icon_size = 64,
    icon_mipmaps = 4,
    pictures =
    {
      { size = 64, filename = "__base__/graphics/icons/iron-ore.png",   scale = 0.25, mipmap_count = 4 },
      { size = 64, filename = "__base__/graphics/icons/iron-ore-1.png", scale = 0.25, mipmap_count = 4 },
      { size = 64, filename = "__base__/graphics/icons/iron-ore-2.png", scale = 0.25, mipmap_count = 4 },
      { size = 64, filename = "__base__/graphics/icons/iron-ore-3.png", scale = 0.25, mipmap_count = 4 }
    },
    …
},
The item definition of vanilla iron ore uses "icon". In this case, icon_size and, optionally, icon_mipmaps must be on the root level of the item definition. Alternatively, "icons" could be used instead to compose an icon of different layers. This would look almost like the definition of "pictures", except there is no scale.

pictures is an array of tables where each table defines a version of an image. Incidentally, the first picture in pictures is the same that was used for icon:
iron-ore.png
iron-ore.png (11.24 KiB) Viewed 2737 times
You'll notice that the image isn't square but rectangular. It's actual size is 120 (width) x 64 (height). This is because the image combines 4 versions of the same image scaled down. Going from left to right, the file iron-ore.png combines images of size 64, 32, 16, and 8, so the file contains 4 mimaps. Why is that? The 64x64 image is what you usually see, but if you zoom out, one of the smaller mipmaps will be used instead. I may be wrong but I guess that has to do with saving work at runtime (the game doesn't have to scale down each image but can use a smaller prebuilt version) and better quality of the image (scaling down is a lossy business, and smaller prebuilt mipmaps could be touched up to prevent that).

Now, why are there different versions of the same picture? This is explained in FFF 297. Basically, the idea was that using the same image again and again would look rather dull if there was a lot of ore to display, so the devs introduced a bit of variety.

The following screenshot illustrates where icons (red box) and pictures (green box) are used:
Green: pictures. Red: icon.
Green: pictures. Red: icon.
iron-ore.png (465.62 KiB) Viewed 2737 times
If you look closely at the ore on the belt, you will notice that there are subtle differences between the separate belt segments.
is it when you use an image for a tag in the map
I think you'd use an item or recipe icon if you want to tag a factory on the map. If you want your tag totally different (meaning there is no icon that you could reuse), you can also define a sprite.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

MrSmoothieHuman
Inserter
Inserter
Posts: 39
Joined: Sat Aug 05, 2023 1:20 am
Contact:

Re: Implementing a new ore

Post by MrSmoothieHuman »

If you look closely at the ore on the belt, you will notice that there are subtle differences between the separate belt segments.
i never noticed that! i have to say though, it definitely helps with visuals, makes it look more..well, more varied :lol:

but i imagine, yeah its used more for perfomance and keep it from looking bad when scaling.

if you really dont mind me asking, since i dont want to go offtopic from my original point, but how do you implement autoplace? i copied over the uranium ore code (without realising why the code was different from the normal 4 ores), but it seems to all work after name-changes and things.
However, i (think) i have succesfully implemented autoplace into my code (which would be here:)
Image

but of course, i want to be sure i have everything down correctly. Sorry if its too offtpoic, but thank you for helping so far!
coder? i hardly know her!

MrSmoothieHuman
Inserter
Inserter
Posts: 39
Joined: Sat Aug 05, 2023 1:20 am
Contact:

Re: Implementing a new ore

Post by MrSmoothieHuman »

If you look closely at the ore on the belt, you will notice that there are subtle differences between the separate belt segments.
i never noticed that! i have to say though, it definitely helps with visuals, makes it look more..well, more varied :lol:

but i imagine, yeah its used more for perfomance and keep it from looking bad when scaling.

if you really dont mind me asking, since i dont want to go offtopic from my original point, but how do you implement autoplace? i copied over the uranium ore code (without realising why the code was different from the normal 4 ores), but it seems to all work after name-changes and things.
However, i (think) i have succesfully implemented autoplace into my code (which would be here:)
Image

but of course, i want to be sure i have everything down correctly. Sorry if its too offtpoic, but thank you for helping so far!
coder? i hardly know her!

MrSmoothieHuman
Inserter
Inserter
Posts: 39
Joined: Sat Aug 05, 2023 1:20 am
Contact:

Re: Implementing a new ore

Post by MrSmoothieHuman »

If you look closely at the ore on the belt, you will notice that there are subtle differences between the separate belt segments.
i never noticed that! i have to say though, it definitely helps with visuals, makes it look more..well, more varied :lol:

but i imagine, yeah its used more for perfomance and keep it from looking bad when scaling.

if you really dont mind me asking, since i dont want to go offtopic from my original point, but how do you implement autoplace? i copied over the uranium ore code (without realising why the code was different from the normal 4 ores), but it seems to all work after name-changes and things.
However, i (think) i have succesfully implemented autoplace into my code (which would be here:)
Image

but of course, i want to be sure i have everything down correctly. Sorry if its too offtpoic, but thank you for helping so far!
coder? i hardly know her!

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

Re: Implementing a new ore

Post by Pi-C »

MrSmoothieHuman wrote:
Sun Aug 06, 2023 6:49 pm
if you really dont mind me asking, since i dont want to go offtopic from my original point, but how do you implement autoplace? i copied over the uranium ore code (without realising why the code was different from the normal 4 ores), but it seems to all work after name-changes and things.
However, i (think) i have succesfully implemented autoplace into my code […]
but of course, i want to be sure i have everything down correctly. Sorry if its too offtpoic, but thank you for helping so far!
So far, I have no personal experience in modding resources. But you are calling the function resource_autoplace_settings defined in data/core/lualib/resource-autoplace.lua, which is preceded by this comment:

Code: Select all

--- Creates and returns an AutoplaceSpecification that will generate spot-based ore patches.
-- Required parameters:
-- - name - name for the type, used as the default autoplace control name and patch set name
--   (each of which can be overridden separately)
-- - base_density - amount of stuff, on average, to be placed per tile
-- Optional parameters:
-- - patch_set_name - name of the patch set; patches sets of the same name and seed1 will overlap; default: name
-- - autoplace_control_name - name of the corresponding autoplace control; default: name
-- - random_probability - probability of placement at any given tile within a patch; default: 1
-- - base_spots_per_km2 - number of patches per square kilometer near the starting area
-- - has_starting_area_placement - true|false|nil - yes, no, and there is no special starting area, respectively
-- - seed1 - random seed to use when generating patch positions; default: 100
-- More obscure parameters can be read about in the inline comments.
According to your screenshot, the required parameter base_density is missing, so you should fix that. Comparing the code of the function with your screenshot, "name" seems to be the only valid parameter you've used. Also, the description of AutoplaceSpecification doesn't contain anything about "type", "category", "richness", and "can_be_disabled". There are some parameters you didn't include (e.g. "order" and "control"), but it seems the function will provide default values to fall back on.

Regarding "richness", this is not supposed to be a Boolean value. Instead, there are "richness_base", "richness_multiplier", and "richness_multiplier_distance_bonus" which will be used to calculate richness.

In Pyanodons Raw Ores, I've found two different ways to set "autoplace". This one is used for pure ores (e.g. in prototypes/ores/aluminium.lua):

Code: Select all

    autoplace = resource_autoplace.resource_autoplace_settings {
        name = "ore-aluminium",
        order = "b",
        base_density = 10,
        base_spots_per_km2 = 1.25,
        has_starting_area_placement = true,
        random_spot_size_minimum = 2,
        random_spot_size_maximum = 4,
        regular_rq_factor_multiplier = 1,
        starting_rq_factor_multiplier = 2,
        candidate_spot_count = 20
    },
This one is used for a combination of a particular ore and rock, which seems to not use resource_autoplace.resource_autoplace_settings (e.g. in prototypes/ores/aluminium-rock.lua):

Code: Select all

    autoplace = {
        name = "aluminium-rock",
        order = "b-aluminium-rock",
        -- We return the chance of spawning on any given tile here
        probability_expression = noise.define_noise_function( function(x, y, tile, map)
            -- This is the user's map setting for the frequency of this ore
            local frequency_multiplier = noise.var("control-setting:aluminium-rock:frequency:multiplier")
            -- 0% chance of spawning in starting area (tier == 0)
            -- Using this is equivalent to has_starting_area_placement = false
            local tier = noise.clamp(noise.var("tier"), 0, 1)
            -- 1 in 64 chunks (each chunk is 64x64 tiles)
            local desired_frequency = 1 / (64 * 64^2)
            -- Our final chance, likely a very, very small decimal
            return tier * desired_frequency * frequency_multiplier
          end),
        -- We return the richness here, which is just the quantity the resource tile yields
        richness_expression = noise.define_noise_function( function(x, y, tile, map)
            -- This is the user's map setting for richness of this ore
            -- We ignore size here because we're always a single tile resource
            local richness_multiplier = noise.var("control-setting:aluminium-rock:richness:multiplier")
            -- This is the distance from the starting position, which is how vanilla scales ore yield
            local distance_value = noise.var("distance")
            -- This is our multiplier for the above, determining the yield gains over distance
            local scalar = 2^16
            -- Add it all together or what is likely a pretty big number
            return distance_value * scalar * richness_multiplier
        end)
    },
I hope these examples are useful! Otherwise, you should open a separate thread regarding autoplacing of resources. This would increase your chances that some real experts in this field may help you. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

MrSmoothieHuman
Inserter
Inserter
Posts: 39
Joined: Sat Aug 05, 2023 1:20 am
Contact:

Re: Implementing a new ore

Post by MrSmoothieHuman »

nope! those are completely useful! :) i have someone who messaged me and helped me with the autoplace (still some errors, but we are getting there :lol: ) but those will be super useful for what im trying to accomplish.

i have to thank you so much for your help, you have been so helpful and i cannot thank you enough. I hope you have a good day/afternoon/night! :D
coder? i hardly know her!

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

Re: Implementing a new ore

Post by Pi-C »

MrSmoothieHuman wrote:
Mon Aug 07, 2023 11:09 am
i have to thank you so much for your help, you have been so helpful and i cannot thank you enough. I hope you have a good day/afternoon/night! :D
You're welcome! By the way, it would be nice if you'd post a link to your mod here once you've got it ready. :-D
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

MrSmoothieHuman
Inserter
Inserter
Posts: 39
Joined: Sat Aug 05, 2023 1:20 am
Contact:

Re: Implementing a new ore

Post by MrSmoothieHuman »

Pi-C wrote:
Mon Aug 07, 2023 11:49 am
MrSmoothieHuman wrote:
Mon Aug 07, 2023 11:09 am
i have to thank you so much for your help, you have been so helpful and i cannot thank you enough. I hope you have a good day/afternoon/night! :D
You're welcome! By the way, it would be nice if you'd post a link to your mod here once you've got it ready. :-D
i thought about it and most likely will! i got it to actually work with the ore, and it spawns and all that jazz. next to work on items and things :twisted:

btw, i dont think i ever specified what my mod is, its a mod for adding pikmin to factorio! i looked on the mod portal and couldnt find anything about pikmin, so i decided to do it myself! :)

since it isnt ready ready, but i do have a few screenshots, is there anyway i can contact you to show you? :?:
coder? i hardly know her!

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

Re: Implementing a new ore

Post by Pi-C »

MrSmoothieHuman wrote:
Mon Aug 07, 2023 12:35 pm
since it isnt ready ready, but i do have a few screenshots, is there anyway i can contact you to show you? :?:
A private message here on the forum should work! Click on my name to open the profile, there's a link "Send private message".
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”