Skip to content

Random selector feature

The random_selector feature can be used to randomly choose from a provided list of features to place.

Configuration

The random_selector feature has the following configuration options:

Option Type Description
features A list of placed features objects (or id's inside the feature option in Json) and their corresponding chance. The list of features to choose from.
default A placed feature The default feature to place if none of the provided features got picked

In code, the RandomFeatureConfiguration class is used to configure the feature.

Example

As an example, here's the random selector used to generate tree in the old growth taiga biome

ConfiguredFeatures.kt
@OptIn(ExperimentalWorldGen::class)
@Init(stage = InitStage.POST_PACK_PRE_WORLD)(stage = InitStage.POST_PACK_PRE_WORLD)
object ConfiguredFeatures : FeatureRegistry by ExampleAddon.registry {

    val TREES_OLD_GROWTH_SPRUCE_TAIGA = registerConfiguredFeature(
        "trees_old_growth_spruce_taiga",
        Feature.RANDOM_SELECTOR,
        RandomFeatureConfiguration(
            listOf(
                WeightedPlacedFeature(
                    VanillaRegistryAccess.getHolder(TreePlacements.MEGA_SPRUCE_CHECKED), 
                    1f / 3f 
                ),
                WeightedPlacedFeature(
                    VanillaRegistryAccess.getHolder(TreePlacements.PINE_CHECKED),
                    1f / 3f 
                )
            ),
            VanillaRegistryAccess.getHolder(TreePlacements.SPRUCE_CHECKED) 
        )
    )

}
configured_feature/trees_old_growth_spruce_taiga.json
{
  "type": "minecraft:random_selector",
  "config": {
    "features": [
      { 
        "chance": 0.33333334,
        "feature": "minecraft:mega_spruce_checked" 
      },
      { 
        "chance": 0.33333334,
        "feature": "minecraft:pine_checked"
      }
    ],
    "default": "minecraft:spruce_checked" 
  }
}

Example