Section
整合包作者
共 6 个一级导航项创建数据生成器
这页只回答一件事:如何写出一个可运行的数据生成器文件。整体概念见运行时数据生成系统 ,字段取值方式见占位符解析器。
放在哪里
生成器文件写在对应处理器的 generator/ 目录下,而不是直接改 assets/ 或 data/:
- 数据包:
[游戏目录]/croparia/datapack/generator/ - 资源包:
[游戏目录]/croparia/resourcepack/generator/
生成后的生成产物会分别落到:
- 数据包:
[游戏目录]/croparia/datapack/data/ - 资源包:
[游戏目录]/croparia/resourcepack/assets/
支持格式:
tomlcdgjson
推荐优先使用 toml。
最小示例
registry = "croparia:crops"
path = "example/recipes/${id.path}.json"
template = """
{
"type": "minecraft:crafting_shapeless",
"ingredients": [
{ "item": "${fruit}" }
],
"result": {
"id": "${seed}",
"count": 1
}
}
"""它表示:
- 遍历
croparia:crops - 为每个条目计算一次
path - 用当前条目填充
template - 生成多个独立文件
核心字段
registry:指定要遍历哪个生成条目集- 常见值:
croparia:cropscroparia:melonscroparia:elements
- 常见值:
path:指定生成产物的相对路径,本身也是一个模板- 示例:
path = "${id.namespace}/models/item/${seed.path}.json"template:指定最终写入的文件内容,本身也是模板字符串- 示例:
template = """
{
"parent": "croparia:item/template_seed"
}
"""-
type:指定生成器类型 -
startup:控制是否在服务器完全启动前参与生成 -
enabled:控制生成器是否启用,可临时停用但保留文件- 示例:
enabled = falsewhitelist- 用途:只为指定条目生成,而不是遍历整个
registry - 常见场景:调试、局部覆盖
- 示例:
- 用途:只为指定条目生成,而不是遍历整个
whitelist = ["croparia:coal", "croparia:iron"]生成器类型
普通生成器 croparia:generator
默认类型。一个条目通常生成一个文件;若目标路径重复,后写入者覆盖前者。
适合:
- 配方
- 模型
- 战利品表
- 方块状态
registry = "croparia:crops"
startup = true
path = "${id.namespace}/models/item/${seed.path}.json"
template = """
{
"parent": "croparia:item/template_seed"
}
"""聚合生成器 croparia:aggregated
先让每个条目生成一段 content,再统一塞进一个 template。适合标签文件等多条目合并成一个文件的场景
额外字段:
content
registry = "croparia:crops"
type = "croparia:aggregated"
startup = true
path = "croparia/tags/item/seeds/crops.json"
content = ' "${seed}"'
template = """
{
"replace": false,
"values": [
${content}
]
}
"""语言生成器 croparia:lang
面向可翻译条目,会按语言拆分输出,并注入可用占位符 _lang。
适合:
- 语言文件
registry = "croparia:crops"
type = "croparia:lang"
startup = true
path = "${id.namespace}/lang/${lang}.json"
template = '"${translation_key}": "${translations.get(_lang)}"'语言字段详见占位符解析器。
In This Page