Skip to content

Simple block feature

The simple_block feature allows you to randomly place blocks in the world.

Configuration

The simple_block feature has a single option, to_place which is a BlockStateProvider that specifies which block states should be placed.

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

Example

As an example, here's the feature used to randomly place spore blossoms.

ConfiguredFeatures.kt
val SPORE_BLOSSOM = FeatureRegistry.registerConfiguredFeature(
    Machines,
    "spore_blossom",
    Feature.SIMPLE_BLOCK,
    SimpleBlockConfiguration(BlockStateProvider.simple(Blocks.SPORE_BLOSSOM))
)
PlacedFeatures.kt
val SPORE_BLOSSOM = FeatureRegistry.registerPlacedFeature(
    Machines,
    "spore_blossom",
    ConfiguredFeatures.SPORE_BLOSSOM,
    listOf(
        CountPlacement.of(25), // (1)!
        InSquarePlacement.spread(), // (2)!
        PlacementUtils.RANGE_BOTTOM_TO_MAX_TERRAIN_HEIGHT, // (3)!
        EnvironmentScanPlacement.scanningFor(Direction.UP, BlockPredicate.solid(), BlockPredicate.ONLY_IN_AIR_PREDICATE, 12), // (4)!
        RandomOffsetPlacement.vertical(ConstantInt.of(-1)), // (5)!
        BiomeFilter.biome() // (6)!
    )
)
  1. 25 attempts to place a spore blossom per chunk.
  2. Randomly offset the location horizontally.
  3. Set the y-coordinate to a random value up to 256. The static constant is equivalent to
    HeightRangePlacement.uniform(VerticalAnchor.bottom(), VerticalAnchor.absolute(256));
    
  4. Search up to 12 blocks above the randomly selected location for a solid block.
  5. Offset the location by -1 vertically.
  6. Only place spore blossoms in biomes that have the minecraft:spore_blossom feature.
configured_feature/spore_blossom.json
{
  "type": "minecraft:simple_block",
  "config": {
    "to_place": {
      "type": "minecraft:simple_state_provider",
      "state": {
        "Name": "minecraft:spore_blossom"
      }
    }
  }
}
placed_feature/spore_blossom.json
{
  "feature": "minecraft:spore_blossom",
  "placement": [
    {
      "type": "minecraft:count",
      "count": 25 // (1)!
    },
    {
      "type": "minecraft:in_square" // (2)!
    },
    {
      "type": "minecraft:height_range", // (3)!
      "height": {
        "type": "minecraft:uniform",
        "max_inclusive": {
          "absolute": 256
        },
        "min_inclusive": {
          "above_bottom": 0
        }
      }
    },
    {
      "type": "minecraft:environment_scan", // (4)!
      "allowed_search_condition": {
        "type": "minecraft:matching_blocks",
        "blocks": "minecraft:air"
      },
      "direction_of_search": "up",
      "max_steps": 12,
      "target_condition": {
        "type": "minecraft:solid"
      }
    },
    {
      "type": "minecraft:random_offset", // (5)!
      "xz_spread": 0,
      "y_spread": -1
    },
    {
      "type": "minecraft:biome" // (6)!
    }
  ]
}
  1. 25 attempts to place a spore blossom per chunk.
  2. Randomly offset the location horizontally.
  3. Set the y-coordinate to a random value up to 256.
  4. Search up to 12 blocks above the randomly selected location for a solid block.
  5. Offset the location by -1 vertically.
  6. Only place spore blossoms in biomes that have the minecraft:spore_blossom feature.

Example