TurtyWurty

TreeGeneration

Nov 9th, 2021 (edited)
756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.64 KB | None | 0 0
  1. public class TreeGeneration {
  2.  
  3.     public static final List<ConfiguredFeature<?, ?>> OVERWORLD_TREES = new ArrayList<>();
  4.     public static final List<ConfiguredFeature<?, ?>> END_TREES = new ArrayList<>();
  5.     public static final List<ConfiguredFeature<?, ?>> NETHER_TREES = new ArrayList<>();
  6.  
  7.     private static <Config extends FeatureConfiguration> ConfiguredFeature<Config, ?> register(String name,
  8.             ConfiguredFeature<Config, ?> configuredFeature) {
  9.         return Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation(TestMod.MODID, name),
  10.                 configuredFeature);
  11.     }
  12.  
  13.     private static void registerTrees() {
  14.         ConfiguredFeature<?, ?> tree = Feature.TREE
  15.                 .configured(new TreeConfiguration.TreeConfigurationBuilder(
  16.                         new SimpleStateProvider(Blocks.PINK_CONCRETE.defaultBlockState()),
  17.                         new FancyTrunkPlacer(5, 4, 6), new SimpleStateProvider(Blocks.PACKED_ICE.defaultBlockState()),
  18.                         new SimpleStateProvider(Blocks.OAK_SAPLING.defaultBlockState()),
  19.                         new RandomSpreadFoliagePlacer(ConstantInt.of(5), ConstantInt.of(5), ConstantInt.of(5), 7),
  20.                         new TwoLayersFeatureSize(5, 1, 4)).ignoreVines().build())
  21.                 .decorated(Features.Decorators.HEIGHTMAP_WITH_TREE_THRESHOLD_SQUARED)
  22.                 .decorated(FeatureDecorator.COUNT_EXTRA
  23.                         .configured(new FrequencyWithExtraChanceDecoratorConfiguration(10, .1f, 1)))
  24.                 .squared().count(20);
  25.         OVERWORLD_TREES.add(register("funky_tree", tree));
  26.     }
  27.  
  28.     @Mod.EventBusSubscriber(modid = TestMod.MODID, bus = Bus.FORGE)
  29.     public static class ForgeBusSubscriber {
  30.         @SubscribeEvent
  31.         public static void biomeLoading(BiomeLoadingEvent event) {
  32.             final List<Supplier<ConfiguredFeature<?, ?>>> features = event.getGeneration()
  33.                     .getFeatures(Decoration.VEGETAL_DECORATION);
  34.             switch(event.getCategory()) {
  35.                 case NETHER -> TreeGeneration.OVERWORLD_TREES.forEach(tree -> features.add(() -> tree));
  36.                 case THEEND -> TreeGeneration.END_TREES.forEach(tree -> features.add(() -> tree));
  37.                 default -> TreeGeneration.NETHER_TREES.forEach(tree -> features.add(() -> tree));
  38.             }
  39.         }
  40.     }
  41.  
  42.     @Mod.EventBusSubscriber(modid = TestMod.MODID, bus = Bus.MOD)
  43.     public static class ModBusSubscriber {
  44.         @SubscribeEvent
  45.         public static void commonSetup(FMLCommonSetupEvent event) {
  46.             event.enqueueWork(TreeGeneration::registerTrees);
  47.         }
  48.     }
  49. }
Add Comment
Please, Sign In to add comment