clean up flora injection and make it configurable, off by default

This commit is contained in:
Zoë Gidiere 2024-01-05 19:44:31 -07:00
parent 2f470a3720
commit 56dd15c9aa
2 changed files with 49 additions and 22 deletions

View File

@ -42,6 +42,10 @@ public class PreLoadCompatibilityOptions implements ConfigTemplate, Properties {
@Default @Default
private double airThreshold = -0.5; private double airThreshold = -0.5;
@Value("minecraft.inject-flora")
@Default
private boolean injectFlora = false;
public boolean useVanillaBiomes() { public boolean useVanillaBiomes() {
return vanillaBiomes; return vanillaBiomes;
} }
@ -57,4 +61,8 @@ public class PreLoadCompatibilityOptions implements ConfigTemplate, Properties {
public double getAirThreshold() { public double getAirThreshold() {
return airThreshold; return airThreshold;
} }
public boolean isInjectFlora() {
return injectFlora;
}
} }

View File

@ -1,5 +1,10 @@
package com.dfsek.terra.mod.util; package com.dfsek.terra.mod.util;
import com.dfsek.terra.mod.CommonPlatform;
import com.dfsek.terra.mod.config.PreLoadCompatibilityOptions;
import com.dfsek.terra.mod.config.ProtoPlatformBiome;
import net.minecraft.block.entity.LootableContainerBlockEntity; import net.minecraft.block.entity.LootableContainerBlockEntity;
import net.minecraft.block.entity.MobSpawnerBlockEntity; import net.minecraft.block.entity.MobSpawnerBlockEntity;
import net.minecraft.block.entity.SignBlockEntity; import net.minecraft.block.entity.SignBlockEntity;
@ -68,29 +73,43 @@ public final class MinecraftUtil {
return null; return null;
} }
public static void registerFlora(Registry<net.minecraft.world.biome.Biome> biomes) { public static void registerFlora(Registry<net.minecraft.world.biome.Biome> biomeRegistry) {
CommonPlatform.get().getConfigRegistry().forEach(pack -> { // Register all Terra biomes.
pack.getCheckedRegistry(com.dfsek.terra.api.world.biome.Biome.class)
.forEach((id, biome) -> {
PreLoadCompatibilityOptions compatibilityOptions = pack.getContext().get(PreLoadCompatibilityOptions.class);
if (compatibilityOptions.isInjectFlora()) {
registerFlora(biome, pack, id, biomeRegistry);
}
});
});
logger.info("Injecting flora into Terra biomes..."); logger.info("Injecting flora into Terra biomes...");
TERRA_BIOME_MAP
.forEach((vb, terraBiomes) -> }
biomes.getOrEmpty(vb)
.ifPresentOrElse(vanilla -> terraBiomes public static void registerFlora(com.dfsek.terra.api.world.biome.Biome biome, ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey id, Registry<net.minecraft.world.biome.Biome> biomeRegistry) {
.forEach(tb -> biomes.getOrEmpty(tb) RegistryKey<net.minecraft.world.biome.Biome> vanillaKey = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(biomeRegistry);
.ifPresentOrElse( biomeRegistry.getOrEmpty(vanillaKey)
terra -> { .ifPresentOrElse(vanillaBiome -> {
Identifier terraBiomeIdentifier = new Identifier("terra", MinecraftUtil.createBiomeID(pack, id));
biomeRegistry.getOrEmpty(terraBiomeIdentifier).ifPresentOrElse(
terraBiome -> {
List<ConfiguredFeature<?, ?>> flowerFeatures = List.copyOf( List<ConfiguredFeature<?, ?>> flowerFeatures = List.copyOf(
vanilla.getGenerationSettings() vanillaBiome.getGenerationSettings()
.getFlowerFeatures()); .getFlowerFeatures());
logger.debug("Injecting flora into biome" + logger.debug("Injecting flora into biome" +
" {} : {}", tb, " {} : {}", terraBiomeIdentifier,
flowerFeatures); flowerFeatures);
((FloraFeatureHolder) terra.getGenerationSettings()).setFloraFeatures( ((FloraFeatureHolder) terraBiome.getGenerationSettings()).setFloraFeatures(
flowerFeatures); flowerFeatures);
}, },
() -> logger.error( () -> logger.error(
"No such biome: {}", "No such biome: {}",
tb))), terraBiomeIdentifier)
() -> logger.error("No vanilla biome: {}", vb))); );
},
() -> logger.error("No vanilla biome: {}", vanillaKey));
} }
public static Map<Identifier, List<Identifier>> getTerraBiomeMap() { public static Map<Identifier, List<Identifier>> getTerraBiomeMap() {