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) {
logger.info("Injecting flora into Terra biomes..."); CommonPlatform.get().getConfigRegistry().forEach(pack -> { // Register all Terra biomes.
TERRA_BIOME_MAP pack.getCheckedRegistry(com.dfsek.terra.api.world.biome.Biome.class)
.forEach((vb, terraBiomes) -> .forEach((id, biome) -> {
biomes.getOrEmpty(vb) PreLoadCompatibilityOptions compatibilityOptions = pack.getContext().get(PreLoadCompatibilityOptions.class);
.ifPresentOrElse(vanilla -> terraBiomes if (compatibilityOptions.isInjectFlora()) {
.forEach(tb -> biomes.getOrEmpty(tb) registerFlora(biome, pack, id, biomeRegistry);
.ifPresentOrElse( }
terra -> { });
List<ConfiguredFeature<?, ?>> flowerFeatures = List.copyOf(
vanilla.getGenerationSettings()
.getFlowerFeatures());
logger.debug("Injecting flora into biome" +
" {} : {}", tb,
flowerFeatures);
((FloraFeatureHolder) terra.getGenerationSettings()).setFloraFeatures(
flowerFeatures);
},
() -> logger.error(
"No such biome: {}",
tb))),
() -> logger.error("No vanilla biome: {}", vb)));
});
logger.info("Injecting flora into Terra biomes...");
}
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) {
RegistryKey<net.minecraft.world.biome.Biome> vanillaKey = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(biomeRegistry);
biomeRegistry.getOrEmpty(vanillaKey)
.ifPresentOrElse(vanillaBiome -> {
Identifier terraBiomeIdentifier = new Identifier("terra", MinecraftUtil.createBiomeID(pack, id));
biomeRegistry.getOrEmpty(terraBiomeIdentifier).ifPresentOrElse(
terraBiome -> {
List<ConfiguredFeature<?, ?>> flowerFeatures = List.copyOf(
vanillaBiome.getGenerationSettings()
.getFlowerFeatures());
logger.debug("Injecting flora into biome" +
" {} : {}", terraBiomeIdentifier,
flowerFeatures);
((FloraFeatureHolder) terraBiome.getGenerationSettings()).setFloraFeatures(
flowerFeatures);
},
() -> logger.error(
"No such biome: {}",
terraBiomeIdentifier)
);
},
() -> logger.error("No vanilla biome: {}", vanillaKey));
} }
public static Map<Identifier, List<Identifier>> getTerraBiomeMap() { public static Map<Identifier, List<Identifier>> getTerraBiomeMap() {