zh_cn:tutorial:structures
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
zh_cn:tutorial:structures [2020/02/04 10:48] – [Creating a Feature] lightcolour | zh_cn:tutorial:structures [2022/09/29 05:27] (current) – 已过时 solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== 生成结构 ====== | ||
- | ===== 特征 ===== | ||
- | |||
- | 本教程中使用的所有代码都可以在此处获得: | ||
- | |||
- | ==== 介绍 ==== | ||
- | |||
- | 我们将研究如何在您的世界中注册和放置结构。 | ||
- | |||
- | 要查看实际使用的1.14原版结构的示例,IglooGenerator和IglooFeature是一个良好的开端。 | ||
- | |||
- | 对于最基本的结构,您将需要一个功能部件和生成器。 该功能处理在生成世界时注册结构并将其加载的过程-回答诸如“我应该在这里生成吗?”和‘我叫什么名字?’之类的问题,生成器处理块的放置或加载 结构文件(如果您选择这样做)。 | ||
- | ==== 创建特征 ==== | ||
- | |||
- | 要创建基本功能,我们建议创建一个扩展AbstractTempleFeature < | ||
- | |||
- | * shouldStartAt:出于测试目的,返回true。 | ||
- | * getName:您的结构的名称 | ||
- | * getRadius:结构的半径,用于放置 | ||
- | * getSeeedModifier | ||
- | |||
- | 您可以将DefaultFeatureConfig :: deserialize传递给构造函数进行测试。 | ||
- | |||
- | 对于getStructureStartFactory,大多数原始结构会创建一个在其Feature类中扩展StructureStart的类: | ||
- | |||
- | <code java [enable_line_numbers=" | ||
- | public static class MyStructureStart extends StructureStart { | ||
- | public MyStructureStart (StructureFeature<?> | ||
- | super(structureFeature_1, | ||
- | } | ||
- | @Override | ||
- | public void initialize(ChunkGenerator<?> | ||
- | DefaultFeatureConfig defaultFeatureConfig = chunkGenerator.getStructureConfig(biome, | ||
- | 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, | ||
- | this.setBoundingBoxFromChildren(); | ||
- | } | ||
- | } | ||
- | </ | ||
- | | ||
- | 当世界尝试以新结构生成时,这称为“要素”和“生成器”之间的差距。 在您的主类中对该变量的引用尚不存在,但我们将在最后创建它。 您也可以将配置设置为等于新的DefaultFeatureConfig。 您可以在getStructureStartFactory中使用返回MyStructureStart :: new返回此函数。 | ||
- | 这是结构文件和直接从generate方法生成的部分方式。 有两种解决方法: | ||
- | |||
- | | ||
- | | ||
- | |||
- | ==== Creating a Generator ==== | ||
- | |||
- | As you have probably noticed, we need to create a generator. We'll name it MyGenerator, | ||
- | |||
- | * An Identifier that points to your structure file; use " | ||
- | * Some sort of setup method - addParts is a good name: | ||
- | |||
- | <code java> | ||
- | public static void addParts(StructureManager structureManager_1, | ||
- | List< | ||
- | | ||
- | } | ||
- | </ | ||
- | | ||
- | In your addParts method, you can choose which structure pieces are added to your generation process. You can add a piece like this: | ||
- | |||
- | <code java> | ||
- | list_1.add(new MyGenerator.Piece(structureManager_1, | ||
- | </ | ||
- | | ||
- | 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, | ||
- | |||
- | <code java [enable_line_numbers=" | ||
- | public static class Piece extends SimpleStructurePiece { | ||
- | private Rotation rotation; | ||
- | private Identifier template; | ||
- | | ||
- | public Piece(StructureManager structureManager_1, | ||
- | super(MyModClass.myStructurePieceType, | ||
- | | ||
- | this.pos = blockPos_1; | ||
- | this.rotation = rotation_1; | ||
- | this.template = identifier_1; | ||
- | | ||
- | this.setStructureData(structureManager_1); | ||
- | } | ||
- | | ||
- | public Piece(StructureManager structureManager_1, | ||
- | super(MyModClass.myStructurePieceType, | ||
- | this.identifier = new Identifier(compoundTag_1.getString(" | ||
- | this.rotation = Rotation.valueOf(compoundTag_1.getString(" | ||
- | this.setStructureData(structureManager_1); | ||
- | } | ||
- | | ||
- | @Override | ||
- | protected void toNbt(CompoundTag compoundTag_1) { | ||
- | super.toNbt(compoundTag_1); | ||
- | compoundTag_1.putString(" | ||
- | compoundTag_1.putString(" | ||
- | } | ||
- | | ||
- | 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, | ||
- | } | ||
- | | ||
- | @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, | ||
- | | ||
- | } | ||
- | } | ||
- | </ | ||
- | | ||
- | 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. | ||
- | |||
- | 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: | ||
- | |||
- | <code java [enable_line_numbers=" | ||
- | @Override | ||
- | public boolean generate(IWorld iWorld_1, Random random_1, MutableIntBoundingBox mutableIntBoundingBox_1, | ||
- | int yHeight = iWorld_1.getTop(Heightmap.Type.WORLD_SURFACE_WG, | ||
- | this.pos = this.pos.add(0, | ||
- | 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 the structure off that position. | ||
- | |||
- | ==== Registering Features ==== | ||
- | |||
- | The last step is to register our features. We're going to need to register: | ||
- | |||
- | * StructurePieceType | ||
- | * 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> | ||
- | public static final StructurePieceType myStructurePieceType = Registry.register(Registry.STRUCTURE_PIECE, | ||
- | </ | ||
- | | ||
- | Registering feature: | ||
- | <code java> | ||
- | public static final StructureFeature< | ||
- | </ | ||
- | | ||
- | Registering structure: | ||
- | <code java> | ||
- | public static final StructureFeature<?> | ||
- | </ | ||
- | | ||
- | To put your feature in the features list, you can use: | ||
- | <code java> | ||
- | 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: | ||
- | |||
- | <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' | ||
- | |||
- | 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.1580813303.txt.gz · Last modified: 2020/02/04 10:48 by lightcolour