User Tools

Site Tools


zh_cn: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
Last revisionBoth sides next revision
zh_cn:tutorial:features [2021/07/12 00:52] – [在您的世界中生成Feature] solidblockzh_cn:tutorial:features [2021/07/12 01:17] – [向生物群落添加Feature] solidblock
Line 1: Line 1:
-===== 添加特征地形 [1.17] ===== +===== 添加地形特征 [1.17] =====
-岩石,树木,矿石和池塘都是Feature的示例。 它们是对世界的简单补充,它们的生成取决于它们的配置方式。 在本教程中,我们将研究如何在我们的世界中随机生成一个简单的石螺旋Feature。+
  
-岩石、树木、矿石、池塘都是特征地形的例子,是对世界的简单补充生成,并根据配置的方式生成。本教程中,我们将研究如何随机生成简单的石头螺旋地形。+岩石、树木、矿石、池塘都是地形特征的例子,是对世界的简单补充生成,并根据配置的方式生成。本教程中,我们将研究如何随机生成简单的石头螺旋地形。
  
-往生物群系中添加特征地形需要3个步骤。 +往生物群系中添加地形特征需要3个步骤。 
-  * 创建特征地形 +  * 创建地形特征 
-  * 配置特征地形 +  * 配置地形特征 
-  * 使用[[https://github.com/FabricMC/fabric/pull/1097|Fabric API中的生物群系修改API]]以往生物群系中添加特征地形。+  * 使用[[https://github.com/FabricMC/fabric/pull/1097|Fabric API中的生物群系修改API]]以往生物群系中添加地形特征
  
 注意生物群系修改API标记为实验性。如果API不起作用,考虑使用[[?rev=1599388928|mixin版本]]。 注意生物群系修改API标记为实验性。如果API不起作用,考虑使用[[?rev=1599388928|mixin版本]]。
  
-==== 创建Feature类 ==== +==== 创建地形特征 ==== 
-一个简单的Feature如下所示: +一个简单的地形特征如下所示: 
-<code java [enable_line_numbers="true"]>+<code java>
 public class StoneSpiralFeature extends Feature<DefaultFeatureConfig> { public class StoneSpiralFeature extends Feature<DefaultFeatureConfig> {
 +  public StoneSpiralFeature(Codec<DefaultFeatureConfig> config) {
 +    super(config);
 +  }
  
-    public StoneSpiralFeature(Function<Dynamic<?>? extends DefaultFeatureConfigconfig) { +  @Override 
-        super(config); +  public boolean generate(StructureWorldAccess worldChunkGenerator generator, Random random, BlockPos pos, 
-    }+      DefaultFeatureConfig config) { 
 +    BlockPos topPos = world.getTopPosition(Heightmap.Type.WORLD_SURFACE, pos); 
 +    Direction offset = Direction.NORTH;
  
-    @Override +    for (int y = 1; y <= 15; y++) { 
-    public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) { +      offset = offset.rotateYClockwise(); 
-        BlockPos topPos = world.getTopPosition(Heightmap.Type.WORLD_SURFACE, pos); +      world.setBlockState(topPos.up(y).offset(offset), Blocks.STONE.getDefaultState(), 3);
-        Direction offset = Direction.NORTH; +
- +
-        for (int y = 1; y < 16; y++) { +
-            offset = offset.rotateYClockwise(); +
-            world.setBlockState(topPos.up(y).offset(offset), Blocks.STONE.getDefaultState(), 3)+
-        } +
- +
-        return true;+
     }     }
 +
 +    return true;
 +  }
 } }
 </code> </code>
  
-构造函数采用''Function<Dynamic<? extends DefaultFeatureConfig>>'',这是数据修复程序配置实例的工厂。 可以直接在超级调用中或实例化功能时为默认配置功能''DefaultFeatureConfig :: deserialize''+''Feature<DefaultFeatureConfig>''构造采用''Codec<DefaultFeatureConfig>''可以直接在构造器的超级调用中或实例化特性时为默认配置特性''DefaultFeatureConfig.CODEC''
  
-块决定生成Feature,将调用``generate``。 如果将功能配置为产生每个块,则也会为正在生成的每个块调用此功能。 在将功能配置为以每个生物群落以一率生成的情况下,在世界想要生成结构的情况下才调用``generate``+块决定生成地形特征时调用''generate''。如果地形特征配置为每个生成,则每个被生成时都会调用一次。在特征被配置为以每个生物群系特的概率生成的情况下,''generate''只会在世界想要生成结构的实例中调用。
  
-在我们的实现中,我们从世界最高位置开始构建一个简单的16块高的石螺旋+在我们的实现中,我们从世界最高位置的方块构建一个简单的15个方块高的石螺旋。 
 + 
 +地形特征可以像游戏其他内容一样被注册,且你不需要担心没有特定的构建器(builder)和机制(mechanic)。
  
 <code java> <code java>
-@Override +public class ExampleMod implements ModInitializer 
-public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) +  private static final Feature<DefaultFeatureConfig> STONE_SPIRAL new StoneSpiralFeature(DefaultFeatureConfig.CODEC);
-    BlockPos topPos = world.getTopPosition(Heightmap.Type.WORLD_SURFACE, pos); +
-    Direction offset = Direction.NORTH; +
- +
-    for (int y = 1; y 16; y++) { +
-        offset offset.rotateYClockwise(); +
-        world.setBlockState(topPos.up(y).offset(offset), Blocks.STONE.getDefaultState(), 3); +
-    }+
  
