[Mod 0.17.54] Factorio Bitumen

Topics and discussion about specific mods
User avatar
Shenpen
Fast Inserter
Fast Inserter
Posts: 178
Joined: Sat Aug 27, 2016 2:46 pm
Contact:

Re: [Mod 0.17.54] Factorio Bitumen

Post by Shenpen » Thu Aug 08, 2019 3:40 pm

bobingabout.png
bobingabout.png (875.16 KiB) Viewed 142 times
Bobs mods compatibilities are qued up...

Adamo
Filter Inserter
Filter Inserter
Posts: 294
Joined: Sat May 24, 2014 7:00 am
Contact:

Re: [Mod 0.17.54] Factorio Bitumen

Post by Adamo » Thu Aug 08, 2019 4:27 pm

Shenpen wrote:
Fri Aug 02, 2019 8:04 pm
What I need to figure out is how to make an alternative recipe for asphalt (using tar) active in case your mod is loaded and then put a soft dependency to the mod.
Did you figure out how to do this? I have a method that's worked well in my mods if you would like a code snippet.

User avatar
Shenpen
Fast Inserter
Fast Inserter
Posts: 178
Joined: Sat Aug 27, 2016 2:46 pm
Contact:

Re: [Mod 0.17.54] Factorio Bitumen

Post by Shenpen » Mon Aug 12, 2019 10:50 am

Adamo wrote:
Thu Aug 08, 2019 4:27 pm
Shenpen wrote:
Fri Aug 02, 2019 8:04 pm
What I need to figure out is how to make an alternative recipe for asphalt (using tar) active in case your mod is loaded and then put a soft dependency to the mod.
Did you figure out how to do this? I have a method that's worked well in my mods if you would like a code snippet.
No. I can make it work with Bobs' installed, but it then errors when trying to load, while Bobs' is not present.

slippycheeze
Filter Inserter
Filter Inserter
Posts: 482
Joined: Sun Jun 09, 2019 10:40 pm
Contact:

Re: [Mod 0.17.54] Factorio Bitumen

Post by slippycheeze » Tue Aug 13, 2019 4:51 pm

Shenpen wrote:
Mon Aug 12, 2019 10:50 am
Adamo wrote:
Thu Aug 08, 2019 4:27 pm
Shenpen wrote:
Fri Aug 02, 2019 8:04 pm
What I need to figure out is how to make an alternative recipe for asphalt (using tar) active in case your mod is loaded and then put a soft dependency to the mod.
Did you figure out how to do this? I have a method that's worked well in my mods if you would like a code snippet.
No. I can make it work with Bobs' installed, but it then errors when trying to load, while Bobs' is not present.
data.lua

Code: Select all

if mods["modname"] then
   -- use their recipe now.
end
control.lua

Code: Select all

if game.active_mods["modname"] then
  -- do something because mod is present
end

Adamo
Filter Inserter
Filter Inserter
Posts: 294
Joined: Sat May 24, 2014 7:00 am
Contact:

Re: [Mod 0.17.54] Factorio Bitumen

Post by Adamo » Tue Aug 13, 2019 7:19 pm

slippycheeze wrote:
Tue Aug 13, 2019 4:51 pm
Shenpen wrote:
Mon Aug 12, 2019 10:50 am
Ahh, thanks for the reminder that I meant to come back to this.

I'm not totally clear on what you want to do, Shenpen, but I take a slightly different approach than what slippycheeze does.

First set the asphalt thing to be an optional mod prereq. Then I would simply do this test, in data-updates.lua or data-final-fixes.lua. Fix the names with the relevant names,

Code: Select all

if data.raw.recipe["other-mod-asphalt"] then
    new_ingred_table = {{"bitumen-asphalt-name", number}, ...other ingredients... }
    new_recipe_table = etc.
    data,raw.recipe["other-mod-asphalt"].ingredients = new_ingred_table
    data.raw.recipe["bitumen-asphalt-recipe"] = new_recipe_table
end
So in a simple case that would change the other guy's recipe. Just be sure he isn't changing it back in his mod at some later data stage. But instead of doing this directly for each recipe, a function might be helpful.

I'm going to write you a function... OK, done.

Code: Select all

