--- front: https://nie.res.netease.com/r/pic/20211104/69055361-2e7a-452f-8b1a-f23e1262a03a.jpg hard: 高级 time: 15分钟 --- # 了解自定义聚合特征规则 我们承接前面的蓝色蕨散植特征,我们希望将这种特征和橡树相结合,生成一种树荫下带有蓝色蕨簇的橡树,我们此时需要使用聚合特征。 ## 使用聚合特征连接蕨类与树木 我们建立`oak_tree_with_blue_fern_cluster_feature.json`文件,并填充如下: ```json { "format_version": "1.13.0", "minecraft:aggregate_feature": { "description": { "identifier": "tutorial_demo:oak_tree_with_blue_fern_cluster_feature" }, "early_out": "first_failure", "features": [ "minecraft:oak_tree_feature", "tutorial_demo:blue_fern_cluster_feature" ] } } ``` 聚合特征会使列表中的特征全部以同一个起始点为输入点,也就是自己的输入点为输入点来放置多个特征。比如这里我们将橡树特征和蓝色蕨簇特征以同一个点为基础放置。橡树的输入点在树根部,而散植特征则是围绕输入点在周围多次散植,因此我们可以营造一种树荫下带有蓝色蕨簇的橡树。 `early_out`指定了何时退出本次特征放置,`first_failure`代表在列表中出现第一个判定失败的特征时便退出本次放置。但是这并不意味着本次聚合特征放置也会失败。聚合特征的判定为列表中只要有至少一个特征放置成功便是成功。注意,聚合特征的放置列表的顺序并不一定是实际放置的顺序,其顺序不能得到保证。 ## 挂接特征规则 我们建立`overworld_oak_tree_with_blue_fern_cluster_feature.json`文件。 ```json { "format_version": "1.13.0", "minecraft:feature_rules": { "description": { "identifier": "tutorial_demo:overworld_oak_tree_with_blue_fern_cluster_feature", "places_feature": "tutorial_demo:oak_tree_with_blue_fern_cluster_feature" }, "conditions": { "placement_pass": "surface_pass", "minecraft:biome_filter": [ { "any_of": [ { "test": "has_biome_tag", "operator": "==", "value": "overworld" }, { "test": "has_biome_tag", "operator": "==", "value": "overworld_generation" } ] } ] }, "distribution": { "iterations": 5, "x": { "distribution": "uniform", "extent": [ 0, 16 ] }, "y": "query.heightmap(variable.worldx, variable.worldz)", "z": { "distribution": "uniform", "extent": [ 0, 16 ] } } } } ``` 并进入游戏查看效果。 ![](./images/16.6_fern_tree_in-game.png) 我们可以看到,确实出现了很多与橡树伴随生成的蓝色蕨!