Skip to content

Commit

Permalink
Fix Vanilla Addition Warm Flowers having same placed feature as defau…
Browse files Browse the repository at this point in the history
…lt, Allow Enabling/Disabling of Individual Additional Features

Signed-off-by: Joseph T. McQuigg <[email protected]>
  • Loading branch information
JT122406 committed Dec 11, 2024
1 parent 9d758f3 commit cc92bf5
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"minecraft:savanna",
"minecraft:savanna_plateau"
],
"features": "biomeswevegone:vanilla/flower_default",
"features": "biomeswevegone:vanilla/flower_warm",
"step": "vegetal_decoration"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"placement": [
{
"type": "minecraft:rarity_filter",
"chance": 16
"chance": 32
},
{
"type": "minecraft:in_square"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"feature": "biomeswevegone:vanilla/flower_default",
"placement": [
{
"type": "minecraft:rarity_filter",
"chance": 16
},
{
"type": "minecraft:in_square"
},
{
"type": "minecraft:heightmap",
"heightmap": "MOTION_BLOCKING"
},
{
"type": "minecraft:biome"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.potionstudios.biomeswevegone.PlatformHandler;
import net.potionstudios.biomeswevegone.world.level.levelgen.biome.BWGBiomes;
import net.potionstudios.biomeswevegone.world.level.levelgen.feature.placed.BWGOverworldTreePlacedFeatures;
import net.potionstudios.biomeswevegone.world.level.levelgen.feature.placed.BWGVanillaPlacedFeatures;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
Expand All @@ -28,7 +31,7 @@
import java.util.function.Supplier;

public record BWGWorldGenConfig(Map<ResourceKey<Biome>, Boolean> enabledBiomes, int regionWeight,
boolean vanillaAdditions) {
boolean vanillaAdditions, Map<ResourceKey<PlacedFeature>, Boolean> vanillaFeatures) {

public static final Path PATH = PlatformHandler.PLATFORM_HANDLER.configPath().resolve("world_generation.json5");

Expand All @@ -39,14 +42,13 @@ public record BWGWorldGenConfig(Map<ResourceKey<Biome>, Boolean> enabledBiomes,
instance.group(
CommentedCodec.of(Codec.unboundedMap(ResourceKey.codec(Registries.BIOME), Codec.BOOL), "enabled_biomes", "Which biomes are enabled, if disabled the biome will default to its vanilla counterpart for the given region").orElse(getDefaultBiomes()).forGetter(BWGWorldGenConfig::enabledBiomes),
CommentedCodec.of(Codec.INT, "region_weight", "How much each BWG region weighs. This weight applies to all 3 BWG Regions").orElse(8).forGetter(BWGWorldGenConfig::regionWeight),
CommentedCodec.of(Codec.BOOL, "vanilla_additions", "Whether to add bwg flowers and features to Vanilla Biomes (Config Option for Fabric Only)").orElse(true).forGetter(config -> true)
CommentedCodec.of(Codec.BOOL, "vanilla_additions", "Whether to add bwg flowers and features to Vanilla Biomes (Config Option for Fabric Only)").orElse(true).forGetter(config -> true),
CommentedCodec.of(Codec.unboundedMap(ResourceKey.codec(Registries.PLACED_FEATURE), Codec.BOOL), "enabled_vanilla_additions", "BWG Features that we add to Vanilla Biomes").orElse(getVanillaPlacedFeatureAdditions()).forGetter(BWGWorldGenConfig::vanillaFeatures)
).apply(instance, BWGWorldGenConfig::new)
);

public static BWGWorldGenConfig createDefault() {
Object2BooleanMap<ResourceKey<Biome>> enabledBiomes = getDefaultBiomes();

return new BWGWorldGenConfig(enabledBiomes, 8, true);
return new BWGWorldGenConfig(getDefaultBiomes(), 8, true, getVanillaPlacedFeatureAdditions());
}

private static @NotNull Object2BooleanMap<ResourceKey<Biome>> getDefaultBiomes() {
Expand All @@ -59,6 +61,17 @@ public static BWGWorldGenConfig createDefault() {
return enabledBiomes;
}

private static @NotNull Object2BooleanMap<ResourceKey<PlacedFeature>> getVanillaPlacedFeatureAdditions() {
Object2BooleanMap<ResourceKey<PlacedFeature>> enabledFeatures = new Object2BooleanOpenHashMap<>();
enabledFeatures.put(BWGVanillaPlacedFeatures.FLOWER_DEFAULT, true);
enabledFeatures.put(BWGVanillaPlacedFeatures.FLOWER_PLAINS, true);
enabledFeatures.put(BWGVanillaPlacedFeatures.FOREST_FLOWERS, true);
enabledFeatures.put(BWGVanillaPlacedFeatures.FLOWER_WARM, true);
enabledFeatures.put(BWGOverworldTreePlacedFeatures.PALM_TREES, true);

return enabledFeatures;
}

public static BWGWorldGenConfig getOrCreateConfigFromDisk() {
BWGWorldGenConfig defaultWorldGenConfig = createDefault();

Expand All @@ -80,7 +93,7 @@ public static BWGWorldGenConfig getOrCreateConfigFromDisk() {
temporary.putAll(defaultWorldGenConfig.enabledBiomes);
temporary.putAll(config.enabledBiomes);

BWGWorldGenConfig toCreate = new BWGWorldGenConfig(temporary, config.regionWeight, config.vanillaAdditions);
BWGWorldGenConfig toCreate = new BWGWorldGenConfig(temporary, config.regionWeight, config.vanillaAdditions, config.vanillaFeatures);

createDefaultFile(toCreate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.potionstudios.biomeswevegone.BiomesWeveGone;
import net.potionstudios.biomeswevegone.config.configs.BWGWorldGenConfig;
import net.potionstudios.biomeswevegone.world.level.levelgen.feature.placed.BWGOverworldTreePlacedFeatures;
import net.potionstudios.biomeswevegone.world.level.levelgen.feature.placed.BWGVanillaPlacedFeatures;

Expand All @@ -21,8 +22,8 @@ public class BWGBiomeModifiers {
public static final Map<ResourceLocation, BWGBiomeModifier> BIOME_MODIFIERS_FACTORIES = new Reference2ObjectOpenHashMap<>();

@SafeVarargs
private static void registerModifierVegetalDecoration(String id, ResourceKey<PlacedFeature> feature, ResourceKey<Biome>... biomes) {
BIOME_MODIFIERS_FACTORIES.put(BiomesWeveGone.id(id), new BWGBiomeModifier(feature, GenerationStep.Decoration.VEGETAL_DECORATION, biomes));
private static void registerModifierVegetalDecoration(String id, ResourceKey<PlacedFeature> feature, Map<ResourceKey<PlacedFeature>, Boolean> map, ResourceKey<Biome>... biomes) {
BIOME_MODIFIERS_FACTORIES.put(BiomesWeveGone.id(id), new BWGBiomeModifier(feature, GenerationStep.Decoration.VEGETAL_DECORATION, map.get(feature), biomes));
}

/**
Expand All @@ -31,19 +32,20 @@ private static void registerModifierVegetalDecoration(String id, ResourceKey<Pla
* @param step The generation step to add the feature to
* @param biomes The biomes to add the feature to
*/
public record BWGBiomeModifier(ResourceKey<PlacedFeature> feature, GenerationStep.Decoration step, ResourceKey<Biome>... biomes) {
public record BWGBiomeModifier(ResourceKey<PlacedFeature> feature, GenerationStep.Decoration step, Boolean enabled, ResourceKey<Biome>... biomes) {
@SafeVarargs
public BWGBiomeModifier {}
}

public static void init() {
BiomesWeveGone.LOGGER.info("Creating and Registering BWG Biome Modifiers for Vanilla Biomes");
registerModifierVegetalDecoration("vanilla/flower_default", BWGVanillaPlacedFeatures.FLOWER_DEFAULT, Biomes.OLD_GROWTH_PINE_TAIGA, Biomes.OLD_GROWTH_SPRUCE_TAIGA, Biomes.WINDSWEPT_HILLS, Biomes.WINDSWEPT_GRAVELLY_HILLS, Biomes.WINDSWEPT_FOREST, Biomes.DESERT, Biomes.SNOWY_PLAINS, Biomes.ICE_SPIKES,
Map<ResourceKey<PlacedFeature>, Boolean> map = BWGWorldGenConfig.INSTANCE.get().vanillaFeatures();
registerModifierVegetalDecoration("vanilla/flower_default", BWGVanillaPlacedFeatures.FLOWER_DEFAULT, map, Biomes.OLD_GROWTH_PINE_TAIGA, Biomes.OLD_GROWTH_SPRUCE_TAIGA, Biomes.WINDSWEPT_HILLS, Biomes.WINDSWEPT_GRAVELLY_HILLS, Biomes.WINDSWEPT_FOREST, Biomes.DESERT, Biomes.SNOWY_PLAINS, Biomes.ICE_SPIKES,
Biomes.WINDSWEPT_SAVANNA, Biomes.FOREST, Biomes.OLD_GROWTH_BIRCH_FOREST, Biomes.BIRCH_FOREST, Biomes.TAIGA, Biomes.SNOWY_TAIGA, Biomes.DARK_FOREST);
registerModifierVegetalDecoration("vanilla/flower_warm", BWGVanillaPlacedFeatures.FLOWER_WARM, Biomes.SPARSE_JUNGLE, Biomes.JUNGLE, Biomes.BAMBOO_JUNGLE, Biomes.SAVANNA, Biomes.SAVANNA_PLATEAU);
registerModifierVegetalDecoration("vanilla/flower_plains", BWGVanillaPlacedFeatures.FLOWER_PLAINS, Biomes.PLAINS, Biomes.SUNFLOWER_PLAINS);
registerModifierVegetalDecoration("vanilla/forest_flowers", BWGVanillaPlacedFeatures.FOREST_FLOWERS, Biomes.FOREST, Biomes.DARK_FOREST);
registerModifierVegetalDecoration("vanilla/beach/palm_trees", BWGOverworldTreePlacedFeatures.PALM_TREES, Biomes.BEACH);
registerModifierVegetalDecoration("vanilla/flower_warm", BWGVanillaPlacedFeatures.FLOWER_WARM, map, Biomes.SPARSE_JUNGLE, Biomes.JUNGLE, Biomes.BAMBOO_JUNGLE, Biomes.SAVANNA, Biomes.SAVANNA_PLATEAU);
registerModifierVegetalDecoration("vanilla/flower_plains", BWGVanillaPlacedFeatures.FLOWER_PLAINS, map, Biomes.PLAINS, Biomes.SUNFLOWER_PLAINS);
registerModifierVegetalDecoration("vanilla/forest_flowers", BWGVanillaPlacedFeatures.FOREST_FLOWERS, map, Biomes.FOREST, Biomes.DARK_FOREST);
registerModifierVegetalDecoration("vanilla/beach/palm_trees", BWGOverworldTreePlacedFeatures.PALM_TREES, map,Biomes.BEACH);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class BWGVanillaPlacedFeatures {
)
);

public static final ResourceKey<PlacedFeature> FLOWER_WARM = PlacedFeaturesUtil.createPlacedFeature("vanilla/flower_default",
public static final ResourceKey<PlacedFeature> FLOWER_WARM = PlacedFeaturesUtil.createPlacedFeature("vanilla/flower_warm",
BWGVanillaConfiguredFeatures.FLOWER_DEFAULT,
() -> List.of(
RarityFilter.onAverageOnceEvery(16),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ private static void registerFuels() {
private static void registerBiomeModifiers() {
if (BWGWorldGenConfig.INSTANCE.get().vanillaAdditions()) {
BWGBiomeModifiers.init();
BWGBiomeModifiers.BIOME_MODIFIERS_FACTORIES.forEach((id, modifier) -> BiomeModifications.addFeature(BiomeSelectors.includeByKey(modifier.biomes()), modifier.step(), modifier.feature()));
BWGBiomeModifiers.BIOME_MODIFIERS_FACTORIES.values().stream().filter(BWGBiomeModifiers.BWGBiomeModifier::enabled).forEach((modifier) ->
BiomeModifications.addFeature(BiomeSelectors.includeByKey(modifier.biomes()), modifier.step(), modifier.feature()));
}
}

Expand Down

0 comments on commit cc92bf5

Please sign in to comment.