local replace_in_recipe_io = function(recipe,old_name,new_name,amount_mult)
	if type(recipe) == "string" then
		recipe = data.raw.recipe[recipe]
	end
	if not recipe 
	or not (type(recipe) == "table")
	or not recipe.type
	or not (recipe.type == "recipe") then
		return false
	end
	if amount_mult == nil 
	or type(amount_mult) ~= "number" then
		amount_mult = 1
	end
	if recipe.result then
		if recipe.result == old_name then
			recipe.result = new_name
		end
		recipe.result_count = math.floor(
			recipe.result_count or 1
			* amount_mult
		)
	end
	if recipe.normal and recipe.normal.result then
		if recipe.normal.result == old_name then
			recipe.normal.result = new_name
		end
		recipe.normal.result_count = math.floor(
			recipe.normal.result_count or 1
			* amount_mult
		)
	end
	if recipe.expensive and recipe.expensive.result then
		if recipe.expensive.result == old_name then
			recipe.expensive.result = new_name
		end
		recipe.expensive.result_count = math.floor(
			recipe.expensive.result_count or 1
			* amount_mult
		)
	end
	for _,ingredient in pairs(recipe.ingredients or {}) do
		if ingredient.name == old_name then
			ingredient.name = new_name
			ingredient.amount = math.ceil(
				ingredient.amount or ingredient[2] or 1
				* amount_mult
			)
			ingredient[2] = nil
		end
		if ingredient[1] == old_name then
			ingredient[1] = new_name
			ingredient[2] = math.ceil(
				ingredient[2] or ingredient.amount or 1
				* amount_mult
			)
			ingredient.amount = nil
		end
		if ingredient.name == nil
		and ingredient[1] == nil then
			ingredient = nil
		end
	end
	if recipe.normal then
		for _,ingredient in pairs(recipe.normal.ingredients or {}) do
			if ingredient.name == old_name then
				ingredient.name = new_name
				ingredient.amount = math.ceil(
					ingredient.amount or ingredient[2] or 1
					* amount_mult
				)
				ingredient[2] = nil
			end
			if ingredient[1] == old_name then
				ingredient[1] = new_name
				ingredient[2] = math.ceil(
					ingredient[2] or ingredient.amount or 1
					* amount_mult
				)
				ingredient.amount = nil
			end
			if ingredient.name == nil
			and ingredient[1] == nil then
				ingredient = nil
			end
		end
	end
	if recipe.expensive then
		for _,ingredient in pairs(recipe.expensive.ingredients or {}) do
			if ingredient.name == old_name then
				ingredient.name = new_name
				ingredient.amount = math.ceil(
					ingredient.amount or ingredient[2] or 1
					* amount_mult
				)
				ingredient[2] = nil
			end
			if ingredient[1] == old_name then
				ingredient[1] = new_name
				ingredient[2] = math.ceil(
					ingredient[2] or ingredient.amount or 1
					* amount_mult
				)
				ingredient.amount = nil
			end
			if ingredient.name == nil
			and ingredient[1] == nil then
				ingredient = nil
			end
		end
	end
	for _,result in pairs(recipe.results or {}) do
		if result.name == old_name then
			result.name = new_name
			result.amount = math.floor(
				result.amount or result[2] or 1
				* amount_mult
			)
		end
		if result[1] == old_name then
			result[1] = new_name
			result[2] = math.floor(
				result[2] or result.amount or 1
				* amount_mult
			)
			result.amount = nil
		end
		if result.name == nil
		and result[1] == nil then
			result = nil
		end
	end
	if recipe.normal then
		for _,result in pairs(recipe.normal.results or {}) do
			if result.name == old_name then
				result.name = new_name
				result.amount = math.floor(
					result.amount or result[2] or 1
					* amount_mult
				)
			end
			if result[1] == old_name then
				result[1] = new_name
				result[2] = math.floor(
					result[2] or result.amount or 1
					* amount_mult
				)
				result.amount = nil
			end
			if result.name == nil
			and result[1] == nil then
				result = nil
			end
		end
	end
	if recipe.expensive then
		for _,result in pairs(recipe.expensive.results or {}) do
			if result.name == old_name then
				result.name = new_name
				result.amount = math.floor(
					result.amount or result[2] or 1
					* amount_mult
				)
			end
			if result[1] == old_name then
				result[1] = new_name
				result[2] = math.floor(
					result[2] or result.amount or 1
					* amount_mult
				)
				result.amount = nil
			end
			if result.name == nil
			and result[1] == nil then
				result = nil
			end
		end
	end
end
If you have any problems, it's only because of some typo, which I will fix if you tell me or if I find a problem with it when I use it down the road. All of the important bases should be covered. This function will take a recipe and replace any ingredients or results called old_name with new_name and multiply the input or output number by amount_mult (rounding down for results, up for ingredients). I have a similar thing for injecting new recipes into techs, if you want that. So just combine the if statements we included above and the use of this function, like

Code: Select all

if data.raw.recipe["other-mod-asphalt"] then
    replace_in_recipe_io(data.raw.recipe["other-mod-asphalt"],"other-mod-asphalt-item","bitumen-asphalt",0.5)
end
to replace the other mod's asphalt with yours and decrease the amount of asphalt used by half. Remember to do it in data-updates.lua or data-final-fixes.lua, whichever is required to be sure you're making your changes AFTER the other mod (or any mod that modifies it) makes any final changes.

If what you're trying to do is take their item as an ingredient to your recipe, then put in data-updates.lua something like,

Code: Select all

if data.raw.item["other-mod-asphalt-precusor-item"] then
    replace_in_recipe_io(data.raw.recipe["bitumen-asphalt"],"bitumen-asphalt-precursor-item","other-mod-asphalt-precursor-item")
end
Since no amount_mult was specified, it'll just leave the ingredient amount the same as the original recipe.

User avatar
Shenpen
Fast Inserter
Fast Inserter
Posts: 178
Joined: Sat Aug 27, 2016 2:46 pm
Contact:

Re: [Mod 0.17.54] Factorio Bitumen

Post by Shenpen » Fri Aug 16, 2019 12:37 pm

First up: Thank you both for suggestions!

I will take a closer look, when I can.
Im a bit pressed for time, but this is next on my list.

Post Reply

Return to “Mods”

Who is online

Users browsing this forum: Mylon