zh_cn:tutorial:structures_old
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| zh_cn:tutorial:structures_old [2024/08/25 13:41] – removed - external edit (Unknown date) 127.0.0.1 | zh_cn:tutorial:structures_old [2024/08/25 13:52] (current) – ↷ Links adapted because of a move operation 52.167.144.180 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== 添加结构地物 [1.16.3] ====== | ||
| + | :!: //**对于 1.18 以上版本,Fabric Structure API 不再存在,结构可完全由数据包完成。请参阅 [[https:// | ||
| + | :!: 本页的翻译质量不佳。如果需要给旧版本添加结构地物,可阅读[[tutorial: | ||
| + | |||
| + | 现在,往世界中注册并放置一些结构。 | ||
| + | |||
| + | 如要查看原版结构的实例,可以从简单的 '' | ||
| + | |||
| + | 对于大多数基本的结构,你需要地物(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. | ||
| + | |||
| + | 本教程中,使用结构文件,不需要覆盖任何内容,但确实需要: | ||
| + | * 指向结构文件的 ID,例如 ''" | ||
| + | * 一些安装方法——例如 '' | ||
| + | |||
| + | <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。 | ||
| + | |||
| + | 您需要将结构添加为特征,以便您的生物群系知道其存在,然后作为生成步骤,以使其实际生成。 | ||
| + | |||
| + | 加载到您的世界中,如果一切顺利,应该会遇到// | ||