Files
2025-08-25 18:36:29 +08:00

92 lines
2.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
front: https://nie.res.netease.com/r/pic/20211104/69055361-2e7a-452f-8b1a-f23e1262a03a.jpg
hard: 高级
time: 15分钟
---
# 了解搜索特征规则
本节中,我们继续一起了解搜索特征。我们尝试使用搜索特征为我们的橡树附着上我们之前在第十章中制作的自定义苹果方块,使其形成一个会结果实的橡树。
## 设置苹果单方块特征
我们还记得,我们的方块标识符为`tutorial_demo:apple`。我们新建一个单方块特征`apple_feature.json`
```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`文件:
```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`的数值时就会使该搜索特征放置判定失败。
我们在下一节中继续通过序列特征实现该搜索特征的放置。