Translation notice
This page was translated with machine translation and may contain inaccuracies. If you can help improve it, please open an issue or submit a pull request.
mcfunction Language Specification (Simplified Version)
Editor's Note
This is a set of naming conventions used to make the data pack structure easier to read. It is not a grammar rule and is not checked by the game. Readers are not required to abide by the following conventions, but concise and standardized naming will obviously make the data pack cleaner and easier to read, and can also significantly improve development efficiency and maintainability. Therefore, readers are recommended to read it carefully.
basic principles
- Prefer short names.
- Names must not be ambiguous.
- When there is no actual conflict, no redundant levels will be added.
Field
Fields are a set of naming and data format conventions, which can also be understood as classes.
Any data, entity or block that conforms to the contract can be regarded as the object of this field.
For example,projectileFields can appear in:
score(@s projectile)
storage(<namespace>:io projectile)
storage(<namespace>:data projectile)
tag(<namespace>.projectile)
function <namespace>:projectile/createThe entity tag must be manually added with the namespace prefix:
tag(<namespace>.projectile)Properties and inheritance
Attributes represent part of the data of a field:
projectile.speed
projectile.lifeInheritance represents a complete type of field:
projectile.fire
projectile.iceWhen path conflicts occur in long-term data, add a layer of attributes, such asdefault、dummyorvalueWait, to eliminate the conflict. likecharacter.knight.max_healthandcharacter.max_healthconflict.character.max_healthshould be written ascharacter.default.max_health。
function structure
类/方法/中间过程For example:
projectile/create
projectile/create/validate
projectile/create/write_data
projectile/delete
...- Methods are allowed to be called outside the field.
- The intermediate process is like
projectile/create/write_data, only belongs tocreate, other functions cannot be called. - When multiple methods need to share the same intermediate process, promote it to a private method.
projectile/__validate
projectile/create
projectile/create/write_data
projectile/deleteThe structure can be changed to this. private method__validateallowprojectileAll methods within (onlycreateanddelete, excludingcreate/write_data) call, but not open outside the field.
special mark
Special markers are not part of the name. Tags should be ignored when determining name conflicts.
__tick__ 自动方法:由游戏特性或游戏内入口调用
__validate 私有方法:仅供当前字段内部调用
__id__ 长期变量:需要跨 tick 保存,不应随意修改__xx__,__xxandxxConsidered to have the same name, they can be created at the same time, but the functions must be exactly the same, such as:
# __a__
function a
# __a
function a
# a
say 1method input
Method inputs are read-only by default. When the input needs to be modified, it must be stated in the header document.
#> projectile/create
# 创建投射物
# @input
# storage <namespace>:io projectile
# @output
# 新创建的投射物or shorter:
#> projectile/create
# 创建投射物,输入为io projectileTemporary variable
Common temporary variables:
score(#temp <namespace>)
storage(<namespace>:io temp.projectile)
tag(<namespace>.this)
tag(<namespace>.init)After calling a normal method, existing temporary variables should be regarded as having unknown contents and should not be read further.
Private methods share variables with the caller and do not affect the call of temporary variables.
quick check
字段的一部分数据 属性
字段的一种完整类型 继承
允许字段外调用 方法
只属于一个方法 中间过程
允许同一字段内多个方法调用 私有方法
由游戏特性或游戏内入口调用 自动方法
跨 tick 保存且不应随意修改 长期变量
当前逻辑中短暂使用 临时变量