Page 1 of 2
Overriding someone else's mod
Posted: Fri May 27, 2016 11:24 am
by CMH
I'm trying to mod bob's mods to suit my playstyle, and wondering how do I change some of the items from his mod.
Just wondering what the code would look like to delete a particular tech/item/recipe from his mod so I can add my own (which will be named differently).
I'm a newbie, but I can figure out how to add/change a recipe, but not delete one.
Re: Overriding someone else's mod
Posted: Fri May 27, 2016 11:41 am
by prg
after the prototype has been added, which will probably happen in a data.lua, so do this in data-updates.lua.
You might need to take care of other prototypes referencing the one you just removed, which would be a bit more involved.
Re: Overriding someone else's mod
Posted: Fri May 27, 2016 12:26 pm
by CMH
Well, given that I don't know a better way, I was planning on changing the recipe, replacing what I've removed one item at a time.
when you say type, I assume "item" or "recipe"? Both?
Re: Overriding someone else's mod
Posted: Fri May 27, 2016 12:36 pm
by ArderBlackard
The first index is the type of prototype, the second one is the name.
Here is an example of a random recipe from the vanilla game:
Code: Select all
{
type = "recipe",
name = "solar-panel",
energy_required = 10,
enabled = false,
ingredients =
{
{"steel-plate", 5},
{"electronic-circuit", 15},
{"copper-plate", 5}
},
result = "solar-panel"
},
So to replace this one you may use a statement like this:
Code: Select all
data.raw["recipe"]["solar-pane"] =
{
type = "recipe",
name = "solar-panel",
energy_required = 10,
enabled = false,
ingredients =
{
{"steel-plate", 1},
{"electronic-circuit", 1},
{"copper-plate", 1}
},
result = "solar-panel"
}
To remove:
Code: Select all
data.raw["recipe"]["solar-pane"] = nil
BTW, you may want not to replace the whole prototype definition, but tune only some of it's properties like this:
Code: Select all
data.raw["recipe"]["solar-pane"].ingredients = { {"wood", 1}, { "electronic-circuit", 1 } }
Re: Overriding someone else's mod
Posted: Fri May 27, 2016 12:46 pm
by Arch666Angel
Yeah dont delete entities ans items if you can replace all the things referencing it. Deleting might lead to errors because of other thing referencing to it.
Re: Overriding someone else's mod
Posted: Fri May 27, 2016 1:22 pm
by CMH
That helps.
What I was doing was coming up with some issues. Apparently technology not found or something
Code: Select all
data.raw["technology"]["electrum-processing"] = nil
data.raw["recipe"]["electrum-alloy"] = nil
data.raw["item"]["electrum-alloy"] = nil
data:extend(
{
{
type = "technology",
name = "gold-alloy",
prerequisites =
{
"alloy-processing-1",
"gold-processing",
},
effects =
{
type = "unlock-recipe",
recipe = "gold-alloy"
}
}
}
)
data.raw.technology["gold-alloy"].icon = "__CMHMod__/graphics/icons/technology/electrum-processing.png"
data.raw.technology["gold-alloy"].order = "c-b-f[gold-alloy]"
data.raw.technology["gold-alloy"].unit = (
{
count = 50,
time = 30,
ingredients =
{
{"science-pack-1", 1},
{"science-pack-2", 1},
{"science-pack-3", 1},
}
}
)
data:extend(
{
{
type = "recipe",
name = "gold-alloy",
enabled = false,
category = "mixing-furnace",
energy_required = 17.5,
ingredients =
{
{type="item", name="silver-plate", amount=3},
{type="item", name="gold-plate", amount=2},
},
results =
{
{type="item", name="gold-alloy", amount=5}
}
},
{
type = "item",
name = "gold-alloy",
icon = "__bobplates__/graphics/icons/plate/electrum-plate.png",
flags = {"goes-to-main-inventory"},
subgroup = "bob-alloy",
order = "c-b-c[gold-alloy]",
stack_size = 200
},
}
)
Was trying to replace his electrum-plate with gold-alloy. I want to change the his silver ore into electrum, which bring me to my next question: how to change a modded ore?
p.s. So I can even change the name? That'd be great

