Implemented both configured features.
This commit is contained in:
@ -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<ConfiguredFeature<?, ?>> WILDFLOWERS_MEADOW = registerKey("wildflowers_meadow");
|
||||
|
||||
public static final ResourceKey<ConfiguredFeature<?, ?>> WILDFLOWERS_BIRCH_FOREST = registerKey("wildflowers_birch_forest");
|
||||
|
||||
public static void bootstrap(BootstapContext<ConfiguredFeature<?, ?>> 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<ConfiguredFeature<?, ?>> registerKey(String name) {
|
||||
@ -28,4 +59,16 @@ public class ModConfiguredFeatures {
|
||||
) {
|
||||
context.register(key, new ConfiguredFeature<>(feature, configuration));
|
||||
}
|
||||
|
||||
private static SimpleWeightedRandomList<BlockState> createAllPossibleFlowerBedBlockEntries(Block block) {
|
||||
SimpleWeightedRandomList.Builder<BlockState> builder = SimpleWeightedRandomList.<BlockState>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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user