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/01/08 12:17] – lightcolour | tutorial:features [2020/09/05 20:29] – minor improvement siglong | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== 在您的世界中生成Feature | + | ===== Generating Features in your World ===== |
- | 岩石,树木,矿石和池塘都是Feature的示例。 它们是对世界的简单补充,它们的生成取决于它们的配置方式。 在本教程中,我们将研究如何在我们的世界中随机生成一个简单的石螺旋Feature。 | + | Rocks, trees, ores, and ponds are all examples of Features. |
- | ==== 创建Feature类 ==== | + | They are simple generation additions to the world which generate depending on how they are configured. |
- | 一个简单的Feature如下所示: | + | In this tutorial, we'll look at generating a simple stone spiral feature in the plain biomes randomly. |
- | <code java [enable_line_numbers=" | + | |
- | public class StoneSpiralFeature extends Feature< | + | |
- | public StoneSpiralFeature(Function< | + | 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 | ||
- | @Override | + | ==== Creating a feature ==== |
- | public boolean generate(IWorld world, ChunkGenerator<? | + | 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 '' |
+ | You can pass in '' | ||
- | 当块决定生成Feature时,将调用``generate``。 如果将功能配置为产生每个块,则也会为正在生成的每个块调用此功能。 在将功能配置为以每个生物群落以一定速率生成的情况下,仅在世界想要生成结构的情况下才调用``generate``。 | + | '' |
+ | 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, '' | ||
- | 在我们的实现中,我们将从世界的最高位置开始构建一个简单的16块高的石头螺旋: | + | 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; | + | |
} | } | ||
</ | </ | ||
- | ==== 注册一个Feature | + | ==== Configuring a feature |
- | 可以像注册游戏中的其他大多数内容一样注册Feature,而且您不必担心任何特殊的构建器或机制。 | + | 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:: | + | |
- | ); | + | @Override |
+ | public void onInitialize() { | ||
+ | [...] | ||
+ | |||
+ | | ||
+ | } | ||
+ | } | ||
</ | </ | ||
- | ==== 向生物群落添加Feature ==== | + | The Decorator represents how the world chooses to place your feature. |
- | 生物群系有一种称为'' | + | 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 to a biome ==== | ||
+ | Vanilla features generated in the plain biomes are listed in '' | ||
- | 我们可以遍历'' | ||
<code java> | <code java> | ||
- | Registry.BIOME.forEach(biome -> biome.addFeature( | + | @Mixin(DefaultBiomeFeatures.class) |
- | | + | public class DefaultBiomeFeaturesMixin { |
- | Biome.configureFeature( | + | |
- | LAVA_HOLE, | + | |
- | new DefaultFeatureConfig(), | + | |
- | Decorator.CHANCE_HEIGHTMAP, | + | } |
- | new ChanceDecoratorConfig(100) | + | } |
- | ) | + | |
- | )); | + | |
</ | </ | ||
- | '' | + | The first argument of '' |
+ | For above-ground houses you may go with '' | ||
- | '' | + | === Result === |
+ | {{https://i.imgur.com/ | ||
- | 装饰器代表世界如何选择放置要素。 '' | ||
- | |||
- | === 结果 === | ||
- | {{https:// |
tutorial/features.txt · Last modified: 2023/12/18 01:19 by solidblock