tutorial:features
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:features [2020/08/11 09:27] – Updated code snippets to work with newer version of fabric dysnomian | tutorial:features [2020/11/02 13:27] – Use Biome Modification API in Fabric API siglong | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Generating | + | ===== Adding |
- | Rocks, trees, ores, and ponds are all examples of Features. They are simple generation additions to the world which generate depending on how they are configured. In this tutorial, we'll look at generating a simple stone spiral feature in our world randomly. | + | Rocks, trees, ores, and ponds are all examples of features. |
+ | They are simple generation additions to the world which generate depending on how they are configured. | ||
+ | In this tutorial, we'll look at generating a simple stone spiral feature in the plain biomes | ||
- | ==== Creating | + | There are 3 steps that are required to add a feature to a biome. |
- | A simple Feature looks like this: | + | * Create a feature |
- | <code java [enable_line_numbers=" | + | * Configure a feature |
- | public class StoneSpiralFeature extends Feature< | + | * Use [[https:// |
- | public StoneSpiralFeature(Codec< | + | Note that the Biome Modification API is marked as experimental. If the API doesn' |
- | super(config); | + | |
- | } | + | |
- | @Override | + | ==== Creating a feature ==== |
- | public boolean generate(ServerWorldAccess world, StructureAccessor accessor, ChunkGenerator generator, Random random, BlockPos pos, DefaultFeatureConfig config) { | + | A simple Feature looks like this: |
- | BlockPos topPos | + | |
- | Direction offset | + | |
- | for (int y = 1; y < 16; y++) { | + | <code java> |
- | | + | public class StoneSpiralFeature extends Feature< |
- | | + | |
- | } | + | super(config); |
+ | } | ||
- | return true; | + | @Override |
+ | public boolean generate(StructureWorldAccess world, ChunkGenerator generator, Random random, BlockPos pos, | ||
+ | DefaultFeatureConfig config) { | ||
+ | BlockPos topPos = world.getTopPosition(Heightmap.Type.WORLD_SURFACE, | ||
+ | Direction offset = Direction.NORTH; | ||
+ | |||
+ | for (int y = 1; y <= 15; y++) { | ||
+ | offset = offset.rotateYClockwise(); | ||
+ | world.setBlockState(topPos.up(y).offset(offset), | ||
} | } | ||
+ | |||
+ | return true; | ||
+ | } | ||
} | } | ||
</ | </ | ||
- | The '' | + | The '' |
+ | You can pass in '' | ||
- | '' | + | '' |
+ | 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, '' | ||
- | In our implementation, | + | In our implementation, |
+ | |||
+ | 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> | ||
- | @Override | + | public class ExampleMod implements ModInitializer { |
- | public boolean generate(WorldAccess world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, | + | |
- | BlockPos topPos | + | |
- | Direction offset = Direction.NORTH; | + | |
- | for (int y = 1; y < 16; y++) { | + | @Override |
- | | + | public void onInitialize() { |
- | world.setBlockState(topPos.up(y).offset(offset), Blocks.STONE.getDefaultState(), 3); | + | |
- | } | + | } |
- | + | ||
- | return true; | + | |
} | } | ||
</ | </ | ||
- | ==== Registering | + | ==== Configuring |
- | 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. | + | We need to give a configuration to a feature. Make sure to register configured feature as well as feature. |
<code java> | <code java> | ||
- | private | + | public class ExampleMod implements ModInitializer { |
- | Registry.FEATURE, | + | public |
- | new Identifier(" | + | |
- | new StoneSpiralFeature(DefaultFeatureConfig.CODEC) | + | |
- | ); | + | @Override |
+ | public void onInitialize() { | ||
+ | [...] | ||
+ | |||
+ | RegistryKey< | ||
+ | new Identifier(" | ||
+ | | ||
+ | } | ||
+ | } | ||
</ | </ | ||
- | ==== Adding a Feature | + | The Decorator represents how the world chooses to place your feature. |
- | Biome has a method called '' | + | To choose the correct Decorator, check out vanilla features with a similar style to your own. |
+ | The decorator config branches off this; in the case of '' | ||
+ | |||
+ | ==== Adding a configured feature | ||
+ | We use the Biome Modification API. | ||
- | We can iterate over '' | ||
<code java> | <code java> | ||
- | Registry.BIOME.forEach(biome -> biome.addFeature(GenerationStep.Feature.RAW_GENERATION, | + | public class ExampleMod implements ModInitializer { |
- | .configure(new DefaultFeatureConfig()) | + | [...] |
- | .createDecoratedFeature(Decorator.CHANCE_HEIGHTMAP.configure(new ChanceDecoratorConfig(100))) | + | |
- | )); | + | @Override |
+ | public void onInitialize() { | ||
+ | [...] | ||
+ | | ||
+ | } | ||
+ | } | ||
</ | </ | ||
- | The first argument of '' | + | The first argument of '' |
- | The second argument | + | The second argument |
+ | For above-ground houses you may go with '' | ||
- | The Decorator represents how the world chooses to place your Feature. '' | + | === Result |
- | + | ||
- | === Results | + | |
{{https:// | {{https:// | ||
+ |
tutorial/features.txt · Last modified: 2023/12/18 01:19 by solidblock