Page 1 of 1

Copy and modify a recipe into a new one

Posted: Fri Dec 18, 2020 8:24 pm
by aram
Hello everyone,

I just started looking into modding factorio.

I'm trying to do a simple thing:

Code: Select all

local myAssemblyMachine = util.table.deepcopy(data.raw["assembling-machine"]["assembling-machine-3"])

myAssemblyMachine["name"] = "assembling-machine-test"
myAssemblyMachine["crafting_speed"] = 5
myAssemblyMachine["localised_name"] = "Assembling Machine 4"
myAssemblyMachine["module_specification"] =
    {
      module_slots = 6
    }
    
-- recipe

local recipe = util.table.deepcopy(data.raw["recipe"]["assembling-machine-3"])
recipe.enabled = true
recipe.name = "assembling-machine-test"
recipe.localised_name = "Assembling Machine 4"
recipe.ingredients = {{"copper-plate",50},{"steel-plate",250}}
recipe.result = "assembling-machine-test"

-- item

local myitem = util.table.deepcopy(data.raw["item"]["assembling-machine-3"])
myitem.name = "assembling-machine-test"
myitem.localised_name = "Assembling Machine 4"

data:extend({myitem, myAssemblyMachine, recipe})
The recipe doesn't show up, I expected it to be next to assembly machine 3.

Any help would be appreciated.

Thanks

Re: Copy and modify a recipe into a new one

Posted: Fri Dec 18, 2020 10:35 pm
by DaveMcW
You need:

1. An entity ✔️
2. A recipe ✔️
3. An item ❌

Make an item by coping data.raw["item"]["assembling-machine-3"].

Re: Copy and modify a recipe into a new one

Posted: Fri Dec 18, 2020 11:03 pm
by aram
DaveMcW wrote: Fri Dec 18, 2020 10:35 pm You need:

1. An entity ✔️
2. A recipe ✔️
3. An item ❌

Make an item by coping data.raw["item"]["assembling-machine-3"].
Hi DaveMcW.

I added this at the end

Code: Select all

-- item

local myitem = util.table.deepcopy(data.raw["item"]["assembling-machine-3"])
myitem.name = "assembling-machine-test"

data:extend({myitem, myAssemblyMachine, recipe})
I still don't see it appear in game.

Re: Copy and modify a recipe into a new one

Posted: Sat Dec 19, 2020 12:03 am
by DaveMcW
For the recipe, you need to copy data.raw["recipe"]["assembling-machine-3"].

Re: Copy and modify a recipe into a new one

Posted: Sat Dec 19, 2020 3:16 am
by aram
DaveMcW wrote: Sat Dec 19, 2020 12:03 am For the recipe, you need to copy data.raw["recipe"]["assembling-machine-3"].
Thanks! it started showing now, however none of the extended properties seem to have applied such as crafting speed.

I looked up the crafting_speed by using Ctrl+Shift+F when looking at assembling machine 3 and added it like this:

Code: Select all

local myAssemblyMachine = util.table.deepcopy(data.raw["assembling-machine"]["assembling-machine-3"])

myAssemblyMachine["name"] = "assembling-machine-test"
myAssemblyMachine["crafting_speed"] = 5
myAssemblyMachine["localised_name"] = "Assembling Machine 4"
myAssemblyMachine["module_specification"] =
    {
      module_slots = 6
    }
In game I still see the crafting speed to be 1.25.

Re: Copy and modify a recipe into a new one

Posted: Sat Dec 19, 2020 4:12 am
by aram
Actually, never mind.

I found out that it's so much easier to copy from base / core lua files in Factorio folder and modify things.

Cheers!
Aram

Re: Copy and modify a recipe into a new one

Posted: Sat Dec 19, 2020 9:56 am
by PFQNiet
There is one thing you missed: setting the item's "place_result" to your new machine. As it stands you have a new item that is still placing AM3.

Re: Copy and modify a recipe into a new one

Posted: Sat Dec 19, 2020 8:54 pm
by aram
PFQNiet wrote: Sat Dec 19, 2020 9:56 am There is one thing you missed: setting the item's "place_result" to your new machine. As it stands you have a new item that is still placing AM3.
yes I saw that but only after I practiced a bit more.

Thanks