User Tools

Site Tools


tutorial:trees

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:trees [2022/09/10 19:35] – [Creating an advanced SaplingGenerator] nexus-dinotutorial:trees [2022/12/21 01:40] (current) – 1.19.3 haykam
Line 27: Line 27:
  
 <code java> <code java>
-public static final RegistryEntry<ConfiguredFeature<TreeFeatureConfig, ?>> TREE_RICH = ConfiguredFeatures.register("tree_rich", Feature.TREE+public static final RegistryEntry<ConfiguredFeature<TreeFeatureConfig, ?>> TREE_RICH = ConfiguredFeatures.register("tutorial:tree_rich", Feature.TREE
   // Configure the feature using the builder   // Configure the feature using the builder
   new TreeFeatureConfig.Builder(   new TreeFeatureConfig.Builder(
Line 76: Line 76:
  
 public static void register() { public static void register() {
-  Registry.register(Registry.BLOCK, new Identifier("tutorial", "rich_sapling"), RICH_SAPLING); +  Registry.register(Registries.BLOCK, new Identifier("tutorial", "rich_sapling"), RICH_SAPLING); 
-  Registry.register(Registry.ITEM, new Identifier("tutorial", "rich_sapling"), new BlockItem(RICH_SAPLING, new FabricItemSettings().group(ItemGroup.MISC)));+  Registry.register(Registries.ITEM, new Identifier("tutorial", "rich_sapling"), new BlockItem(RICH_SAPLING, new FabricItemSettings()));
 } }
  
Line 163: Line 163:
  
 <code java> <code java>
-public static final TrunkPlacerType<RichTrunkPlacer> RICH_TRUNK_PLACER = TrunkPlacerTypeInvoker.callRegister("rich_trunk_placer", RichTrunkPlacer.CODEC);+public static final TrunkPlacerType<RichTrunkPlacer> RICH_TRUNK_PLACER = TrunkPlacerTypeInvoker.callRegister("tutorial:rich_trunk_placer", RichTrunkPlacer.CODEC);
 </code> </code>
  
Line 220: Line 220:
     public static final Codec<RichFoliagePlacer> CODEC = RecordCodecBuilder.create(instance ->     public static final Codec<RichFoliagePlacer> CODEC = RecordCodecBuilder.create(instance ->
         fillFoliagePlacerFields(instance)         fillFoliagePlacerFields(instance)
-        .and(IntProvider.createValidatingCodec(1, 512).fieldOf("foliage_height").forGetter(RichFoliagePlacer::getFoliageHeight)+        .and(IntProvider.createValidatingCodec(1, 512).fieldOf("foliage_height").forGetter(RichFoliagePlacer::getFoliageHeight))
         .apply(instance, RichFoliagePlacer::new));         .apply(instance, RichFoliagePlacer::new));
  
Line 277: Line 277:
  
 <code java> <code java>
-public static final FoliagePlacerType<RichFoliagePlacer> RICH_FOLIAGE_PLACER = FoliagePlacerTypeInvoker.callRegister("rich_foliage_placer", RichFoliagePlacer.CODEC);+public static final FoliagePlacerType<RichFoliagePlacer> RICH_FOLIAGE_PLACER = FoliagePlacerTypeInvoker.callRegister("tutorial:rich_foliage_placer", RichFoliagePlacer.CODEC);
 </code> </code>
  
Line 371: Line 371:
  
 <code java> <code java>
-public static final TreeDecoratorType<RichTreeDecorator> RICH_TREE_DECORATOR = TreeDecoratorTypeInvoker.callRegister("rich_tree_decorator", RichTreeDecorator.CODEC);+public static final TreeDecoratorType<RichTreeDecorator> RICH_TREE_DECORATOR = TreeDecoratorTypeInvoker.callRegister("tutorial:rich_tree_decorator", RichTreeDecorator.CODEC);
 </code> </code>
  
Line 394: Line 394:
                  
         // Each tree has a 10% chance         // Each tree has a 10% chance
-        if (chance < 10) { +        return switch (chance) { 
-            return ConfiguredFeatures.OAK; +          case 10 -> TreeConfiguredFeatures.OAK; 
-        } else if (chance < 20) { +          case 20 -> TreeConfiguredFeatures.BIRCH; 
-            return ConfiguredFeatures.BIRCH; +          case 30 -> TreeConfiguredFeatures.MEGA_SPRUCE
-        } else if (chance < 60) { +          case 40 -> TreeConfiguredFeatures.PINE
-            return ConfiguredFeatures.SPRUCE+          case 50 -> TreeConfiguredFeatures.MEGA_PINE
-        } else if (chance < 40) { +          case 60 -> TreeConfiguredFeatures.MEGA_JUNGLE_TREE
-            return ConfiguredFeatures.MEGA_SPRUCE+          default -> Tutorial.RICH
-        } else if (chance < 50) { +
-            return ConfiguredFeatures.PINE+
-        } else if (chance < 60) { +
-            return ConfiguredFeatures.MEGA_PINE+
-        } else if (chance < 70) { +
-            return ConfiguredFeatures.MEGA_JUNGLE_TREE;+
         }         }
-         +   }
-        // If none of that happened (the random value was between 70 and 100), create the actual tree +
-        return feature; +
-    }+
 } }
 </code> </code>
Line 427: Line 418:
 <code java> <code java>
 [...] [...]
-.dirtProvider(new SimpleBlockStateProvider(Blocks.IRON_BLOCK.getDefaultState()))+.dirtProvider(BlockStateProvider.of(Blocks.IRON_BLOCK))
 [...] [...]
 </code> </code>
tutorial/trees.1662838538.txt.gz · Last modified: 2022/09/10 19:35 by nexus-dino