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/04/23 18:18] – [Adding a Feature to a Biome] Update feature configuration 2xsaiko | tutorial:features [2020/09/05 20:02] – Fix typo 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(IWorld world, ChunkGenerator<? | + | 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 constructor takes in a '' | + | The '' |
+ | You can pass in '' | ||
- | `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, | + | '' |
+ | 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(IWorld 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:: | + | |
- | ); | + | @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( | + | @Mixin(DefaultBiomeFeatures.class) |
- | | + | public class DefaultBiomeFeaturesMixin { |
- | LAVA_HOLE.configure(new DefaultFeatureConfig()) | + | |
- | .configureDecorator(Decorator.CHANCE_HEIGHTMAP, new ChanceDecoratorConfig(100)); | + | |
- | )); | + | |
+ | } | ||
+ | } | ||
</ | </ | ||
- | 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