外观
氛围动效
外观
氛围动效
命名空间是数据包中隔离内容的核心机制。所有数据包内容(物品、方块、函数、战利品表等)都由 命名空间:路径 格式的 ID 唯一标识。
miragedge:my_sword # miragedge 命名空间下的 my_sword
minecraft:stick # 原版命名空间下的 stick关键规则:
a-z、0-9、_、-)miragedgenamespace:id,如 miragedge:ruby_swordpack_format 是 pack.mcmeta 中的版本号,告知 Minecraft 该数据包兼容的游戏版本。版本不匹配将导致警告,但不阻止加载。
自 MC 1.21.9 起,Mojang 引入了 min_format / max_format 范围字段,逐步取代单一的 pack_format。Leaf 26.1.2 服务端对这两个字段有强制要求(详见参考页的 Leaf pack.mcmeta 严格校验规则)。
不要混用整数和数组格式
pack_format / min_format / max_format 三个字段必须使用同一种格式:
101、82、107101.1 等):[101, 1]错误示例(Leaf 会报错):
{
"pack": {
"pack_format": 101,
"min_format": 101,
"max_format": [101, 1] // ❌ min 是整数、max 是数组,不一致
}
}Leaf 26.1.2(pack_format 101)推荐写法:
{
"pack": {
"description": "MiragEdge Custom Data Pack",
"pack_format": 101,
"min_format": 82,
"max_format": 107
}
}为什么 min_format 是 82 而不是 101? 因为 Leaf 规定:当
min_format落在 17-81(legacy 区间)时,必须额外提供已弃用的supported_formats字段;而supported_formats在 pack_format 82+ 又必须移除——会陷入死循环。min_format必须设成 82 或更大才能避开这个陷阱。详见参考页的 Leaf pack.mcmeta 严格校验规则。
数据包中绝大多数配置文件使用 JSON 格式。AI 辅助开发时需注意:
// 或 /* */)Name 与 name 是不同的键mcfunction 文件是 .mcfunction 扩展名的纯文本文件,每行一条 Minecraft 命令,以 # 开头表示注释。
# 这是一个注释
say Hello, World!
give @a minecraft:diamond 1
execute as @a run say I am a player!关键语法元素:
| 元素 | 说明 | 示例 |
|---|---|---|
@p | 最近玩家 | give @p diamond 1 |
@a | 所有玩家 | say @a Hello |
@s | 当前执行实体 | execute as @p run say @s |
@e | 所有实体 | kill @e[type=creeper] |
@r | 随机玩家 | give @r emerald 1 |
速查链接:Minecraft 命令参考
推荐使用 Spyglass(前身为 Datapack Helper Plus,简称 DHP),这是目前最成熟的 MC 数据包开发扩展。
安装方式:
SPGoding.datapack-language-serverCtrl+P 输入 ext install SPGoding.datapack-language-server核心功能:
工作区配置:将数据包根文件夹(包含 pack.mcmeta 和 data/ 的目录)作为 VSCode 工作区根目录以获得最佳体验。
版本覆盖:如果需要为目标版本与实际不同的数据包提供智能提示,在工作区根目录创建 spyglass.json:
{
"env": {
"gameVersion": "26.1.2"
}
}Misode 是功能最全面的数据包在线生成器,支持:
核心优势:提供结构化的表单编辑界面,实时预览,支持导出为完整数据包项目。推荐优先使用 Misode 生成初始 JSON,再手动调整细节。
MCStacker 是命令生成器,特别适合生成复杂的 /give、/summon、/loot 等命令。支持 Minecraft 26.1+ 最新版本。
典型用途:
/give 命令测试 CE 物品/loot 命令测试战利品表建议创建一个独立的超平坦创造模式世界用于开发测试:
# 在服务器控制台创建测试世界(若有 Multiverse 等插件)
# 或在单人客户端创建后上传至服务器 datapacks/ 目录测试世界要求:
datapacks/ 目录miragedge-datapack/
├── pack.mcmeta # 数据包元数据(必需)
├── pack.png # 数据包图标(可选,256×256)
└── data/
└── miragedge/ # 命名空间目录
├── function/ # mcfunction 函数文件
│ ├── load.mcfunction # 加载时执行
│ ├── tick.mcfunction # 每 tick 执行
│ ├── test_<module>.mcfunction # 测试函数
│ └── <category>/ # 按功能分类的子目录
├── loot_table/ # 战利品表
│ ├── blocks/ # 方块掉落
│ ├── entities/ # 生物掉落
│ └── chests/ # 箱子战利品
├── recipe/ # 原版合成配方
├── advancement/ # 进度
├── predicate/ # 谓词(条件判断)
├── item_modifier/ # 物品修饰器
├── tag/ # 标签(合并机制)
│ ├── item/ # 物品标签
│ ├── block/ # 方块标签
│ ├── entity_type/ # 实体类型标签
│ ├── function/ # 函数标签(用于 tick/load 调度)
│ └── damage_type/ # 伤害类型标签
└── structure/ # 结构 NBT 模板
└── *.nbt| 类型 | 规范 | 示例 |
|---|---|---|
| 文件/目录名 | 小写字母 + 下划线 | loot_table/blocks/ruby_ore.json |
| 函数名 | namespace:path/to/function | miragedge:test_weapon_give |
| 战利品表路径 | 反映来源类型 | entities/zombie_king.json |
| 标签路径 | 与原版对应 | tag/item/weapons.json |
| CE 物品 ID | namespace:snake_case_name | miragedge:flame_sword |
{
"pack": {
"description": "MiragEdge Custom Data Pack",
"pack_format": 101,
"min_format": 82,
"max_format": 107
}
}{
"pack": {
"description": "MiragEdge Custom Data Pack",
"pack_format": [101, 1],
"min_format": [82, 0],
"max_format": [107, 0]
}
}{
"pack": {
"description": "MiragEdge Custom Data Pack",
"pack_format": 34
}
}不要使用 supported_formats 字段
在 Leaf 26.1.2 中,supported_formats 字段从 pack_format 82 起被弃用,保留会导致启动报错。请使用 min_format + max_format 替代。