How to add Results to Recipes old?

Place to post guides, observations, things related to modding that are not mods themselves.
User avatar
GenFrogKing
Manual Inserter
Manual Inserter
Posts: 2
Joined: Thu Jun 01, 2017 5:41 am
Contact:

How to add Results to Recipes old?

Post by GenFrogKing »

Hello world and the Factorio community! I have been a huge fan of this game since its release and all the mods out there are awesome too; I really enjoy the added complexity, challenge and modularity lent to the game by Bob's, Angel's, Evolution, Bio Processing, HardCrafting, Youki's, Robot Army, etc.

To the topic at hand, how do I add a result to a vanilla recipe? I have been working on a mod off and on for the past month. With summer here, I am dedicating more time to it. One thing I've managed to do is make it so furnaces yield two items. For example, magnetite ore smelts to iron plate and iron slag. Alas, I've hit a road block! How does one add to the results of an existing recipe? Here is what I have tried thus far...

Code: Select all

data.raw.recipe["stone-brick"].results = {{"stone-brick",2},{"rock-slag",1}}
This code attempts to completely rewrite the old recipe, but flags this error message: "Failed to load mods: error while loading recipe prototype "stone-brick" (recipe): Key "icon" not found in property tree ROOT.recipe.stone-brick Modifications: Base Mod > Slave to the System"

Yes, my mod's name is "Slave to the System" in honor of a song I liked from the command and conquer series. The title also seems appropriate for the direction this mod is going.

Code: Select all

table.insert(data.raw["recipe"]["stone-brick"].results, {type="item", name="rock-slag", amount=1})
This code attempts to add a result to the recipe, but flags this error message: "Failed to load mods: __slave_to_the_system__/data.lua:13:...system__/prototypes/vanilla-extension/recipe-extension.lua:7:bad argument #1 to 'insert' (table expected, got nil)"

This probably falls into the category of GenFrogKing-doesn't-know-Lua... .
<.<
>.>
Help greatly appreciated!

Also, as a part two question, I want to know what sort of legal issues might arise with my mod. I'm making a compilation mod that revisits many of the mods I've mentioned and tweaks them to my liking. It also adds elements that are entirely my own creation. My questions are these: Do I need permission from the original mod developers to do this? What do I need to be aware of? Any sort of direction here would be appreciated! My goal here is not to take credit or step on any toes, but just to make what I believe will be an awesome extension of the Factorio experience; especially for those hardcore/masochistic players like me and my friends! :lol:
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: How to add Results to Recipes old?

Post by bobingabout »

If you read my mod licence, it states that although you can look through my code, and edit it for your own purposes, you are not allowed to distribute any version of my mod that has been changed.
If you plan to release a mod, I recommend you write a mod that edits my mod. It might sound complicated, but it should make sense if you think it through.

Now to the question in the title.

If you were to take a look in my library mod, you will find that I actually have quite an involved function to do what you are requesting, but to keep it short...

Code: Select all

local recipe = "stone-brick"
if not data.raw.recipe[recipe].results then
  if data.raw.recipe[recipe].result then
    if data.raw.recipe[recipe].result_count then 
      data.raw.recipe[recipe].results = {{data.raw.recipe[recipe].result, data.raw.recipe[recipe].result_count}}
    else
      data.raw.recipe[recipe].results = {{data.raw.recipe[recipe].result, 1}}
    end
  else
    data.raw.recipe[recipe].results = {} --should never actually be a valid option on an existing recipe.
  end
end
table.insert(data.raw.recipe[recipe].results, {type="item", name="rock-slag", amount=1})
of course, I've half made this a function (uses the recipe variable), that last line is just your line.
Though, as you can see, this actually uses the same method that you did in your first example that says it has no icon. So I'm not sure what's going wrong there, it should have worked.

but yes, you need to create the results table before you can insert a new entry into it.

Another issue you might experience is that some of the recipes in the new version of the game have a normal/expensive recipe variant, this code wouldn't work for that.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: How to add Results to Recipes old?

Post by Optera »

Your error messages look to me like your mod is loading before the mods containing the entities you are referencing. Note that Base is treated like a mod.
Add dependencies to info.json to make sure your mod is loaded after the mods you want to change.
"dependencies": ["base >= 0.15.13", "?boblogistics >= 0.15.1"],
Get to know the mods you modify and always use dependencies and data.lua whenever possible.
Only badly written mods use data-updates and data-final-fixes to generate prototypes when they could instead do it in data.lua.
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: How to add Results to Recipes old?

