User Tools

Site Tools


zh_cn:tutorial:structures

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
zh_cn:tutorial:structures [2020/02/04 10:56] – [Creating a Generator] lightcolourzh_cn:tutorial:structures [2022/09/29 05:27] (current) – 已过时 solidblock
Line 1: Line 1:
-====== 生成结构 ====== 
  
-===== 特征 ===== 
- 
-本教程中使用的所有代码都可以在此处获得: [[https://github.com/Draylar/fabric-structure-example-repo|fabric-structure-example-repo]] 
- 
-==== 介绍 ==== 
- 
-我们将研究如何在您的世界中注册和放置结构。 
- 
-要查看实际使用的1.14原版结构的示例,IglooGenerator和IglooFeature是一个良好的开端。 
- 
-对于最基本的结构,您将需要一个功能部件和生成器。 该功能处理在生成世界时注册结构并将其加载的过程-回答诸如“我应该在这里生成吗?”和‘我叫什么名字?’之类的问题,生成器处理块的放置或加载 结构文件(如果您选择这样做)。 
-==== 创建特征 ==== 
- 
-要创建基本功能,我们建议创建一个扩展AbstractTempleFeature <DefaultFeatureConfig>的类。 海难,雪屋和神殿等各种原版结构都使用AbstractTempleFeature作为基础。 您将必须重写以下方法: 
- 
-   * shouldStartAt:出于测试目的,返回true。 
-   * getName:您的结构的名称 
-   * getRadius:结构的半径,用于放置 
-   * getSeeedModifier 
- 
-您可以将DefaultFeatureConfig :: deserialize传递给构造函数进行测试。 
- 
-对于getStructureStartFactory,大多数原始结构会创建一个在其Feature类中扩展StructureStart的类: 
- 
-<code java [enable_line_numbers="true"]> 
-public static class MyStructureStart extends StructureStart { 
-    public MyStructureStart (StructureFeature<?> structureFeature_1, int int_1, int int_2, Biome biome_1, MutableIntBoundingBox mutableIntBoundingBox_1, int int_3, long long_1) { 
-        super(structureFeature_1, int_1, int_2, biome_1, mutableIntBoundingBox_1, int_3, long_1); 
-    } 
-    @Override 
-    public void initialize(ChunkGenerator<?> chunkGenerator, StructureManager structureManager, int chunkX, int chunkZ, Biome biome) { 
-        DefaultFeatureConfig defaultFeatureConfig = chunkGenerator.getStructureConfig(biome, MyMainclass.myFeature); 
-        int x = chunkX * 16; 
-        int z = chunkZ * 16; 
-        BlockPos startingPos = new BlockPos(x, 0, z); 
-        Rotation rotation = Rotation.values()[this.random.nextInt(Rotation.values().length)]; 
-        MyGenerator.addParts(structureManager, startingPos, rotation, this.children, this.random, defaultFeatureConfig); 
-        this.setBoundingBoxFromChildren(); 
-    } 
-} 
-</code> 
-     
-当世界尝试以新结构生成时,这称为“要素”和“生成器”之间的差距。 在您的主类中对该变量的引用尚不存在,但我们将在最后创建它。 您也可以将配置设置为等于新的DefaultFeatureConfig。 您可以在getStructureStartFactory中使用返回MyStructureStart :: new返回此函数。 
-这是结构文件和直接从generate方法生成的部分方式。 有两种解决方法: 
- 
-   *如果需要,您可以简单地在Feature类中重写generate,并使用setBlockState将块直接放置在世界上。 这是一个有效的选项,在1.13之前很流行。 
-   *使用结构文件和生成器。 在这一点上,这些功能非常强大,因此强烈建议使用。 
- 
-==== 创建一个生成器 ==== 
- 
-您可能已经注意到,我们需要创建一个生成器。 我们将其命名为MyGenerator,并在StructureStart类的initialize方法中对其进行引用。 它不需要覆盖任何内容,但需要满足以下条件: 
- 
-*指向您的结构文件的标识符; 如果需要示例,请使用''igloo / top'' 
-   *某种安装方法-addParts是一个好名字: 
- 
-<code java> 
-public static void addParts(StructureManager structureManager_1, BlockPos blockPos_1, Rotation rotation_1,  
-    List<StructurePiece> list_1, Random random_1, DefaultFeatureConfig featureConfig) 
-     
-} 
-</code> 
- 
-在addParts方法中,您可以选择将哪些结构件添加到生成过程中。 您可以添加如下内容: 
- 
-<code java> 
-list_1.add(new MyGenerator.Piece(structureManager_1, identifier, blockPos, rotation_1)); 
-</code> 
- 
-标识符是我们最近创建的路径。 
- 
-现在,我们将创建我们刚刚引用的作品; 创建一个名为Piece的类,该类扩展了SimpleStructurePiece//在您的生成器类中//. 
- 
-覆盖必需的方法,并添加一个接受StructureManager,Identifier,BlockPos和Rotation的构造函数。 ** toNbt不是必需的,但在需要时可用**。 我们还将使用不同的参数实现自己的setStructureData,因此它不是替代。 我们还有2个构造函数:1个构造函数,一个构造函数。 一个基本的模板是: 
-<code java [enable_line_numbers="true"]> 
-public static class Piece extends SimpleStructurePiece { 
-    private Rotation rotation; 
-    private Identifier template; 
-     
-    public Piece(StructureManager structureManager_1, Identifier identifier_1, BlockPos blockPos_1, Rotation rotation_1) { 
-        super(MyModClass.myStructurePieceType, 0); 
-         
-        this.pos = blockPos_1; 
-        this.rotation = rotation_1; 
-        this.template = identifier_1; 
-         
-        this.setStructureData(structureManager_1); 
-    } 
-     
-    public Piece(StructureManager structureManager_1, CompoundTag compoundTag_1) { 
-        super(MyModClass.myStructurePieceType, compoundTag_1); 
-        this.identifier = new Identifier(compoundTag_1.getString("Template")); 
-        this.rotation = Rotation.valueOf(compoundTag_1.getString("Rot")); 
-        this.setStructureData(structureManager_1); 
-    } 
-     
-    @Override 
-    protected void toNbt(CompoundTag compoundTag_1) { 
-        super.toNbt(compoundTag_1); 
-        compoundTag_1.putString("Template", this.template.toString()); 
-        compoundTag_1.putString("Rot", this.rotation.name()); 
-    } 
-     
-    public void setStructureData(StructureManager structureManager) { 
-        Structure structure_1 = structureManager.getStructureOrBlank(this.identifier); 
-        StructurePlacementData structurePlacementData_1 = (new StructurePlacementData()).setRotation(this.rotation).setMirrored(Mirror.NONE).setPosition(pos).addProcessor(BlockIgnoreStructureProcessor.IGNORE_STRUCTURE_BLOCKS); 
-        this.setStructureData(structure_1, this.pos, structurePlacementData_1); 
-    } 
-     
-    @Override 
-    protected void handleMetadata(String string_1, BlockPos blockPos_1, IWorld iWorld_1, Random random_1, MutableIntBoundingBox mutableIntBoundingBox_1) { 
-         
-    } 
-     
-    @Override 
-    public boolean generate(IWorld iWorld_1, Random random_1, MutableIntBoundingBox mutableIntBoundingBox_1, ChunkPos chunkPos_1) { 
-       
-    } 
-} 
-</code> 
-     
-handleMetadata是查看结构中的数据块并根据发现的内容执行任务的地方。 在原版结构中,数据块放置在箱子上方,因此可以用这种方法将它们填满战利品。 
- 
-我们将StructurePieceType设置为MyModClass.myStructurePiece类型; 这是保存您注册的结构件的变量。 在完成generate函数之后,我们将对其进行处理,该函数将设置结构的位置并生成它: 
- 
-<code java [enable_line_numbers="true"]> 
-@Override 
-public boolean generate(IWorld iWorld_1, Random random_1, MutableIntBoundingBox mutableIntBoundingBox_1, ChunkPos chunkPos_1) { 
-    int yHeight = iWorld_1.getTop(Heightmap.Type.WORLD_SURFACE_WG, this.pos.getX() + 8, this.pos.getZ() + 8); 
-    this.pos = this.pos.add(0, yHeight - 1, 0); 
-    return super.generate(iWorld_1, random_1, mutableIntBoundingBox_1, chunkPos_1); 
-} 
-</code> 
-     
-在这种情况下,我们仅获取块中间最高块的y位置,并从该位置生成结构。 
- 
-==== Registering Features ==== 
- 
-The last step is to register our features. We're going to need to register: 
- 
-  * StructurePieceType 
-  * StructureFeature<DefaultFeatureConfig> 
-  * StructureFeature<?> 
- 
-We're also going to need to add the structure to the STRUCTURES list and add it to each biome as a feature and generation step. 
- 
-Registering piece type: 
-<code java> 
-public static final StructurePieceType myStructurePieceType = Registry.register(Registry.STRUCTURE_PIECE, "my_piece", MyGenerator.Piece::new); 
-</code> 
-   
-Registering feature: 
-<code java> 
-public static final StructureFeature<DefaultFeatureConfig> myFeature = Registry.register(Registry.FEATURE, "my_feature", new MyFeature()); 
-</code> 
-   
-Registering structure: 
-<code java> 
-public static final StructureFeature<?> myStructure = Registry.register(Registry.STRUCTURE_FEATURE, "my_structure", myFeature); 
-</code> 
-   
-To put your feature in the features list, you can use: 
-<code java> 
-Feature.STRUCTURES.put("My Awesome Feature", myFeature); 
-</code> 
-   
-For testing, it's a good idea to register your feature to every biome and set the spawn rate to 100% so you can be sure it's spawning and working. You probably don't want your structure floating in the water, so we'll also filter that out. Add it to every biome by iterating over the biome list and adding it as a feature and generation step: 
- 
-<code java [enable_line_numbers="true"]> 
-for(Biome biome : Registry.BIOME) { 
-    if(biome.getCategory() != Biome.Category.OCEAN && biome.getCategory() != Biome.Category.RIVER) { 
-        biome.addStructureFeature(myFeature, new DefaultFeatureConfig()); 
-        biome.addFeature(GenerationStep.Feature.SURFACE_STRUCTURES, Biome.configureFeature(myFeature, new DefaultFeatureConfig(), Decorator.CHANCE_PASSTHROUGH, new ChanceDecoratorConfig(0))); 
-    } 
-} 
-</code> 
- 
-ChanceDecoratorConfig's argument is basically how many chunks it will skip over before generating. 0 is every chunk, 1 is every other, and 100 is every 100. 
- 
-You need to add your structure as a feature so your biome knows it exists, and then as a generation step so it's actually generated. 
- 
-Load into your world, and if all went well, you should be met with a //lot// of Igloos. 
zh_cn/tutorial/structures.1580813789.txt.gz · Last modified: 2020/02/04 10:56 by lightcolour