-    return true;+  @Override 
 +  public void onInitialize() { 
 +    Registry.register(Registry.FEATURE, new Identifier("tutorial", "stone_spiral"), STONE_SPIRAL); 
 +  }
 } }
 </code> </code>
  
-==== 注册一个Feature ==== +==== 配置地形特征 ==== 
-可以像注册游戏中其他大多数内容一样注册Feature,而且您不必担心任何殊的构建器或机制+我们需要为地形特征提供配置。确保注册配置地形征和地形特征 
 <code java> <code java>
-private static final Feature<DefaultFeatureConfigLAVA_HOLE Registry.register+public class ExampleMod implements ModInitializer { 
- Registry.FEATURE+  public static final ConfiguredFeature<?, ?STONE_SPIRAL_CONFIGURED STONE_SPIRAL.configure(FeatureConfig.DEFAULT) 
- new Identifier("tutorial", "stone_spiral"), +      .decorate(Decorator.CHANCE.configure(new ChanceDecoratorConfig(5))); 
- new StoneSpiralFeature(DefaultFeatureConfig::deserialize) + 
-);+  @Override 
 +  public void onInitialize() { 
 +    [...] 
 +     
 +    RegistryKey<ConfiguredFeature<?, ?>> stoneSpiral = RegistryKey.of(Registry.CONFIGURED_FEATURE_KEY
 +        new Identifier("tutorial", "stone_spiral")); 
 +    Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, stoneSpiral.getValue(), STONE_SPIRAL_CONFIGURED); 
 +  } 
 +}
 </code> </code>
  
-==== 向生物群添加Feature ==== +Decorator表示世界如何选择放置该特征。要选择正确的Decorator,检查原版的地形特征,你自己的应该要类似。装饰器配置是从这个分支出来的,在''CHANCE''的情况下,你应该传入''ChanceDecoratorConfig''的实例。  
-生物群系有一种称为''addFeature''的方法,用于将Feature添加到生物群落的生成过程中。 您可以在每个生物群落类(例如''ForestBiome''或''SavannaBiome'')中查看此方法的更详细用法+ 
 +==== 向生物群添加特征地形 ==== 
 +我们使用生物群系修改API
  
-我们可以遍历''Registry.BIOME''以将我们的Feature添加到每个生物群系中。 
 <code java> <code java>
-Registry.BIOME.forEach(biome -> biome.addFeature( +public class ExampleMod implements ModInitializer { 
-        GenerationStep.Feature.RAW_GENERATION, +  [...]
- Biome.configureFeature( +
- LAVA_HOLE, +
- new DefaultFeatureConfig(), +
- Decorator.CHANCE_HEIGHTMAP, +
- new ChanceDecoratorConfig(100) +
-+
-)); +
-</code>+
  
-''addFeature''的第一个参数有助于确定何时生成结构。 对于地上的房屋,您可以使用''SURFACE_STRUCTURES'',对于洞穴,您可以使用'' RAW_GENERATION''+  @Override 
 +  public void onInitialize() { 
 +    [...] 
 +    BiomeModifications.addFeature(BiomeSelectors.all(), GenerationStep.Feature.UNDERGROUND_ORES, stoneSpiral); 
 +  } 
 +
 +</code>
  
-''addFeature''的第个参数是ConfiguredFeature,可以通过''Biome.configureFeature''创建。 后者接收功能的实例,功能的config类,装饰器和装饰器配置的实例+''addFeature''的第个参数确定结构生成在什么生物群系中
  
-装饰器代表世界如选择放置要素。 ''CHANCE_HEIGHTMAP''通过查看高度图来工作,而''NOISE_HEIGHTMAP_32''可使用噪声来工作。 要选择正确的装饰器请签出与您自己风格相似的香草功能。 装饰器配置将分支此分支; 对于''CHANCE_HEIGHTMAP'',您将传入''ChanceHeightmapDecorator的实例+第二个参数帮助你确定结构时生成对于地上的房子,以用''SURFACE_STRUCTURES'',对于洞穴,可以用''RAW_GENERATION''
  
 === 结果 === === 结果 ===
 {{https://i.imgur.com/Kr59o0B.png}} {{https://i.imgur.com/Kr59o0B.png}}
zh_cn/tutorial/features.txt · Last modified: 2022/08/18 03:37 by solidblock