Re: Overriding someone else's mod
Posted: Fri May 27, 2016 1:30 pm
by CMH
Tried this:
Code: Select all
data.raw["technology"]["electrum-processing"].name = {"gold-alloy"}
data.raw["recipe"]["electrum-alloy"].name = {"gold-alloy"}
data.raw["item"]["electrum-alloy"].name = {"gold-alloy"}
Didn't work, says can't find recipe. works fine when removed.
Re: Overriding someone else's mod
Posted: Fri May 27, 2016 2:21 pm
by ArderBlackard
Changing prototype name effectively means removing old prototype and creating a new one having the same properties but another name. I guess that the "electrum-alloy" recipe is referred somewhere else (by technologies or anything else) so it's not simply a matter of removing the prototype - you need to remove also all it's usages.
Re: Overriding someone else's mod
Posted: Fri May 27, 2016 2:24 pm
by CMH
Yeah, there's a couple of places it is used. Let me see if I can remove them.
Re: Overriding someone else's mod
Posted: Fri May 27, 2016 2:31 pm
by DedlySpyder
Wait, is all this to ONLY change the names? If so, just go to the locale and edit the names after the = for each thing
Re: Overriding someone else's mod
Posted: Fri May 27, 2016 3:34 pm
by bobingabout
I think maybe you should explain in detail what you're trying to do, then we'd be better able to suggest how to do that.
if the only issue is that you don't want to have to use electrum, and want to use gold instead, then there's a function in my library mod that can help with that. Obviously if you're overriding my mod, you'll have access to the library.
I think it's... bobmods.lib.replace_in_all_recipes(olditem, newitem), (I'll have to double check it), so you'd do bobmods.lib.replace_in_all_recipes("electrum-alloy", "gold-plate")
And then you can safely set data.raw.recipe["electrum-alloy"]=nil, same with item.
However, the electrum-processing technology will likely still be used as a prerequisite in a few places, the best thing to do would be to use a pairs iteration through all technologies, and then an ipairs iteration through all prerequisites within those technologies(a loop within a loop), and either remove any it finds, or replace with gold-processing.
That's how I'd do what I THINK you're trying to do.
Re: Overriding someone else's mod
Posted: Fri May 27, 2016 3:57 pm
by CMH
I'm happy to explain in detail.
I'm trying to reduce the number of ores, so I'm combining silver + gold into electrum (which is also a naturally occuring ore).
And it doesn't make sense for me to call gold + silver alloy electrum again (confusing) so I'm changing the name.
Of course this is just a part of what I'm doing, I'm planning on reducing silicon as a product of stone.
thinking of doing something with nickel as well.
Will also be adding an easier smelting process for a few of your ores as a backup (or to balance production). What this means is that there's no byproduct, therefore possibly being able to tailor your smelting between simple and advanced smelting to achieve the number of plates produced without having too much byproduct (ie galena to lead, but advanced lead can produce nickel as well. Solves the "too much nickel" issue while needing some sorting). Obv simple smelting will achieve lower yields.
Some interesting production controls can be put in place to choose between simple/advanced smelting. Possibly.
Also planning to tweak some recipes to increase consumption of type = "item" byproduct, as type = "gas" can be vented (not sulfur dioxide for some greenie reason

)
So that's the plan for my mod, the naming issue is just the start of it

