zh_cn:tutorial:structures
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
zh_cn:tutorial:structures [2020/02/04 10:50] – [创建特征] lightcolour | zh_cn:tutorial:structures [2021/07/24 16:34] – [创建一个生成器] not done solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
+ | 现在,往世界中注册并放置一些结构。 | ||
- | ===== 特征 ===== | + | 入药查看原版结构的实例,可以从简单的'' |
- | 本教程中使用的所有代码都可以在此处获得: [[https:// | + | 对于大多数基本的结构,你需要地物(feature)和生成器(generator)。地物处理注册结构并在生成世界时加载的过程。生成器处理方块的放置,或者在结构文件中加载(如果选择这样做)。 |
- | ==== 介绍 ==== | + | 注意本教程依赖标记为实验性的[[https:// |
- | 我们将研究如何在您的世界中注册和放置结构。 | + | ===== 创建地物 ===== |
+ | 要创建基本的地物(feature),我们推荐创建扩展'' | ||
- | 要查看实际使用的1.14原版结构的示例,IglooGenerator和IglooFeature是一个良好的开端。 | + | 你需要覆写'' |
- | 对于最基本的结构,您将需要一个功能部件和生成器。 该功能处理在生成世界时注册结构并将其加载的过程-回答诸如“我应该在这里生成吗?”和‘我叫什么名字?’之类的问题,生成器处理块的放置或加载 结构文件(如果您选择这样做)。 | + | <code java> |
- | ==== 创建特征 ==== | + | public class MyFeature extends StructureFeature< |
+ | public MyFeature(Codec< | ||
+ | super(codec); | ||
+ | } | ||
- | 要创建基本功能,我们建议创建一个扩展AbstractTempleFeature | + | @Override |
+ | public StructureFeature.StructureStartFactory< | ||
+ | return Start:: | ||
+ | } | ||
- | * shouldStartAt:出于测试目的,返回true。 | + | public static class Start extends StructureStart< |
- | * getName:您的结构的名称 | + | public Start(StructureFeature< |
- | * getRadius:结构的半径,用于放置 | + | long seed) { |
- | * getSeeedModifier | + | |
+ | } | ||
- | 您可以将DefaultFeatureConfig :: deserialize传递给构造函数进行测试。 | + | // 世界尝试在新的结构中生成时调用,同时也是地物和结构之间的“空隙(gap)”。 |
- | + | public | |
- | 对于getStructureStartFactory,大多数原始结构会创建一个在其Feature类中扩展StructureStart的类: | + | |
- | + | int x = chunkX * 16; | |
- | <code java [enable_line_numbers=" | + | int z = chunkZ * 16; |
- | public static class MyStructureStart extends StructureStart { | + | int y = chunkGenerator.getHeight(x, |
- | public | + | |
- | super(structureFeature_1, | + | |
- | } | + | MyGenerator.addPieces(manager, pos, rotation, this.children); |
- | @Override | + | this.setBoundingBoxFromChildren(); |
- | public void initialize(ChunkGenerator<?> | + | |
- | | + | |
- | | + | |
- | int z = chunkZ * 16; | + | |
- | BlockPos | + | |
- | | + | |
- | MyGenerator.addParts(structureManager, startingPos, rotation, this.children, this.random, | + | |
- | this.setBoundingBoxFromChildren(); | + | |
} | } | ||
+ | } | ||
} | } | ||
</ | </ | ||
- | | ||
- | 当世界尝试以新结构生成时,这称为“要素”和“生成器”之间的差距。 在您的主类中对该变量的引用尚不存在,但我们将在最后创建它。 您也可以将配置设置为等于新的DefaultFeatureConfig。 您可以在getStructureStartFactory中使用返回MyStructureStart :: new返回此函数。 | ||
- | 这是结构文件和直接从generate方法生成的部分方式。 有两种解决方法: | ||
- | | + | ===== 创建生成器 |
- | | + | 你可能已经注意到,我们需要创建生成器。 |
- | ==== Creating | + | This is where structure files and generating straight from a '' |
- | As you have probably noticed, we need to create a generator. We'll name it MyGenerator, | + | * If you want, you can simply override '' |
+ | * Use structure files. These are rather powerful at this point and are highly recommended. | ||
- | | + | 本教程中,使用结构文件,不需要override任何内容,但确实需要: |
- | * Some sort of setup method - addParts is a good name: | + | |
+ | * 一些安装方法——例如'' | ||
<code java> | <code java> | ||
- | public static void addParts(StructureManager | + | public class MyGenerator { |
- | | + | private static final Identifier IGLOO_TOP = new Identifier(" |
- | + | ||
+ | | ||
+ | pieces.add(new MyPiece(manager, pos, IGLOO_TOP, rotation)); | ||
+ | } | ||
} | } | ||
</ | </ | ||
- | | + | |
- | In your addParts method, you can choose | + | 在'' |
+ | |||
+ | 我们现在// | ||
+ | |||
+ | Override required methods, and add a constructor that takes in a '' | ||
+ | **toNbt isn't required but is available if you need it**. | ||
+ | We're also implementing '' | ||
+ | We also have 2 constructors: | ||
+ | A basic template would be: | ||
<code java> | <code java> | ||
- | list_1.add(new MyGenerator.Piece(structureManager_1, | + | public static class MyPiece extends SimpleStructurePiece { |
- | </ | + | |
- | + | | |
- | 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//. | + | public MyPiece(StructureManager structureManager, |
+ | super(ExampleMod.MY_PIECE, | ||
+ | this.template = new Identifier(compoundTag.getString(" | ||
+ | this.rotation = BlockRotation.valueOf(compoundTag.getString(" | ||
+ | this.initializeStructureData(structureManager); | ||
+ | } | ||
- | Override required methods, and add a constructor that takes in a StructureManager, Identifier, BlockPos, | + | public MyPiece(StructureManager |
+ | super(ExampleMod.MY_PIECE, 0); | ||
+ | this.pos = pos; | ||
+ | this.rotation = rotation; | ||
+ | this.template = template; | ||
- | <code java [enable_line_numbers=" | + | this.initializeStructureData(structureManager); |
- | public static class Piece extends SimpleStructurePiece { | + | } |
- | | + | |
- | private | + | private |
- | + | | |
- | public Piece(StructureManager | + | |
- | | + | |
- | + | .setMirror(BlockMirror.NONE) | |
- | this.pos | + | .addProcessor(BlockIgnoreStructureProcessor.IGNORE_STRUCTURE_BLOCKS); |
- | this.rotation = rotation_1; | + | this.setStructureData(structure, this.pos, placementData); |
- | | + | } |
- | + | ||
- | this.setStructureData(structureManager_1); | + | protected void toNbt(CompoundTag |
- | | + | super.toNbt(tag); |
- | + | tag.putString(" | |
- | public Piece(StructureManager structureManager_1, | + | tag.putString(" |
- | super(MyModClass.myStructurePieceType, | + | } |
- | this.identifier = new Identifier(compoundTag_1.getString(" | + | |
- | this.rotation = Rotation.valueOf(compoundTag_1.getString(" | + | @Override |
- | this.setStructureData(structureManager_1); | + | protected void handleMetadata(String |
- | } | + | |
- | + | } | |
- | | + | |
- | | + | |
- | super.toNbt(compoundTag_1); | + | |
- | | + | |
- | | + | |
- | } | + | |
- | + | ||
- | | + | |
- | 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, | + | |
- | } | + | |
- | + | ||
- | | + | |
- | protected void handleMetadata(String | + | |
- | + | ||
- | } | + | |
- | + | ||
- | @Override | + | |
- | public boolean generate(IWorld iWorld_1, Random random_1, MutableIntBoundingBox mutableIntBoundingBox_1, | + | |
- | + | ||
- | | + | |
} | } | ||
</ | </ | ||
| | ||
- | 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. | + | '' |
+ | This can be good for dynamic stuff such as placing certain mobs based on what mod is on and so on. | ||
- | We set the StructurePieceType | + | In vanilla structures, data blocks are placed above chests so they can be filled with loot in this method. |
+ | HOWEVER, you do not need to use datablocks to place chests with loot. Instead, use this command to set a north facing chest with a loottable. | ||
+ | Save this chest into your structure's nbt file and it will generate loot when opened for the first time. (Don't open the chest before saving to the nbt file!) | ||
+ | < | ||
- | <code java [enable_line_numbers=" | + | We set the '' |
- | @Override | + | |
- | public boolean generate(IWorld iWorld_1, Random random_1, MutableIntBoundingBox mutableIntBoundingBox_1, | + | |
- | int yHeight = iWorld_1.getTop(Heightmap.Type.WORLD_SURFACE_WG, | + | |
- | | + | |
- | return super.generate(iWorld_1, | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | In this case, we simply get the y position of the highest block in the middle of our chunk and generate | + | |
- | ==== Registering Features | + | ==== 注册功能 |
- | The last step is to register our features. We're going to need to register: | + | 最后一步是注册我们的功能。 我们需要注册: |
* StructurePieceType | * StructurePieceType | ||
Line 145: | Line 138: | ||
* 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, | public static final StructurePieceType myStructurePieceType = Registry.register(Registry.STRUCTURE_PIECE, | ||
</ | </ | ||
| | ||
- | Registering feature: | + | 注册功能: |
<code java> | <code java> | ||
public static final StructureFeature< | public static final StructureFeature< | ||
</ | </ | ||
| | ||
- | Registering structure: | + | 注册结构: |
<code java> | <code java> | ||
public static final StructureFeature<?> | public static final StructureFeature<?> | ||
</ | </ | ||
| | ||
- | To put your feature in the features list, you can use: | + | 要将功能放入功能列表,可以使用: |
<code java> | <code java> | ||
Feature.STRUCTURES.put(" | Feature.STRUCTURES.put(" | ||
</ | </ | ||
| | ||
- | 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=" | <code java [enable_line_numbers=" | ||
Line 178: | Line 171: | ||
</ | </ | ||
- | ChanceDecoratorConfig's argument is basically how many chunks it will skip over before generating. | + | ChanceDecoratorConfig的参数基本上是在生成之前将跳过多少个块。 |
- | 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. | + | 加载到您的世界中,如果一切顺利,应该会遇到//很多//的雪屋。 |