Post by bobingabout »

Optera wrote:Only badly written mods use data-updates and data-final-fixes to generate prototypes when they could instead do it in data.lua.
Although this is correct, that doesn't mean that data-updates isn't useful. The example I posted earlier is one such example of what could be in data-updates. data-final-fixes on the other hand is one that should very rarely be used. All prototypes should be created in data.lua and all edits to them completed and correct by the end of data-updates.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: How to add Results to Recipes old?

Post by Optera »

bobingabout wrote:
Optera wrote:Only badly written mods use data-updates and data-final-fixes to generate prototypes when they could instead do it in data.lua.
Although this is correct, that doesn't mean that data-updates isn't useful. The example I posted earlier is one such example of what could be in data-updates. data-final-fixes on the other hand is one that should very rarely be used. All prototypes should be created in data.lua and all edits to them completed and correct by the end of data-updates.
That's exactly what I wanted to say.
User avatar
GenFrogKing
Manual Inserter
Manual Inserter
Posts: 2
Joined: Thu Jun 01, 2017 5:41 am
Contact:

Re: How to add Results to Recipes old?

Post by GenFrogKing »

@bobingabout
I just looked a bit at everyone's license and realize all of you pretty much require the same thing you just mentioned. I've noticed that both you and Angel are pretty heavy on the scripting that checks for each others mods and then makes changes accordingly. Is this what you're suggesting I do? Thus far, I've been doing a complete rip and restructuring of everyone's assets, but I guess this would prevent me from publishing without lawsuit? I should have thought as much. :roll:

Anyways, if that's what I must do (meaning the indirect changes via scripting), then that's what I'll do. I'm sure with some practice I can get Lua's loops down. In fact, with some clever scripting this might actually save time from all the asset relocation and re-scripting.

Back to the topic...

I really drove myself nuts with this one, but it would appear (after looking at the Base Mod) that the "stone-brick" recipe is (what I guess is called) a processor recipe. The following example is taken from "demo-furnace-recipe.lua" in the Base Mod recipes.

Code: Select all

{
    type = "recipe",
    name = "stone-brick",
    category = "smelting",
    energy_required = 3.5,
    enabled = true,
    ingredients = {{"stone", 2}},
    result = "stone-brick"
  },
}
Special emphasis on the result (versus results plural) being a string (versus a table), I guess. I think what was happening was that the game thought I was trying to create a new non-processor recipe called "stone-brick" and realized that all other requirements like icon and subgroup for such a recipe were missing.

Code: Select all

data.raw.recipe["stone-brick"].icon = "__slave_to_the_system__/graphics/icons/stone-brick.png"
I also tried amending my script to fix the lack of icon with the above snippet and received this error: "Failed to load mods: error while running setup for recipe prototype "stone-brick" (recipe): Subgroup must be defined when there is no common main product."

So, my solution was this in my "vanilla-extension" directory.

Code: Select all

data.raw.recipe["stone-brick"] = nil
addRecipe("stone-brick","smelting","energy-pipe-distribution",2,{{"stone",2}},{{"stone-brick",2},{"rock-slag",1}},"0",true)
addRecipe is a function stored in anoter Lua file; it's just a huge time-saver. This script works, but I'm wondering if there was perhaps a more elegant way to change the original recipe's result. Also, for non-processor recipes, I believe both of these would work towards adding to the ingredients and results, respectively. I haven't tested the latter, but I can confirm the former.

Code: Select all

table.insert(data.raw["recipe"]["landfill"].ingredients, {"dirt",10})
table.insert(data.raw["recipe"]["landfill"].results, {"peanut",9001})
Optera wrote:Only badly written mods use data-updates and data-final-fixes to generate prototypes when they could instead do it in data.lua.
Thanks for the advice.
bobingabout wrote:Although this is correct, that doesn't mean that data-updates isn't useful. The example I posted earlier is one such example of what could be in data-updates. data-final-fixes on the other hand is one that should very rarely be used. All prototypes should be created in data.lua and all edits to them completed and correct by the end of data-updates.
Thanks for the clarification.
Post Reply

Return to “Modding discussion”