Class FabricStructureBuilder<FC extends net.minecraft.world.gen.feature.FeatureConfig,​S extends net.minecraft.world.gen.feature.StructureFeature<FC>>

java.lang.Object
net.fabricmc.fabric.api.structure.v1.FabricStructureBuilder<FC,​S>

public final class FabricStructureBuilder<FC extends net.minecraft.world.gen.feature.FeatureConfig,​S extends net.minecraft.world.gen.feature.StructureFeature<FC>> extends Object
A builder for registering custom structures.

Example usage:


 StructureFeature structure = new MyStructure(DefaultFeatureConfig.CODEC);
 ConfiguredStructureFeature<DefaultFeatureConfig, ? extends StructureFeature<DefaultFeatureConfig>> configuredStructure
     = structure.configure(new DefaultFeatureConfig());
 FabricStructureBuilder.create(new Identifier("mymod:mystructure"), structure)
     .step(GenerationStep.Feature.SURFACE_STRUCTURES) // required
     .defaultConfig(32, 8, 12345) // required
     .superflatFeature(configuredStructure)
     .register();
 

This class does not add structures to biomes for you, you have to do that yourself. You may also need to register custom structure pieces yourself.

  • Method Details

    • create

      public static <FC extends net.minecraft.world.gen.feature.FeatureConfig,​ S extends net.minecraft.world.gen.feature.StructureFeature<FC>> FabricStructureBuilder<FC,​S> create(net.minecraft.util.Identifier id, S structure)
      Creates a new FabricStructureBuilder for registering a structure.
      Parameters:
      id - The structure ID.
      structure - The StructureFeature you want to register.
    • step

      public FabricStructureBuilder<FC,​S> step(net.minecraft.world.gen.GenerationStep.Feature step)
      Sets the generation step of this structure. The generation step specifies when the structure is generated, to ensure they are generated in the correct order to reduce the amount of floating blocks.

      The most commonly used values for structures are GenerationStep.Feature.SURFACE_STRUCTURES and GenerationStep.Feature.UNDERGROUND_STRUCTURES, however technically any value in the GenerationStep.Feature enum may be used.

      This is a required option.

    • defaultConfig

      public FabricStructureBuilder<FC,​S> defaultConfig(net.minecraft.world.gen.chunk.StructureConfig config)
      Sets the default StructureConfig for this structure. See the alternative defaultConfig(int, int, int) for details.

      This is a required option.

    • defaultConfig

      public FabricStructureBuilder<FC,​S> defaultConfig(int spacing, int separation, int salt)
      Sets the default StructureConfig for this structure. This sets the default configuration of where in the world to place structures.

      Note: the spacing and separation options are subject to other checks for whether the structure can spawn, such as biome. If these checks always pass and the structure can spawn in every biome, then the description of these values below would be exactly correct.

      This is a required option. Vanilla needs it to function.

      Parameters:
      spacing - The average distance between 2 structures of this type along the X and Z axes.
      separation - The minimum distance between 2 structures of this type.
      salt - The random salt of the structure. This does not affect how common the structure is, but every structure must have an unique salt in order to spawn in different places.
      See Also:
      defaultConfig(StructureConfig)
    • superflatFeature

      public FabricStructureBuilder<FC,​S> superflatFeature(net.minecraft.world.gen.feature.ConfiguredStructureFeature<FC,​? extends net.minecraft.world.gen.feature.StructureFeature<FC>> superflatFeature)
      Sets the structure configuration which spawns in superflat worlds. If unset, this structure will not spawn in superflat worlds.
      See Also:
      superflatFeature(FeatureConfig)
    • superflatFeature

      public FabricStructureBuilder<FC,​S> superflatFeature(FC config)
      Sets the structure configuration which spawns in superflat worlds. If unset, this structure will not spawn in superflat worlds.
      See Also:
      superflatFeature(ConfiguredStructureFeature)
    • adjustsSurface

      public FabricStructureBuilder<FC,​S> adjustsSurface()
      Causes structure pieces of this structure to adjust the surface of the world to fit them, so that they don't stick out of or into the ground.
    • register

      public S register()
      Registers this structure and applies the other changes from the FabricStructureBuilder.