zh_cn:tutorial:structures
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
zh_cn:tutorial:structures [2021/07/24 16:34] – [创建一个生成器] not done solidblock | zh_cn:tutorial:structures [2022/09/29 05:27] (current) – 已过时 solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== 添加结构特征 [1.16.3] ====== | ||
- | 现在,往世界中注册并放置一些结构。 | ||
- | 入药查看原版结构的实例,可以从简单的'' | ||
- | |||
- | 对于大多数基本的结构,你需要地物(feature)和生成器(generator)。地物处理注册结构并在生成世界时加载的过程。生成器处理方块的放置,或者在结构文件中加载(如果选择这样做)。 | ||
- | |||
- | 注意本教程依赖标记为实验性的[[https:// | ||
- | |||
- | ===== 创建地物 ===== | ||
- | 要创建基本的地物(feature),我们推荐创建扩展'' | ||
- | |||
- | 你需要覆写'' | ||
- | |||
- | <code java> | ||
- | public class MyFeature extends StructureFeature< | ||
- | public MyFeature(Codec< | ||
- | super(codec); | ||
- | } | ||
- | |||
- | @Override | ||
- | public StructureFeature.StructureStartFactory< | ||
- | return Start::new; | ||
- | } | ||
- | |||
- | public static class Start extends StructureStart< | ||
- | public Start(StructureFeature< | ||
- | long seed) { | ||
- | super(feature, | ||
- | } | ||
- | |||
- | // 世界尝试在新的结构中生成时调用,同时也是地物和结构之间的“空隙(gap)”。 | ||
- | public void init(DynamicRegistryManager registryManager, | ||
- | int chunkZ, Biome biome, DefaultFeatureConfig config) { | ||
- | int x = chunkX * 16; | ||
- | int z = chunkZ * 16; | ||
- | int y = chunkGenerator.getHeight(x, | ||
- | BlockPos pos = new BlockPos(x, y, z); | ||
- | BlockRotation rotation = BlockRotation.random(this.random); | ||
- | MyGenerator.addPieces(manager, | ||
- | this.setBoundingBoxFromChildren(); | ||
- | } | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | ===== 创建生成器 ===== | ||
- | 你可能已经注意到,我们需要创建生成器。 | ||
- | |||
- | This is where structure files and generating straight from a '' | ||
- | |||
- | * If you want, you can simply override '' | ||
- | * Use structure files. These are rather powerful at this point and are highly recommended. | ||
- | |||
- | 本教程中,使用结构文件,不需要override任何内容,但确实需要: | ||
- | * 指向结构文件的标识符(identifier,例如''" | ||
- | * 一些安装方法——例如'' | ||
- | |||
- | <code java> | ||
- | public class MyGenerator { | ||
- | private static final Identifier IGLOO_TOP = new Identifier(" | ||
- | |||
- | public static void addPieces(StructureManager manager, BlockPos pos, BlockRotation rotation, List< | ||
- | pieces.add(new MyPiece(manager, | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | 在'' | ||
- | |||
- | 我们现在// | ||
- | |||
- | 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> | ||
- | public static class MyPiece extends SimpleStructurePiece { | ||
- | private final BlockRotation rotation; | ||
- | private final Identifier template; | ||
- | |||
- | public MyPiece(StructureManager structureManager, | ||
- | super(ExampleMod.MY_PIECE, | ||
- | this.template = new Identifier(compoundTag.getString(" | ||
- | this.rotation = BlockRotation.valueOf(compoundTag.getString(" | ||
- | this.initializeStructureData(structureManager); | ||
- | } | ||
- | |||
- | public MyPiece(StructureManager structureManager, | ||
- | super(ExampleMod.MY_PIECE, | ||
- | this.pos = pos; | ||
- | this.rotation = rotation; | ||
- | this.template = template; | ||
- | |||
- | this.initializeStructureData(structureManager); | ||
- | } | ||
- | |||
- | private void initializeStructureData(StructureManager structureManager) { | ||
- | Structure structure = structureManager.getStructureOrBlank(this.template); | ||
- | StructurePlacementData placementData = (new StructurePlacementData()) | ||
- | .setRotation(this.rotation) | ||
- | .setMirror(BlockMirror.NONE) | ||
- | .addProcessor(BlockIgnoreStructureProcessor.IGNORE_STRUCTURE_BLOCKS); | ||
- | this.setStructureData(structure, | ||
- | } | ||
- | |||
- | protected void toNbt(CompoundTag tag) { | ||
- | super.toNbt(tag); | ||
- | tag.putString(" | ||
- | tag.putString(" | ||
- | } | ||
- | |||
- | @Override | ||
- | protected void handleMetadata(String metadata, BlockPos pos, ServerWorldAccess serverWorldAccess, | ||
- | BlockBox boundingBox) { | ||
- | } | ||
- | } | ||
- | </ | ||
- | | ||
- | '' | ||
- | This can be good for dynamic stuff such as placing certain mobs based on what mod is on and so on. | ||
- | |||
- | 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' | ||
- | < | ||
- | |||
- | We set the '' | ||
- | |||
- | ==== 注册功能 ==== | ||
- | |||
- | 最后一步是注册我们的功能。 我们需要注册: | ||
- | |||
- | * StructurePieceType | ||
- | * StructureFeature< | ||
- | * StructureFeature<?> | ||
- | |||
- | 我们还需要将结构添加到“结构”列表中,并将其添加到每个生物群系中,作为功能部件和生成步骤。 | ||
- | |||
- | 注册件类型: | ||
- | <code java> | ||
- | public static final StructurePieceType myStructurePieceType = Registry.register(Registry.STRUCTURE_PIECE, | ||
- | </ | ||
- | | ||
- | 注册功能: | ||
- | <code java> | ||
- | public static final StructureFeature< | ||
- | </ | ||
- | | ||
- | 注册结构: | ||
- | <code java> | ||
- | public static final StructureFeature<?> | ||
- | </ | ||
- | | ||
- | 要将功能放入功能列表,可以使用: | ||
- | <code java> | ||
- | Feature.STRUCTURES.put(" | ||
- | </ | ||
- | | ||
- | 对于测试,将功能注册到每个生物群系并将生成率设置为100%是个好主意,这样您就可以确保其生成并正常工作。 您可能不希望您的结构漂浮在水中,因此我们也将其过滤掉。 通过遍历生物群系列表并将其添加为特征和生成步骤,将其添加到每个生物群系: | ||
- | |||
- | <code java [enable_line_numbers=" | ||
- | for(Biome biome : Registry.BIOME) { | ||
- | if(biome.getCategory() != Biome.Category.OCEAN && biome.getCategory() != Biome.Category.RIVER) { | ||
- | biome.addStructureFeature(myFeature, | ||
- | biome.addFeature(GenerationStep.Feature.SURFACE_STRUCTURES, | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | ChanceDecoratorConfig的参数基本上是在生成之前将跳过多少个块。 0是每个块,1是彼此,并且100是每100。 | ||
- | |||
- | 您需要将结构添加为特征,以便您的生物群系知道其存在,然后作为生成步骤,以使其实际生成。 | ||
- | |||
- | 加载到您的世界中,如果一切顺利,应该会遇到// |
zh_cn/tutorial/structures.1627144461.txt.gz · Last modified: 2021/07/24 16:34 by solidblock