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
Next revisionBoth sides next revision
zh_cn:tutorial:structures [2020/02/04 10:45] – [Introduction] lightcolourzh_cn:tutorial:structures [2021/07/24 16:27] – [创建地物] solidblock
Line 1: Line 1:
-====== 生成结构 ======+====== 添加结构特征 [1.16.3] ====== 
 +现在,往世界中注册并放置一些结构。
  
-===== 特征 =====+入药查看原版结构的实例,可以从简单的''IglooFeature''和''IglooGenerator''开始。然而,制作新结构的上升的标准是使用拼图结构,这样更易于使用并可以让你少打一些代码。[[zh_cn:tutorial:jigsaw|这里有关于拼图结构和制作方法的教程。]]
  
-教程中使用所有代码都可以获得: [[https://github.com/Draylar/fabric-structure-example-repo|fabric-structure-example-repo]]+对于大多数基本的结构,你需要地物(feature)和生成器(generator)。地物处理注册结构并生成世界时加载的过程。生成器理方块的放置,或者在结构文件中加载(如果选择这样做)。
  
-==== 介绍 ====+注意本教程依赖标记为实验性的[[https://github.com/FabricMC/fabric/pull/1097|Fabric API中的生物群系修改API]]。如果API不起作用,考虑使用[[?rev=1599808070|mixin版本]]。
  
-我们将研究如何在您世界中注册和放置结构+===== 创建地物 ===== 
 +要创建基本的地物(feature),我们推荐创建扩展''StructureFeature<DefaultFeatureConfig>''类。大多数原版结构,如沉船、雪屋、神殿都是以''StructureFeature<DefaultFeatureConfig>''为基础,
  
-查看实际使用的1.14原版结构的示例,IglooGenerator和IglooFeature是一个良好的开端+你需覆写''getStructureStartFactory''方法。对于''getStructureStartFactory'',大多数原版结构在其地物类中创建扩展''StructureStart''
  
-对于最基本的结构,您将需要一个功能部件和生成器。 该功能处理在生成世界时注册结构并将其加载的过程-回答诸如“我应该在这里生成吗?”和‘我叫什么名字?’之类的问题,生成器处理块的放置或加载 结构文件(如果您选择这样做)。 +<code java> 
-==== Creating a Feature ====+public class MyFeature extends StructureFeature<DefaultFeatureConfig>
 +  public MyFeature(Codec<DefaultFeatureConfig> codec) { 
 +    super(codec); 
 +  }
  
-To create a basic feature, we recommend creating a class that extends AbstractTempleFeature<DefaultFeatureConfig>. Various vanilla structures, such as Shipwrecks, Igloos, and Temples, use AbstractTempleFeature as a base. You will have to override the following methods:+  @Override 
 +  public StructureFeature.StructureStartFactory<DefaultFeatureConfig> getStructureStartFactory() { 
 +    return Start::new; 
 +  }
  
-  * shouldStartAt: return true for testing purposes. +  public static class Start extends StructureStart<DefaultFeatureConfig> { 
-  * getName: name of your structure +    public Start(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box, int references, 
-  * getRadius: radius of your structureused for placement +        long seed) { 
-  * getSeeedModifier+      super(feature, chunkX, chunkZ, box, referencesseed); 
 +    }
  
-You can pass DefaultFeatureConfig::deserialize into your constructor for testing. +    // 世界尝试在新的结构中生成时调用,同时也是地物和结构之间的“空隙(gap)”。 
- +    public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, 
-For getStructureStartFactory, most vanilla structures make a class that extends StructureStart inside their Feature class: +        int chunkZ, Biome biome, DefaultFeatureConfig config) { 
- +      int x = chunkX * 16; 
-<code java [enable_line_numbers="true"]> +      int z = chunkZ * 16; 
-public static class MyStructureStart extends StructureStart { +      int y = chunkGenerator.getHeight(x, z, Heightmap.Type.WORLD_SURFACE_WG); 
-    public MyStructureStart (StructureFeature<?> structureFeature_1int int_1, int int_2, Biome biome_1, MutableIntBoundingBox mutableIntBoundingBox_1, int int_3, long long_1) { +      BlockPos pos = new BlockPos(x, y, z); 
-        super(structureFeature_1, int_1, int_2, biome_1, mutableIntBoundingBox_1, int_3, long_1); +      BlockRotation rotation = BlockRotation.random(this.random); 
-    } +      MyGenerator.addPieces(managerpos, rotation, this.children); 
-    @Override +      this.setBoundingBoxFromChildren();
-    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(structureManagerstartingPos, rotation, this.children, this.random, defaultFeatureConfig); +
-        this.setBoundingBoxFromChildren();+
     }     }
 +  }
 } }
 </code> </code>
-     
-This is called when the world attempts to spawn in a new structure, and is the gap between your Feature and Generator. The reference to the variable in your main class doesn't exist yet, but we'll create it at the end. You can also just set the config equal to a new DefaultFeatureConfig. You can return this in getStructureStartFactory with return MyStructureStart::new. 
  
-This is where structure files and generating straight from a generate method part ways. There are two ways to go about this:+==== 创建一个生成器 ====
  
-  * If you want, you can simply override generate in your Feature class and use setBlockState to place blocks directly in the world. This is a valid option and was popular pre-1.13. +您可能已经注意到,我们需要创建一个生成器。 我们将其命名为MyGenerator,并在StructureStart类的initialize方法中对其进行引用。 它不需要覆盖任何内容,但需要满足以下条件:
-  * Use structure files and a Generator. These are rather powerful at this point and are highly recommended.+
  
-==== Creating a Generator ==== +*指向您的结构文件的标识符; 如果需要示例,请使用''igloo / top'' 
- +   *某种安装方法-addParts是一个好名字:
-As you have probably noticed, we need to create a generator. We'll name it MyGenerator, and it's referenced in the initialize method of your StructureStart class. It doesn't need to override anything, but does require the following: +
- +
-  * An Identifier that points to your structure file; use "igloo/top" if you need an example. +
-  Some sort of setup method - addParts is a good name:+
  
 <code java> <code java>
Line 63: Line 58:
 } }
 </code> </code>
