Implementing a new ore
-
- Inserter
- Posts: 39
- Joined: Sat Aug 05, 2023 1:20 am
- Contact:
Implementing a new ore
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!
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!
Re: Implementing a new ore
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!MrSmoothieHuman wrote: ↑Sat Aug 05, 2023 3:08 pmhello! 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.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: Implementing a new ore
Mods or how it was made in factorio Base game https://github.com/wube/factorio-data/b ... ources.lua
-
- Inserter
- Posts: 39
- Joined: Sat Aug 05, 2023 1:20 am
- Contact:
Re: Implementing a new ore
im trying that right now actually! although, to no avail yet haha 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.vjbone wrote: ↑Sun Aug 06, 2023 7:15 amMods or how it was made in factorio Base game https://github.com/wube/factorio-data/b ... ources.lua
Thank you for replying though!
coder? i hardly know her!
-
- Inserter
- Posts: 39
- Joined: Sat Aug 05, 2023 1:20 am
- Contact:
Re: Implementing a new ore
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?Pi-C wrote: ↑Sat Aug 05, 2023 5:36 pmHi! 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!MrSmoothieHuman wrote: ↑Sat Aug 05, 2023 3:08 pmhello! 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.
coder? i hardly know her!
Re: Implementing a new ore
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.MrSmoothieHuman wrote: ↑Sun Aug 06, 2023 9:33 ami 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?
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!
-
- Inserter
- Posts: 39
- Joined: Sat Aug 05, 2023 1:20 am
- Contact:
Re: Implementing a new ore
ah! that would have been useful to know before i cleared my mod folder out but no matter, im sure i can find something online.Pi-C wrote: ↑Sun Aug 06, 2023 10:24 amTypically, 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.MrSmoothieHuman wrote: ↑Sun Aug 06, 2023 9:33 ami 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?
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.
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."
but thank you though, you have helped!
coder? i hardly know her!
Re: Implementing a new ore
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.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."
You're welcome!but thank you though, you have helped!
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
-
- Inserter
- Posts: 39
- Joined: Sat Aug 05, 2023 1:20 am
- Contact:
Re: Implementing a new ore
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.Pi-C wrote: ↑Sun Aug 06, 2023 10:57 amYou 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.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."
You're welcome!but thank you though, you have helped!
coder? i hardly know her!
Re: Implementing a new ore
To be truly honest: Most mod authors do that. Usually, they won't copy and paste the code verbatim, but use something like this:MrSmoothieHuman wrote: ↑Sun Aug 06, 2023 1:46 pmif 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.
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})
This is the definition of vanilla iron-ore: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.
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!
-
- Inserter
- Posts: 39
- Joined: Sat Aug 05, 2023 1:20 am
- Contact:
Re: Implementing a new ore
oh my god thank you i couldnt find just the items. but one question, whats the: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 },
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!
Re: Implementing a new ore
MrSmoothieHuman wrote: ↑Sun Aug 06, 2023 4:40 pmwhats the:
used for? is it when you use an image for a tag in the map?Code: Select all
{ size = 64, filename ="__base/graphics/icons/iron-ore.png", scale = 0.25, mipmap_count = 4},
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 }
},
…
},
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: 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: If you look closely at the ore on the belt, you will notice that there are subtle differences between the separate belt segments.
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.is it when you use an image for a tag in the map
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
-
- Inserter
- Posts: 39
- Joined: Sat Aug 05, 2023 1:20 am
- Contact:
Re: Implementing a new ore
i never noticed that! i have to say though, it definitely helps with visuals, makes it look more..well, more variedIf you look closely at the ore on the belt, you will notice that there are subtle differences between the separate belt segments.
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:)
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!
-
- Inserter
- Posts: 39
- Joined: Sat Aug 05, 2023 1:20 am
- Contact:
Re: Implementing a new ore
i never noticed that! i have to say though, it definitely helps with visuals, makes it look more..well, more variedIf you look closely at the ore on the belt, you will notice that there are subtle differences between the separate belt segments.
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:)
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!
-
- Inserter
- Posts: 39
- Joined: Sat Aug 05, 2023 1:20 am
- Contact:
Re: Implementing a new ore
i never noticed that! i have to say though, it definitely helps with visuals, makes it look more..well, more variedIf you look closely at the ore on the belt, you will notice that there are subtle differences between the separate belt segments.
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:)
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!
Re: Implementing a new ore
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:MrSmoothieHuman wrote: ↑Sun Aug 06, 2023 6:49 pmif 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!
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.
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
},
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)
},
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
-
- Inserter
- Posts: 39
- Joined: Sat Aug 05, 2023 1:20 am
- Contact:
Re: Implementing a new ore
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 ) 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!
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!
coder? i hardly know her!
Re: Implementing a new ore
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.MrSmoothieHuman wrote: ↑Mon Aug 07, 2023 11:09 ami 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!
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
-
- Inserter
- Posts: 39
- Joined: Sat Aug 05, 2023 1:20 am
- Contact:
Re: Implementing a new ore
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 thingsPi-C wrote: ↑Mon Aug 07, 2023 11:49 amYou'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.MrSmoothieHuman wrote: ↑Mon Aug 07, 2023 11:09 ami 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!
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!
Re: Implementing a new ore
A private message here on the forum should work! Click on my name to open the profile, there's a link "Send private message".MrSmoothieHuman wrote: ↑Mon Aug 07, 2023 12:35 pmsince it isnt ready ready, but i do have a few screenshots, is there anyway i can contact you to show you?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!