Minecraft Wiki

除另有声明,转载时均必须注明出处若簡繁轉換出錯,請以遊戲內為準请勇于扩充与修正内容有兴趣逛逛我们的微博沟通交流,欢迎到社区专页需要协助,请在告示板留言

了解更多

Minecraft Wiki
Advertisement
Information icon
此特性为Java版基岩版独有。

命令/infobox

运行一个函数

语法
function <名称>
参数
名称
必须为函数名称或标签。函数名称和命名空间由数据包指定,如my_namespace:hellomy_namespace:123/456。命名空间省略时,默认为minecraft:。也可以是函数标签,如#minecraft:tick,同样当命名空间为minecraft:时可以省略命名空间。
效果
若参数未正确指定、所选的函数不存在(包括无效)或标签不存在(包括为空以及含有无效函数)时命令失败。
成功时,以实体或命令方块的身份运行指定的函数。
示例[仅Java版]
运行路径“/datapack/数据包名称/data/custom/functions/example/test.mcfunction”中的函数:/function custom:example/test
方圆2米内存在羊时运行函数:/execute if entity @e[type=sheep,distance=..2] run function custom:example/test
执行者不是玩家时,运行函数:/execute unless @s[type=player] run function custom:example/test
基岩版
1.8beta 1.8.0.8加入了/function
Advertisement