Re: Overriding someone else's mod
Posted: Fri May 27, 2016 9:41 pm
by bobingabout
If you just want to rename the electrum, but keep the functionallity, then the easiest solution would be to simply rename it in locale, and leave it as electrum-alloy internally.
The ore items could have similar issues, but at least they're easier to remove than the plates, with very few exceptions, ores are only used in smelting recipes, unlike plates and alloys that are all over the place.
Re: Overriding someone else's mod
Posted: Fri May 27, 2016 9:53 pm
by Arch666Angel
If you want to reduce the ore patches then take a look at my refining mod, because thats what I did, combine all the ores in bobmods to compound ores and add refining steps to get the elements from them.
Re: Overriding someone else's mod
Posted: Sat May 28, 2016 3:34 am
by CMH
@Arch666Angel: will have a look.
@bobingabout: good thing your electrum is only used in 3 solar panels, which makes it pretty easy.
I doubt I'd be changing too many plates/alloys, as you can see I'm mainly interested in changing the ores>plates part.
How do I rename it in locale though?
edit: I found the locale file, and some of the programming now makes more sense. Still need to know how to edit it in a separate mod.
Re: Overriding someone else's mod
Posted: Sun May 29, 2016 6:58 pm
by bobingabout
here's a small extact of me editing things (in it's own mod) based on items that exist in another mod
Code: Select all
if data.raw.tool["science-pack-4"] then
bobmods.lib.replace_science_pack("water-miner-5", "alien-science-pack", "science-pack-4")
end
if data.raw.item["copper-pipe"] then
bobmods.lib.replace_recipe_item ("water-miner-1", "pipe", "copper-pipe")
end
if data.raw.item["advanced-processing-unit"] then
bobmods.lib.replace_recipe_item("water-miner-5", "processing-unit", "advanced-processing-unit")
bobmods.lib.add_technology_prerequisite("water-miner-5", "advanced-electronics-3")
end
my library makes it look easy.
the other important part is the dependancies tag in info.json.
Code: Select all
"dependencies": ["base >= 0.12.0", "boblibrary >= 0.12.5", "? bobconfig >= 0.12.0"]
As you can see, Base and Library are both required in this example, and config is opional.
you would need to put the specific mod you are editing as a requirement. if you are editing items from multiple mods, you should put them as optional, and perform additional checks to see if an item exists first before trying to edit it.
given the specific information, I'd say you want
Code: Select all
"dependencies": ["base >= 0.12.0", "bobplates >= 0.12.11"]
Re: Overriding someone else's mod
Posted: Mon May 30, 2016 12:47 pm
by CMH
Cool. Will have a closer look this weekend.
Looks like you've written your library well. Given that what I'm doing is just messing around your mod, your library will definitely be a dependency.
Also, still need to know how to change the name in another mod's locale.
Thanks.
Re: Overriding someone else's mod
Posted: Tue May 31, 2016 11:09 am
by bobingabout
CMH wrote:Also, still need to know how to change the name in another mod's locale.
Thanks.
I think if you just redefine the same locale entry, with the mod you're overriding as a dependency, it should replace the locale entry with yours, since it loads after.
Re: Overriding someone else's mod
Posted: Thu Jun 02, 2016 12:44 pm
by CMH
@Arch666Angel: I had a look at your mod. I don't really understand how you have programmed the ore generation. Would appreciate a bit of explanation to what you have done
Also, wondering how to remove an ore from bobsores (say I'd like to remove gold ore fields from being generated).
I'm thinking the easiest way would be for me to totally remove the ores I don't need, and re-write the ores>plates to the ones I want. There's no real need for me to generate new ores if I can just take over the ones already generated, although it does mean I'll need to remove the ones I don't want.
p.s. I will post my mod here when I think I've got enough for a release
viewtopic.php?f=97&t=26024
Re: Overriding someone else's mod
Posted: Thu Jun 02, 2016 2:34 pm
by bobingabout
I'd be better able to answer the question if I was looking at the code, but basically, use this line at the end of data.lua with my ores mod as a dependency, and plates and config as optional dependancies.
As a result, when the data-updates phase of bobores looks at the stored variables, it will not generate the ore's autoplace table, autoplace-control, or the noise-layer for that ore.
Alternatively you could delete those mentioned objects in data-final-fixes.lua by using the following lines, this will work for all ores, not just mine
Code: Select all
data.raw.resource["gold-ore"].autoplace = nil
data.raw["autoplace-control"]["gold-ore"] = nil
data.raw["noise-layer"]["gold-ore"] = nil
Though, deleting the noise layer CAN be dangerous if it is used by more than one ore, the reason to delete it though is that if you do not, it will slow down the map generation phase creating a resource overlay that isn't used. I can state though that every ore in the current release of my mods has it's own noise layer, used by nothing else.