How to prevent an existing resource from spawning?

Place to get help with not working mods / modding interface.
bluegreen1024
Burner Inserter
Burner Inserter
Posts: 15
Joined: Wed Aug 24, 2022 9:56 pm
Contact:

How to prevent an existing resource from spawning?

Post 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.

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: How to prevent an existing resource from spawning?

Post 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.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics

bluegreen1024
Burner Inserter
Burner Inserter
Posts: 15
Joined: Wed Aug 24, 2022 9:56 pm
Contact:

Re: How to prevent an existing resource from spawning [SOLVED?]

Post 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.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1724
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: How to prevent an existing resource from spawning [SOLVED?]

Post 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
autoplace_control.png (74.3 KiB) Viewed 849 times
Also, hovering the cursor over an entity and pressing CTRL+SHIFT+F will open a window showing the properties of that prototype.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Modding help”