# 了解搜索特征规则

本节中,我们继续一起了解搜索特征。我们尝试使用搜索特征为我们的橡树附着上我们之前在第十章中制作的自定义苹果方块,使其形成一个会结果实的橡树。

# 设置苹果单方块特征

我们还记得,我们的方块标识符为tutorial_demo:apple。我们新建一个单方块特征apple_feature.json

{
  "format_version": "1.13.0",
  "minecraft:single_block_feature": {
    "description": {
      "identifier": "tutorial_demo:apple_feature"
    },
	"places_block": "tutorial_demo:custom_apple",
    "enforce_survivability_rules": true,
    "enforce_placement_rules": true,
	"may_attach_to": {
      "auto_rotate": false,
      "min_sides_must_attach": 2,
      "top": {
        "name": "minecraft:leaves",
        "states": {
          "old_leaf_type": "oak"
        }
      },
      "west": {
        "name": "minecraft:leaves",
        "states": {
          "old_leaf_type": "oak"
        }
      },
      "north": {
        "name": "minecraft:leaves",
        "states": {
          "old_leaf_type": "oak"
        }
      },
      "east": {
        "name": "minecraft:leaves",
        "states": {
          "old_leaf_type": "oak"
        }
      },
      "south": {
        "name": "minecraft:leaves",
        "states": {
          "old_leaf_type": "oak"
        }
      }
    },
	"may_replace": [
      "minecraft:air"
    ]
  }
}

这里我们为其进行了严格的替换设置。我们期望一个苹果在上、前、后、左、右五个方向上至少有两个方向是连接像树叶的。这样,我们的苹果才会看起来是挂在橡树上一样,不至于特别突兀。

# 使用搜索特征连接苹果特征

我们新建apple_search_feature.json文件:

{
  "format_version": "1.13.0",
  "minecraft:search_feature": {
    "description": {
      "identifier": "tutorial_demo:apple_search_feature"
    },
    "places_feature": "tutorial_demo:apple_feature",
    "search_volume": {
      "min": [ -4, -16, -4 ],
      "max": [ 4, 0, 4 ]
    },
    "search_axis": "-y",
    "required_successes": 1
  }
}

我们这里从输入位置开始向Y轴负方向也就是向下开始搜索,当成功获取一个能够使苹果单方块特征tutorial_demo:apple_feature的位置时便停止搜索并放置该单方块特征。当找到的“能够使要放置的特征成功”的位置少于required_successes的数值时就会使该搜索特征放置判定失败。

我们在下一节中继续通过序列特征实现该搜索特征的放置。