Removing mob spawners from world generation

Is there any way of modifying the world generation in such a way that mob spawners are no longer generated?

I feel like it must be possible, considering Swappa managed to replace ores (and other blocks). Perhaps look into its source code?

The way Swappa managed it is being discontinued in 4.0 due to there being better alternatives with the World Generation API.

What you’ll want to do is iterate over the Populators of a given World and use an Iterator and if the PopulatorType is matching PopulatorTypes.DUNGEON, then remove from the Iterator. After that, the world will not generate dungeons (which includes the mob spawners). Correct me if I’m wrong @Deamon.

Edit: Iterate over the worlds AND their biomes.

Edit 2: A nice way @Deamon mentioned is

worldGenerator.getPopulators().removeAll(worldGenerator.getPopulators(Dungeon.class))

similarly for biomes:

for(BiomeType type: types) {
 worldGenerator.getBiomeSettings(type).getPopulators().removeAll(...)
}
1 Like

Thank you. Is there an ideal event listener in which to call these?
Right now I’m doing it after a GameStartedServerEvent.

Basically, you can handle it as each world is being loaded through the LoadWorldEvent

I tried doing it but I can’t figure out how to get the available BiomeTypes for a given WorldGenerator / BiomeGenerator (apparently no methods). Is it the same across all worlds?

Where can I find the Iterable<? extends BiomeType> you previously called types?

You’d want to get the Collection<BiomeType> from Sponge.getRegistry().getAllOf(BiomeType.class)

Thanks a lot for all your help. I’ll try running the code…