User Tools

Site Tools


tutorial:features

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
Next revisionBoth sides next revision
tutorial:features [2020/04/23 18:53] – [Adding a Feature to a Biome] Update feature configuration 2xsaikotutorial:features [2020/08/11 09:27] – Updated code snippets to work with newer version of fabric dysnomian
Line 7: Line 7:
 public class StoneSpiralFeature extends Feature<DefaultFeatureConfig> { public class StoneSpiralFeature extends Feature<DefaultFeatureConfig> {
  
-    public StoneSpiralFeature(Function<Dynamic<?>, ? extends DefaultFeatureConfig> config) {+    public StoneSpiralFeature(Codec<DefaultFeatureConfig> config) {
         super(config);         super(config);
     }     }
  
     @Override     @Override
-    public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {+    public boolean generate(ServerWorldAccess world, StructureAccessor accessor, ChunkGenerator generator, Random random, BlockPos pos, DefaultFeatureConfig config) {
         BlockPos topPos = world.getTopPosition(Heightmap.Type.WORLD_SURFACE, pos);         BlockPos topPos = world.getTopPosition(Heightmap.Type.WORLD_SURFACE, pos);
         Direction offset = Direction.NORTH;         Direction offset = Direction.NORTH;
Line 26: Line 26:
 </code> </code>
  
-The constructor takes in a ''Function<Dynamic<? extends DefaultFeatureConfig>>'', which is a factory for data fixer config instances. You can pass in ''DefaultFeatureConfig::deserialize'' for default config features, either directly in the super call or when you instantiate the feature.+The ''Feature<DefaultFeatureConfig>'' constructor takes in a ''Codec<DefaultFeatureConfig>''. You can pass in ''DefaultFeatureConfig.CODEC'' for default config features, either directly in the super call in the constructor or when you instantiate the feature.
  
-`generateis called when the chunk decides to generate the feature. If the feature is configured to spawn every chunk, this would be called for each chunk being generated as well. In the case of the feature being configured to spawn at a certain rate per biome, `generatewould only be called in instances where the world wants to spawn the structure. +''generate'' is called when the chunk decides to generate the feature. If the feature is configured to spawn every chunk, this would be called for each chunk being generated as well. In the case of the feature being configured to spawn at a certain rate per biome, ''generate'' would only be called in instances where the world wants to spawn the structure. 
  
 In our implementation, we'll build a simple 16-block tall spiral of stone starting at the top block in the world: In our implementation, we'll build a simple 16-block tall spiral of stone starting at the top block in the world:
Line 34: Line 34:
 <code java> <code java>
 @Override @Override
-public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {+public boolean generate(WorldAccess world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
     BlockPos topPos = world.getTopPosition(Heightmap.Type.WORLD_SURFACE, pos);     BlockPos topPos = world.getTopPosition(Heightmap.Type.WORLD_SURFACE, pos);
     Direction offset = Direction.NORTH;     Direction offset = Direction.NORTH;
Line 50: Line 50:
 Features can be registered like most other content in the game, and there aren't any special builders or mechanics you'll have to worry about.  Features can be registered like most other content in the game, and there aren't any special builders or mechanics you'll have to worry about. 
 <code java> <code java>
-private static final Feature<DefaultFeatureConfig> LAVA_HOLE = Registry.register(+private static final Feature<DefaultFeatureConfig> STONE_SPIRAL = Registry.register(
  Registry.FEATURE,  Registry.FEATURE,
  new Identifier("tutorial", "stone_spiral"),  new Identifier("tutorial", "stone_spiral"),
- new StoneSpiralFeature(DefaultFeatureConfig::deserialize)+ new StoneSpiralFeature(DefaultFeatureConfig.CODEC)
 ); );
 </code> </code>
Line 62: Line 62:
 We can iterate over ''Registry.BIOME'' to add our Feature to every Biome. We can iterate over ''Registry.BIOME'' to add our Feature to every Biome.
 <code java> <code java>
-Registry.BIOME.forEach(biome -> biome.addFeature( +Registry.BIOME.forEach(biome -> biome.addFeature(GenerationStep.Feature.RAW_GENERATION, STONE_SPIRAL 
-        GenerationStep.Feature.RAW_GENERATION, + .configure(new DefaultFeatureConfig()) 
- LAVA_HOLE.configure(new DefaultFeatureConfig()) + .createDecoratedFeature(Decorator.CHANCE_HEIGHTMAP.configure(new ChanceDecoratorConfig(100))) 
- .createDecoratedFeature(Decorator.CHANCE_HEIGHTMAP.configure(new ChanceDecoratorConfig(100))); + ));
-));+
 </code> </code>
  
tutorial/features.txt · Last modified: 2023/12/18 01:19 by solidblock