Skip to content

Random patch feature

The random_patch feature can be used to place a feature in a random pattern multiple times. It's mostly used for vegetation and even has 2 more features for flowers: flower and no_bonemeal_flower. Their configuration is the same as therandom_patch feature, but flower features will also be used when applying bonemeal to grass blocks. no_bonemeal_flower only exists to make distinguishing it from other random_patch features easier.

Configuration

The following configuration options are available:

Option Type Description
tries (optional in Json, defaults to 128) A positive int. The amount of times the feature will try to generate.
xz_spread (optional in Json, defaults to 7) A positive int. The maximum horizontal distance from the center of the feature.
y_spread (optional in Json, defaults to 3) A positive int. The maximum vertical distance from the center of the feature.
feature The placed feature (in Json, this can also be the id of the placed feature if registered elsewhere) The placed feature to generate.

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

Example

As an example, here's the random patch used to generate dead bushes in the badlands biome:

Minecraft offers a few util functions in the FeatureUtils class to make the creation of the RandomPatchConfiguration easier.

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

    val PATCH_DEAD_BUSH = registerConfiguredFeature(
        "patch_dead_bush",
        Feature.RANDOM_PATCH,
        FeatureUtils.simpleRandomPatchConfiguration( 
            4, // tries
            PlacementUtils.onlyWhenEmpty( 
                Feature.SIMPLE_BLOCK,
                SimpleBlockConfiguration(BlockStateProvider.simple(Blocks.DEAD_BUSH)) 
            )
        )
    )

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

    val PATCH_DEAD_BUSH = placedFeature("patch_dead_bush", ConfiguredFeatures.PATCH_DEAD_BUSH)
        .count(20) 
        .inSquareSpread() 
        .moveToWorldSurface() 
        .biomeFilter() 
        .register()

}
configured_feature/patch_dead_bush.json
{
  "type": "minecraft:random_patch",
  "config": {
    "feature": { 
      "feature": { 
        "type": "minecraft:simple_block",
        "config": {
          "to_place": {
            "type": "minecraft:simple_state_provider",
            "state": {
              "Name": "minecraft:dead_bush"
            }
          }
        }
      },
      "placement": [
        {
          "type": "minecraft:block_predicate_filter",
          "predicate": {
            "type": "minecraft:matching_blocks",
            "blocks": "minecraft:air"
          }
        }
      ]
    },
    "tries": 4,
    "xz_spread": 7,
    "y_spread": 3
  }
}
placed_feature/patch_dead_bush_badlands.json
{
  "feature": "minecraft:patch_dead_bush",
  "placement": [
    {
      "type": "minecraft:count",
      "count": 20 
    },
    {
      "type": "minecraft:in_square" 
    },
    {
      "type": "minecraft:heightmap",
      "heightmap": "WORLD_SURFACE_WG" 
    },
    {
      "type": "minecraft:biome" 
    }
  ]
}

Result

Example