-     + 
-In your addParts method, you can choose which structure pieces are added to your generation process. You can add a piece like this:+addParts方法中,您可以选择将哪些结构件添加到生成过程中。 您可以添加如下内容:
  
 <code java> <code java>
 list_1.add(new MyGenerator.Piece(structureManager_1, identifier, blockPos, rotation_1)); list_1.add(new MyGenerator.Piece(structureManager_1, identifier, blockPos, rotation_1));
 </code> </code>
-   
-where the identifier is the path we created recently. 
  
-We're now going to create the Piece we just referenced; make a class called Piece that extends SimpleStructurePiece //within your generator class//.+标识符是我们最近创建的路径。
  
-Override required methods, and add a constructor that takes in a StructureManager, Identifier, BlockPos, and Rotation**toNbt isn't required but is available if you need it**. We're also implementing our own setStructureData with different arguments, so it's not an override. We also have 2 constructors: 1 for our own pieces, and one for registry. A basic template would be:+现在,我们将创建我们刚刚引用的作品; 创建一个名为Piece的类,该类扩展了SimpleStructurePiece//在您的生成器类中//.
  
 +覆盖必需的方法,并添加一个接受StructureManager,Identifier,BlockPos和Rotation的构造函数。 ** toNbt不是必需的,但在需要时可用**。 我们还将使用不同的参数实现自己的setStructureData,因此它不是替代。 我们还有2个构造函数:1个构造函数,一个构造函数。 一个基本的模板是:
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
 public static class Piece extends SimpleStructurePiece { public static class Piece extends SimpleStructurePiece {
Line 123: Line 117:
 </code> </code>
          
-handleMetadata is where you look at data blocks within your structure and do tasks based on what you find. In vanilla structures, data blocks are placed above chests so they can be filled with loot in this method.+handleMetadata是查看结构中的数据块并根据发现的内容执行任务的地方。 在原版结构中,数据块放置在箱子上方,因此可以用这种方法将它们填满战利品。
  
-We set the StructurePieceType to MyModClass.myStructurePiece type; this is the variable that holds your registered structure piece. We'll handle that after we finish the generate function, which sets the position of your structure and generates it:+我们将StructurePieceType设置为MyModClass.myStructurePiece类型; 这是保存您注册的结构件的变量。 在完成generate函数之后,我们将对其进行处理,该函数将设置结构的位置并生成它:
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
Line 136: Line 130:
 </code> </code>
          
-In this case, we simply get the position of the highest block in the middle of our chunk and generate the structure off that position. +在这种情况下,我们仅获取块中间最高块的y位置,并从该位置生成结构。
  
-==== Registering Features ====+==== 注册功能 ====
  
-The last step is to register our features. We're going to need to register:+最后一步是注册我们的功能。 我们需要注册:
  
   * StructurePieceType   * StructurePieceType
Line 146: Line 140:
   * StructureFeature<?>   * 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> <code java>
 public static final StructurePieceType myStructurePieceType = Registry.register(Registry.STRUCTURE_PIECE, "my_piece", MyGenerator.Piece::new); public static final StructurePieceType myStructurePieceType = Registry.register(Registry.STRUCTURE_PIECE, "my_piece", MyGenerator.Piece::new);
 </code> </code>
      
-Registering feature:+注册功能:
 <code java> <code java>
 public static final StructureFeature<DefaultFeatureConfig> myFeature = Registry.register(Registry.FEATURE, "my_feature", new MyFeature()); public static final StructureFeature<DefaultFeatureConfig> myFeature = Registry.register(Registry.FEATURE, "my_feature", new MyFeature());
 </code> </code>
      
-Registering structure:+注册结构:
 <code java> <code java>
 public static final StructureFeature<?> myStructure = Registry.register(Registry.STRUCTURE_FEATURE, "my_structure", myFeature); public static final StructureFeature<?> myStructure = Registry.register(Registry.STRUCTURE_FEATURE, "my_structure", myFeature);
 </code> </code>
      
-To put your feature in the features list, you can use:+要将功能放入功能列表,可以使用:
 <code java> <code java>
 Feature.STRUCTURES.put("My Awesome Feature", myFeature); Feature.STRUCTURES.put("My Awesome Feature", myFeature);
 </code> </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:+对于测试,将功能注册到每个生物群系并将生成率设置为100%是个好主意,这样您就可以确保其生成并正常工作。 您可能不希望您的结构漂浮在水中,因此我们也将其过滤掉。 通过遍历生物群系列表并将其添加为特征和生成步骤,将其添加到每个生物群系:
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
Line 179: Line 173:
 </code> </code>
  
-ChanceDecoratorConfig's argument is basically how many chunks it will skip over before generating. is every chunk, is every other, and 100 is every 100.+ChanceDecoratorConfig的参数基本上是在生成之前将跳过多少个块。 0是每个块,1是彼此,并且100是每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.+加载到您的世界中,如果一切顺利,应该会遇到//很多//的雪屋。