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:28] 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 329: Line 329:
     // Our constructor doesn't have any arguments, so we create a unit codec that returns the singleton instance     // Our constructor doesn't have any arguments, so we create a unit codec that returns the singleton instance
     public static final Codec<RichTreeDecorator> CODEC = Codec.unit(() -> INSTANCE);     public static final Codec<RichTreeDecorator> CODEC = Codec.unit(() -> INSTANCE);
 +    
 +    private RichTreeDecorator() {}
  
     @Override     @Override
Line 336: Line 338:
  
     @Override     @Override
-    public void generate(TestableWorld world, BiConsumer<BlockPos, BlockState> replacer, Random random, List<BlockPos> logPositions, List<BlockPos> leavesPositions) {+    public void generate(TreeDecorator.Generator generator) {
         // Iterate through block positions         // Iterate through block positions
-        for (BlockPos logPosition : logPositions) {+        generator.getLogPositions().forEach(pos -> { 
 +            Random random = generator.getRandom();
             // Pick a value from 0 (inclusive) to 4 (exclusive) and if it's 0, continue             // Pick a value from 0 (inclusive) to 4 (exclusive) and if it's 0, continue
             // This is the chance for spawning the gold block             // This is the chance for spawning the gold block
Line 359: Line 362:
                 replacer.accept(targetPosition, Blocks.GOLD_BLOCK.getDefaultState());                 replacer.accept(targetPosition, Blocks.GOLD_BLOCK.getDefaultState());
             }             }
-        }+        });
     }     }
 } }
Line 368: 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 385: 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 430: Line 418:
 <code java> <code java>
 [...] [...]
-.dirtProvider(new SimpleBlockStateProvider(Blocks.IRON_BLOCK.getDefaultState()))+.dirtProvider(BlockStateProvider.of(Blocks.IRON_BLOCK))
 [...] [...]
 </code> </code>
tutorial/trees.1662838115.txt.gz · Last modified: 2022/09/10 19:28 by nexus-dino