diff --git a/src/main/java/dev/micle/wildflowers_backport/worldgen/ModConfiguredFeatures.java b/src/main/java/dev/micle/wildflowers_backport/worldgen/ModConfiguredFeatures.java index a8c60cf..a3d4c0e 100644 --- a/src/main/java/dev/micle/wildflowers_backport/worldgen/ModConfiguredFeatures.java +++ b/src/main/java/dev/micle/wildflowers_backport/worldgen/ModConfiguredFeatures.java @@ -1,21 +1,52 @@ package dev.micle.wildflowers_backport.worldgen; import dev.micle.wildflowers_backport.WildflowersBackport; +import dev.micle.wildflowers_backport.block.FlowerBedBlock; +import dev.micle.wildflowers_backport.block.ModBlocks; +import net.minecraft.core.Direction; import net.minecraft.core.registries.Registries; import net.minecraft.data.worldgen.BootstapContext; +import net.minecraft.data.worldgen.placement.PlacementUtils; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.random.SimpleWeightedRandomList; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; +import net.minecraft.world.level.levelgen.feature.configurations.RandomPatchConfiguration; +import net.minecraft.world.level.levelgen.feature.configurations.SimpleBlockConfiguration; +import net.minecraft.world.level.levelgen.feature.stateproviders.WeightedStateProvider; public class ModConfiguredFeatures { public static final ResourceKey> WILDFLOWERS_MEADOW = registerKey("wildflowers_meadow"); - public static final ResourceKey> WILDFLOWERS_BIRCH_FOREST = registerKey("wildflowers_birch_forest"); public static void bootstrap(BootstapContext> context) { + register(context, WILDFLOWERS_MEADOW, Feature.FLOWER, new RandomPatchConfiguration( + 8, + 6, + 2, + PlacementUtils.onlyWhenEmpty( + Feature.SIMPLE_BLOCK, + new SimpleBlockConfiguration( + new WeightedStateProvider(createAllPossibleFlowerBedBlockEntries(ModBlocks.WILDFLOWERS.get())) + ) + ) + )); + register(context, WILDFLOWERS_BIRCH_FOREST, Feature.FLOWER, new RandomPatchConfiguration( + 64, + 6, + 2, + PlacementUtils.onlyWhenEmpty( + Feature.SIMPLE_BLOCK, + new SimpleBlockConfiguration( + new WeightedStateProvider(createAllPossibleFlowerBedBlockEntries(ModBlocks.WILDFLOWERS.get())) + ) + ) + )); } public static ResourceKey> registerKey(String name) { @@ -28,4 +59,16 @@ public class ModConfiguredFeatures { ) { context.register(key, new ConfiguredFeature<>(feature, configuration)); } + + private static SimpleWeightedRandomList createAllPossibleFlowerBedBlockEntries(Block block) { + SimpleWeightedRandomList.Builder builder = SimpleWeightedRandomList.builder(); + + for (Direction direction : Direction.Plane.HORIZONTAL) { + for (int i = FlowerBedBlock.MIN_SEGMENT; i <= FlowerBedBlock.MAX_SEGMENT; i++) { + builder.add(block.defaultBlockState().setValue(FlowerBedBlock.FACING, direction).setValue(FlowerBedBlock.AMOUNT, i), 1); + } + } + + return builder.build(); + } }