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
Last revisionBoth sides next revision
tutorial:trees [2022/09/10 19:34] – [Creating the TreeDecorator] nexus-dinotutorial:trees [2022/10/31 02:48] – Add missing namespaces daomephsta
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 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 388: Line 388:
 <code java> <code java>
 public class RichSaplingGenerator extends SaplingGenerator { public class RichSaplingGenerator extends SaplingGenerator {
-    private final ConfiguredFeature<TreeFeatureConfig, ?> feature; 
- 
-    public RichSaplingGenerator(ConfiguredFeature<?, ?> feature) { 
-        this.feature = (ConfiguredFeature<TreeFeatureConfig, ?>) feature; 
-    } 
- 
     @Nullable     @Nullable
     @Override     @Override
-    protected ConfiguredFeature<TreeFeatureConfig, ?> getTreeFeature(Random random, boolean bees) {+    protected RegistryEntry<ConfiguredFeature<TreeFeatureConfig, ?>> getTreeFeature(Random random, boolean bees) {
         int chance = random.nextInt(100);         int chance = random.nextInt(100);
                  
         // 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 433: Line 418:
 <code java> <code java>
 [...] [...]
-.dirtProvider(new SimpleBlockStateProvider(Blocks.IRON_BLOCK.getDefaultState()))+.dirtProvider(BlockStateProvider.of(Blocks.IRON_BLOCK))
 [...] [...]
 </code> </code>
tutorial/trees.txt · Last modified: 2022/12/21 01:40 by haykam