Page 1 of 1
How to prevent an existing resource from spawning?
Posted: Wed Aug 24, 2022 10:12 pm
by bluegreen1024
I'm trying to create a mod that changes some other mods' behavior. In particular I want to prevent some resources from spawning on the map. By this I mean that the ore shouldn't appear on the ground and the resource control sliders in the new game menu should not appear. It is OK, maybe even desirable, if the ore item, processing recipes, etc, still exist in the game. I want to use this mod alongside Space Exploration, so I also need to prevent SE from spawning the affected resources on other planets and from generating the corresponding core fragment types. As an example, what I have tried so far is
Code: Select all
for _, resource in pairs(data.raw.resource) do
if string.find(resource.name,"zircon",1,true) then
resource.autoplace.control = nil
resource.autoplace = nil
end
end
in data.lua. The goal is to prevent any resource whose name contains "zircon" from spawning and remove its control sliders. What actually happens is: zircon does not appear to spawn within a reasonable distance of the starting area (i checked probably ~1000 tiles outward) but the resource control sliders for zircon still appear in the new game menu.
If someone knows how to get the control sliders to disappear, and/or how to tell if Space Exploration ignores this resource when placing resources on other planets, could you help me out?
Thanks.
Re: How to prevent an existing resource from spawning?
Posted: Thu Aug 25, 2022 12:02 am
by FuryoftheStars
I’d check out some of the smaller mods that do the same, like the ones made by
brevven, as a better way of identifying how this is done.
Re: How to prevent an existing resource from spawning [SOLVED?]
Posted: Thu Aug 25, 2022 5:06 pm
by bluegreen1024
After looking at brevven's mods as well as digging through the code of the PyLandBlock mod, i found a way that seems to work. The code is
Code: Select all
local ores_to_remove = {"zircon", "graphite"}
for _, ore in ipairs(ores_to_remove) do
if data.raw["resource"][ore] then
data.raw["resource"][ore].autoplace = nil
end
if data.raw["autoplace-control"][ore] then
data.raw["autoplace-control"][ore] = nil
end
for _, preset in pairs(data.raw["map-gen-presets"]["default"]) do
if preset and preset.basic_settings and preset.basic_settings.autoplace_controls and preset.basic_settings.autoplace_controls[ore] then
preset.basic_settings.autoplace_controls[ore] = nil
end
end
end
which is derived from code in PyLandBlock, and it must run after any other code that adds resources or autoplace settings. The downside is that you must know the precise internal names of the resource and the autoplace control, and the code assumes these names are the same. Fortunately they are the same in brevven's mods (and apparently PyMods as well), but in general I don't know how to see the internal name of an autoplace control short of searching through another mod's code (debug mode doesn't help here). I also found that Space Exploration's Zone Discovery tab in Informatron doesn't list the affected resources as focus options, which is encouraging.
Hopefully this helps anyone else with the same issue, but I'm still curious if there is a more elegant way.
Re: How to prevent an existing resource from spawning [SOLVED?]
Posted: Fri Aug 26, 2022 3:23 am
by Pi-C
bluegreen1024 wrote: ↑Thu Aug 25, 2022 5:06 pm
I don't know how to see the internal name of an autoplace control short of searching through another mod's code (debug mode doesn't help here).
Open the game and press CTRL+SHIFT+E to get at the list of prototypes:
- autoplace_control.png (74.3 KiB) Viewed 853 times
Also, hovering the cursor over an entity and pressing CTRL+SHIFT+F will open a window showing the properties of that prototype.