tutorial:features
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next 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/09/05 20:01] – 1.16.2 siglong | ||
---|---|---|---|
Line 1: | Line 1: | ||
===== Generating Features in your World ===== | ===== Generating Features in your World ===== | ||
- | 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 a Feature class ==== | + | There are 3 steps that are required to add a feature to a biome. |
+ | * Create a feature | ||
+ | * Configure a feature | ||
+ | * Add a configured feature to a biome | ||
+ | |||
+ | ==== Creating a feature | ||
A simple Feature looks like this: | A simple Feature looks like this: | ||
- | <code java [enable_line_numbers=" | + | |
+ | <code java> | ||
public class StoneSpiralFeature extends Feature< | public class StoneSpiralFeature extends Feature< | ||
+ | public StoneSpiralFeature(Codec< | ||
+ | super(config); | ||
+ | } | ||
- | | + | @Override |
- | super(config); | + | |
- | | + | |
+ | | ||
+ | | ||
- | | + | for (int y = 1; y <= 15; y++) { |
- | public boolean generate(ServerWorldAccess world, StructureAccessor accessor, ChunkGenerator generator, Random random, BlockPos pos, DefaultFeatureConfig config) { | + | offset = offset.rotateYClockwise(); |
- | BlockPos topPos = world.getTopPosition(Heightmap.Type.WORLD_SURFACE, | + | world.setBlockState(topPos.up(y).offset(offset), |
- | Direction offset = Direction.NORTH; | + | |
- | + | ||
- | | + | |
- | offset = offset.rotateYClockwise(); | + | |
- | world.setBlockState(topPos.up(y).offset(offset), | + | |
- | } | + | |
- | + | ||
- | return true; | + | |
} | } | ||
+ | |||
+ | 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. |
<code java> | <code java> | ||
- | private | + | public class ExampleMod implements ModInitializer { |
- | Registry.FEATURE, | + | public |
- | new Identifier(" | + | |
- | new StoneSpiralFeature(DefaultFeatureConfig.CODEC) | + | |
- | ); | + | @Override |
+ | public void onInitialize() { | ||
+ | | ||
+ | } | ||
+ | } | ||
</ | </ | ||
- | ==== 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 | ||
+ | Vanilla features generated in the plain biomes are listed in '' | ||
- | We can iterate over '' | ||
<code java> | <code java> | ||
- | Registry.BIOME.forEach(biome -> biome.addFeature(GenerationStep.Feature.RAW_GENERATION, | + | @Mixin(DefaultBiomeFeatures.class) |
- | .configure(new DefaultFeatureConfig()) | + | public class DefaultBiomeFeaturesMixin { |
- | .createDecoratedFeature(Decorator.CHANCE_HEIGHTMAP.configure(new ChanceDecoratorConfig(100))) | + | @Inject(method = " |
- | )); | + | |
+ | builder.feature(GenerationStep.Feature.TOP_LAYER_MODIFICATION, | ||
+ | } | ||
+ | } | ||
</ | </ | ||
- | The first argument of '' | + | The first argument of '' |
+ | For above-ground houses you may go with '' | ||
- | The second argument of '' | + | === Result === |
+ | {{https://i.imgur.com/Kr59o0B.png}} | ||
- | The Decorator represents how the world chooses to place your Feature. '' | ||
- | |||
- | === Results === | ||
- | {{https:// |
tutorial/features.txt · Last modified: 2023/12/18 01:19 by solidblock