Advertisement
jayhillx

MysticFeatures [1.19.2]

May 30th, 2023
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.67 KB | None | 0 0
  1. package com.mysticsbiomes.core.init;
  2.  
  3. import com.mysticsbiomes.common.block.StrawberryBushBlock;
  4. import com.mysticsbiomes.core.MysticsBiomes;
  5. import net.minecraft.core.Holder;
  6. import net.minecraft.core.Registry;
  7. import net.minecraft.data.worldgen.features.FeatureUtils;
  8. import net.minecraft.data.worldgen.placement.PlacementUtils;
  9. import net.minecraft.data.worldgen.placement.VegetationPlacements;
  10. import net.minecraft.util.random.SimpleWeightedRandomList;
  11. import net.minecraft.util.valueproviders.ConstantInt;
  12. import net.minecraft.util.valueproviders.UniformInt;
  13. import net.minecraft.world.level.block.Block;
  14. import net.minecraft.world.level.block.Blocks;
  15. import net.minecraft.world.level.block.state.BlockState;
  16. import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
  17. import net.minecraft.world.level.levelgen.feature.Feature;
  18. import net.minecraft.world.level.levelgen.feature.configurations.*;
  19. import net.minecraft.world.level.levelgen.feature.featuresize.TwoLayersFeatureSize;
  20. import net.minecraft.world.level.levelgen.feature.foliageplacers.RandomSpreadFoliagePlacer;
  21. import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
  22. import net.minecraft.world.level.levelgen.feature.stateproviders.WeightedStateProvider;
  23. import net.minecraft.world.level.levelgen.feature.trunkplacers.BendingTrunkPlacer;
  24. import net.minecraft.world.level.levelgen.feature.trunkplacers.FancyTrunkPlacer;
  25. import net.minecraft.world.level.levelgen.feature.trunkplacers.StraightTrunkPlacer;
  26. import net.minecraft.world.level.levelgen.placement.*;
  27. import net.minecraftforge.registries.DeferredRegister;
  28. import net.minecraftforge.registries.RegistryObject;
  29.  
  30. import java.util.List;
  31. import java.util.function.Supplier;
  32.  
  33. import static net.minecraftforge.registries.DeferredRegister.create;
  34.  
  35. public class MysticFeatures {
  36.     public static final DeferredRegister<ConfiguredFeature<?, ?>> CONFIGURED_FEATURES = create(Registry.CONFIGURED_FEATURE_REGISTRY, MysticsBiomes.modId);
  37.     public static final DeferredRegister<PlacedFeature> PLACED_FEATURES = create(Registry.PLACED_FEATURE_REGISTRY, MysticsBiomes.modId);
  38.  
  39.     public static class Configured {
  40.         public static final RegistryObject<ConfiguredFeature<TreeConfiguration, ?>> JACARANDA_TREE = register("jacaranda_tree", Feature.TREE, () -> (new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(MysticBlocks.JACARANDA_LOG.get()), new BendingTrunkPlacer(4, 2, 0, 2, UniformInt.of(1, 1)), new WeightedStateProvider(SimpleWeightedRandomList.<BlockState>builder().add(MysticBlocks.JACARANDA_BLOSSOMS.get().defaultBlockState(), 2).add(MysticBlocks.JACARANDA_LEAVES.get().defaultBlockState(), 3)), new RandomSpreadFoliagePlacer(ConstantInt.of(3), ConstantInt.of(0), ConstantInt.of(3), 32), new TwoLayersFeatureSize(1, 0, 1))).build());
  41.         public static final RegistryObject<ConfiguredFeature<RandomPatchConfiguration, ?>> LAVENDER = register("lavender", Feature.RANDOM_PATCH, () -> (new RandomPatchConfiguration(128, 9, 7, PlacementUtils.onlyWhenEmpty(Feature.SIMPLE_BLOCK, new SimpleBlockConfiguration(BlockStateProvider.simple(MysticBlocks.LAVENDER.get()))))));
  42.         public static final RegistryObject<ConfiguredFeature<RandomPatchConfiguration, ?>> GRASS = register("grass", Feature.RANDOM_PATCH, () -> (new RandomPatchConfiguration(222, 7, 7, PlacementUtils.onlyWhenEmpty(Feature.SIMPLE_BLOCK, new SimpleBlockConfiguration(BlockStateProvider.simple(Blocks.GRASS))))));
  43.         public static final RegistryObject<ConfiguredFeature<RandomPatchConfiguration, ?>> LIGHT_GRASS = register("light_grass", Feature.RANDOM_PATCH, () -> FeatureUtils.simplePatchConfiguration(Feature.SIMPLE_BLOCK, new SimpleBlockConfiguration(BlockStateProvider.simple(Blocks.GRASS)), List.of(Blocks.GRASS_BLOCK)));
  44.  
  45.         public static final RegistryObject<ConfiguredFeature<TreeConfiguration, ?>> PINK_CHERRY_TREE = register("pink_cherry_tree", Feature.TREE, () -> (createBushyFoliage(MysticBlocks.CHERRY_LOG.get(), MysticBlocks.PINK_CHERRY_BLOSSOMS.get(), 11, 0, 112)).build());
  46.         public static final RegistryObject<ConfiguredFeature<TreeConfiguration, ?>> LARGE_PINK_CHERRY_TREE = register("large_pink_cherry_tree", Feature.TREE, () -> (createBushyFoliage(MysticBlocks.CHERRY_LOG.get(), MysticBlocks.PINK_CHERRY_BLOSSOMS.get(), 13, 3, 128)).build());
  47.         public static final RegistryObject<ConfiguredFeature<TreeConfiguration, ?>> WHITE_CHERRY_TREE = register("white_cherry_tree", Feature.TREE, () -> (createBushyFoliage(MysticBlocks.CHERRY_LOG.get(), MysticBlocks.WHITE_CHERRY_BLOSSOMS.get(), 11, 0, 112)).build());
  48.         public static final RegistryObject<ConfiguredFeature<TreeConfiguration, ?>> LARGE_WHITE_CHERRY_TREE = register("large_white_cherry_tree", Feature.TREE, () -> (createBushyFoliage(MysticBlocks.CHERRY_LOG.get(), MysticBlocks.WHITE_CHERRY_BLOSSOMS.get(), 13, 3, 112)).build());
  49.         public static final RegistryObject<ConfiguredFeature<TreeConfiguration, ?>> PEONY_BUSH = register("peony_bush", Feature.TREE, () -> (new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(Blocks.OAK_LOG), new StraightTrunkPlacer(1, 0, 0), new WeightedStateProvider(SimpleWeightedRandomList.<BlockState>builder().add(MysticBlocks.BUDDING_PEONY_LEAVES.get().defaultBlockState(), 3).add(MysticBlocks.PEONY_LEAVES.get().defaultBlockState(), 3)), new RandomSpreadFoliagePlacer(ConstantInt.of(3), ConstantInt.of(0), ConstantInt.of(2), 72), new TwoLayersFeatureSize(0, 0, 0))).build());
  50.  
  51.         public static final RegistryObject<ConfiguredFeature<RandomPatchConfiguration, ?>> BAMBOO = register("bamboo", Feature.RANDOM_PATCH, () -> FeatureUtils.simplePatchConfiguration(Feature.BAMBOO, new ProbabilityFeatureConfiguration(0.7F), List.of(Blocks.GRASS_BLOCK, Blocks.PODZOL), 96));
  52.  
  53.         public static final RegistryObject<ConfiguredFeature<RandomPatchConfiguration, ?>> PINK_CHERRY_TREE_PLACED = register("pink_cherry_tree_placed", Feature.RANDOM_PATCH, () -> FeatureUtils.simplePatchConfiguration(Feature.TREE, PINK_CHERRY_TREE.get().config(), List.of(Blocks.GRASS_BLOCK), 1));
  54.         public static final RegistryObject<ConfiguredFeature<RandomPatchConfiguration, ?>> LARGE_PINK_CHERRY_TREE_PLACED = register("large_pink_cherry_tree_placed", Feature.RANDOM_PATCH, () -> FeatureUtils.simplePatchConfiguration(Feature.TREE, LARGE_PINK_CHERRY_TREE.get().config(), List.of(Blocks.GRASS_BLOCK), 1));
  55.         public static final RegistryObject<ConfiguredFeature<RandomPatchConfiguration, ?>> WHITE_CHERRY_TREE_PLACED = register("white_cherry_tree_placed", Feature.RANDOM_PATCH, () -> FeatureUtils.simplePatchConfiguration(Feature.TREE, WHITE_CHERRY_TREE.get().config(), List.of(Blocks.GRASS_BLOCK), 1));
  56.         public static final RegistryObject<ConfiguredFeature<RandomPatchConfiguration, ?>> LARGE_WHITE_CHERRY_TREE_PLACED = register("large_white_cherry_tree_placed", Feature.RANDOM_PATCH, () -> FeatureUtils.simplePatchConfiguration(Feature.TREE, LARGE_WHITE_CHERRY_TREE.get().config(), List.of(Blocks.GRASS_BLOCK), 1));
  57.         public static final RegistryObject<ConfiguredFeature<RandomPatchConfiguration, ?>> PEONY_BUSH_PLACED = register("peony_bush_placed", Feature.RANDOM_PATCH, () -> FeatureUtils.simplePatchConfiguration(Feature.TREE, PEONY_BUSH.get().config(), List.of(Blocks.GRASS_BLOCK), 1));
  58.  
  59.         public static final RegistryObject<ConfiguredFeature<TreeConfiguration, ?>> STRAWBERRY_TREE = register("strawberry_tree", Feature.TREE, () -> (createBushyFoliage(MysticBlocks.STRAWBERRY_LOG.get(), MysticBlocks.STRAWBERRY_BLOSSOMS.get(), 8, 0, 82)).build());
  60.         public static final RegistryObject<ConfiguredFeature<RandomPatchConfiguration, ?>> STRAWBERRY_BUSH = register("strawberry_bush", Feature.RANDOM_PATCH, () -> (new RandomPatchConfiguration(400, 9, 2, PlacementUtils.onlyWhenEmpty(Feature.SIMPLE_BLOCK, new SimpleBlockConfiguration(BlockStateProvider.simple(MysticBlocks.STRAWBERRY_BUSH.get().defaultBlockState().setValue(StrawberryBushBlock.AGE, 5)))))));
  61.         public static final RegistryObject<ConfiguredFeature<RandomPatchConfiguration, ?>> PINK_TULIP = register("pink_tulip", Feature.RANDOM_PATCH, () -> (new RandomPatchConfiguration(64, 7, 2, PlacementUtils.onlyWhenEmpty(Feature.SIMPLE_BLOCK, new SimpleBlockConfiguration(BlockStateProvider.simple(Blocks.PINK_TULIP))))));
  62.         public static final RegistryObject<ConfiguredFeature<RandomPatchConfiguration, ?>> WHITE_TULIP = register("white_tulip", Feature.RANDOM_PATCH, () -> (new RandomPatchConfiguration(64, 7, 2, PlacementUtils.onlyWhenEmpty(Feature.SIMPLE_BLOCK, new SimpleBlockConfiguration(BlockStateProvider.simple(Blocks.WHITE_TULIP))))));
  63.  
  64.         private static TreeConfiguration.TreeConfigurationBuilder createBushyFoliage(Block log, Block leaves, int baseHeight, int heightRandomA, int foliageAttempts) {
  65.             return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(log), new FancyTrunkPlacer(baseHeight, heightRandomA, 0), BlockStateProvider.simple(leaves), new RandomSpreadFoliagePlacer(ConstantInt.of(3), ConstantInt.of(0), ConstantInt.of(3), foliageAttempts), new TwoLayersFeatureSize(1, 0, 1));
  66.         }
  67.  
  68.         public static <FC extends FeatureConfiguration, F extends Feature<FC>> RegistryObject<ConfiguredFeature<FC, ?>> register(String name, F feature, Supplier<FC> configSupplier) {
  69.             return CONFIGURED_FEATURES.register(name, () -> new ConfiguredFeature<>(feature, configSupplier.get()));
  70.         }
  71.     }
  72.  
  73.     /** What's placed in the world generation. */
  74.     public static class Placed {
  75.         public static final RegistryObject<PlacedFeature> TREES_JACARANDA = register("trees_jacaranda", Configured.JACARANDA_TREE.getHolder().orElseThrow(), VegetationPlacements.treePlacement(RarityFilter.onAverageOnceEvery(3), Blocks.OAK_SAPLING));
  76.         public static final RegistryObject<PlacedFeature> FLOWERS_LAVENDER = register("flowers_lavender", Configured.LAVENDER.getHolder().orElseThrow(), VegetationPlacements.worldSurfaceSquaredWithCount(48));
  77.         public static final RegistryObject<PlacedFeature> FOLIAGE_GRASS = register("foliage_grass", Configured.GRASS.getHolder().orElseThrow(), VegetationPlacements.worldSurfaceSquaredWithCount(128));
  78.         public static final RegistryObject<PlacedFeature> FOLIAGE_LIGHT_GRASS = register("foliage_light_grass", Configured.LIGHT_GRASS.getHolder().orElseThrow(), VegetationPlacements.worldSurfaceSquaredWithCount(16));
  79.  
  80.         public static final RegistryObject<PlacedFeature> TREES_PINK_CHERRY = register("trees_pink_cherry", Configured.PINK_CHERRY_TREE_PLACED.getHolder().orElseThrow(), VegetationPlacements.treePlacement(NoiseBasedCountPlacement.of(8, 0.4D, 1), Blocks.OAK_SAPLING));
  81.         public static final RegistryObject<PlacedFeature> TREES_LARGE_PINK_CHERRY = register("trees_large_pink_cherry", Configured.LARGE_PINK_CHERRY_TREE_PLACED.getHolder().orElseThrow(), VegetationPlacements.treePlacement(NoiseBasedCountPlacement.of(6, 0.4D, 1), Blocks.OAK_SAPLING));
  82.         public static final RegistryObject<PlacedFeature> TREES_WHITE_CHERRY = register("trees_white_cherry", Configured.WHITE_CHERRY_TREE_PLACED.getHolder().orElseThrow(), VegetationPlacements.treePlacement(NoiseBasedCountPlacement.of(8, 0.4D, 1), Blocks.OAK_SAPLING));
  83.         public static final RegistryObject<PlacedFeature> TREES_LARGE_WHITE_CHERRY = register("trees_large_white_cherry", Configured.LARGE_WHITE_CHERRY_TREE_PLACED.getHolder().orElseThrow(), VegetationPlacements.treePlacement(NoiseBasedCountPlacement.of(6, 0.4D, 1), Blocks.OAK_SAPLING));
  84.         public static final RegistryObject<PlacedFeature> FOLIAGE_PEONY_BUSH = register("foliage_peony_bush", Configured.PEONY_BUSH_PLACED.getHolder().orElseThrow(), VegetationPlacements.treePlacement(NoiseBasedCountPlacement.of(80, 0.4D, 1), Blocks.OAK_SAPLING));
  85.  
  86.         public static final RegistryObject<PlacedFeature> FOLIAGE_BAMBOO = register("foliage_bamboo", Configured.BAMBOO.getHolder().orElseThrow(), NoiseBasedCountPlacement.of(158, 80.0D, 0.3D), RarityFilter.onAverageOnceEvery(28), InSquarePlacement.spread(), PlacementUtils.HEIGHTMAP_WORLD_SURFACE, BiomeFilter.biome());
  87.  
  88.         public static final RegistryObject<PlacedFeature> TREES_STRAWBERRY = register("trees_strawberry", Configured.STRAWBERRY_TREE.getHolder().orElseThrow(), VegetationPlacements.treePlacement(RarityFilter.onAverageOnceEvery(3), Blocks.OAK_SAPLING));
  89.  
  90.         public static final RegistryObject<PlacedFeature> FOLIAGE_STRAWBERRY_BUSH = register("foliage_strawberry_bush", Configured.STRAWBERRY_BUSH.getHolder().orElseThrow(), RarityFilter.onAverageOnceEvery(1), InSquarePlacement.spread(), PlacementUtils.HEIGHTMAP_WORLD_SURFACE, BiomeFilter.biome());
  91.         public static final RegistryObject<PlacedFeature> FLOWERS_PINK_TULIP = register("foliage_pink_tulip", Configured.PINK_TULIP.getHolder().orElseThrow(), RarityFilter.onAverageOnceEvery(1), InSquarePlacement.spread(), PlacementUtils.HEIGHTMAP_WORLD_SURFACE, BiomeFilter.biome());
  92.         public static final RegistryObject<PlacedFeature> FLOWERS_WHITE_TULIP = register("foliage_white_tulip", Configured.WHITE_TULIP.getHolder().orElseThrow(), RarityFilter.onAverageOnceEvery(1), InSquarePlacement.spread(), PlacementUtils.HEIGHTMAP_WORLD_SURFACE, BiomeFilter.biome());
  93.  
  94.         // InSquarePlacement.spread(), PlacementUtils.HEIGHTMAP_WORLD_SURFACE, BiomeFilter.biome()
  95.  
  96.         public static RegistryObject<PlacedFeature> register(String name, Holder<? extends ConfiguredFeature<?, ?>> feature, List<PlacementModifier> modifiers) {
  97.             return PLACED_FEATURES.register(name, () -> new PlacedFeature(Holder.hackyErase(feature), List.copyOf(modifiers)));
  98.         }
  99.  
  100.         public static RegistryObject<PlacedFeature> register(String name, Holder<? extends ConfiguredFeature<?, ?>> feature, PlacementModifier... modifiers) {
  101.             return register(name, feature, List.of(modifiers));
  102.         }
  103.     }
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement