你可以帮助我们来翻译此条目,但请勿使用机器翻译。
本教程介绍如何制作数据包。
入门
提示:本教程大约需要1到1.5个小时才能完成。'
数据包允许玩家自定义命令函数,掉落物,世界结构,成就和合成,这将改变这个游戏游戏。在安装之前,首先需要制作一个数据包。
不该做什么
在制作数据包之前,您不应该做一些事情。这是一个“不应该做”的列表:
- 做任何违反Mojang “Minecraft使用条款”的事情。
- 发布Minecraft版本或修改版本,允许玩家在没有从Mojang购买Minecraft'的情况下玩游戏。
- 以任何方式释放反编译的Minecraft'源代码。
创建数据包
要创建数据包,首先导航到世界文件夹中的datapacks文件夹。要查找世界文件夹,请在.minecraft中找到saves文件夹。
进入文件夹后,创建并打开一个文件夹并命名:Tutorial Data Pack。这是您的数据包的名称,可以是您想要的任何名称。
创建文件夹后要做的第一件事是创建pack.mcmeta文件。这让Minecraft知道该文件夹是一个数据包。
创建MCMETA文件
要创建MCMETA文件,请右键单击“Tutorial_Data_Pack”文件夹并创建一个新的文本文档。将此文件命名为“pack.mcmeta”。
要求
- 任何文本编辑器都可以使用,但建议的编辑器是Notepad++。它是一个开源的文本编辑器,具有许多编程语言的语法高亮,包括JSON,它是数据包中大多数文件的格式。
您可以从这里下载Notepad++:[1]
- 注意
在重命名时要确保文件扩展名为.mcmeta而非.txt。您可能会收到警告:更改文件扩展名可能会导致文件不可用。但是,不要担心这个消息;无论如何都该保持正确的文件扩展名。
如果您看不到文件扩展名,可以通过转到文件资源管理器的“查看”菜单并选中文件扩展名的复选框来打开它们。

pack.mcmeta
在您选择的文本编辑器中打开pack.mcmeta,复制或键入以下内容:
{
"pack": {
"pack_format": 1,
"description": "Tutorial Data Pack"
}
}
pack_format可以是任何数字,因为它当前没有强制执行。 description可以是任何字符串,并且会在/datapack list的输出中将鼠标悬停在数据包上时显示。
- 注意
这个文件是用JSON编写的!本教程现在没有详细介绍格式,但要注意事项的布局。 要小心,不要忘记引号,冒号,括号或方括号。缺少其中一个可能导致您的数据包无法正常工作!要检查您的文件,您可以使用JSON验证器,例如 JSONLint上的验证器。
数据
在你的数据包文件夹里创建一个叫做 data的文件夹, 和你放pack.mcmeta的文件夹在一个文件夹里。 在data文件夹里你需要创建你的namespace文件夹。
Minecraft中大部分的东西都是在命名空间里面的,因此如果一个Mod(或是地图,等等)被灌同时入游戏,它们会各自工作。
如果要命名某个东西(例如:战利品表),你也要说明它的命名空间,或使用默认的minecraft。 游戏本身就是用minecraft 命名空间,所以往里面加东西意味着覆盖已有的Minecraft数据。
如果要加入新的东西,应该用自己的命名空间。仅当覆盖其他东西,或是追加标签的时候,才使用其他命名空间。基本上,不要试图往minecraft命名空间里加薪东西。
命名空间和其他文件名称应该只含有以下字符:
• 0123456789 数字
• abcdefghijklmnopqrstuvwxyz 小写字母
• _ 下划线
• - 连字号(减号)
其他文件名称还可以有:
• / 正斜杠
• . 句点
建议的命名格式是:以下划线隔开的小写字母单词(lower_case_with_underscores)。
测试你的数据包
现在你已经建立好你的数据包了,在游戏中试试看吧!启动Minecraft,进入世界,输入/datapack list查看可用的数据包列表。应该有两条:第一条是“vanilla”,第二条是以“file/”开头。
无法正常工作?
如果你的数据包无法正常工作,再三确认pack.mcmeta 是正确的。如果它不正确,寻找缺失的花括号“{ }”,逗号“,”,冒号“:”,引号“ " " ”,方括号“[ ]”。要记得,每个左花括号、方括号、引号都要有对应的右花括号、方括号、引号。
函数
Functions are a set of commands that can be run in order.
To add functions, first create a folder named functions inside the namespace folder. Then, create a file named (function_name).mcfunction in this folder or in any of its subfolders. This will be your function file. Your function will be named in the game as (namespace):(name) or (namespace):(subfolder1)/(subfolder2)/.../(name) when the function file is located in a subfolder.
Loot tables
Loot tables will tell Minecraft what should be dropped when a mob dies or what should be generated inside containers, like chests, when opened for the first time.
To add loot tables, first create a folder named loot_tables inside the namespace folder. Then, create a file named (loot_table_name).json in this folder or in any of its subfolders. This will be your loot table file. Your loot table will be named in the game as (namespace):(name) or (namespace):(subfolder1)/(subfolder2)/.../(name) if the file is located in a subfolder.
Here is an example of a cow's loot table, it can be used as a reference:
{
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:leather",
"weight": 1,
"functions": [
{
"function": "set_count",
"count": {
"min": 0,
"max": 2
}
},
{
"function": "looting_enchant",
"count": {
"min": 0,
"max": 1
}
}
]
}
]
},
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:beef",
"weight": 1,
"functions": [
{
"function": "set_count",
"count": {
"min": 1,
"max": 3
}
},
{
"function": "furnace_smelt",
"conditions": [
{
"condition": "entity_properties",
"entity": "this",
"properties": {
"on_fire": true
}
}
]
},
{
"function": "looting_enchant",
"count": {
"min": 0,
"max": 1
}
}
]
}
]
}
]
}
To learn what each tag means, see 战利品表. There are also a list of vanilla loot tables on that page.
Structures
Structures can be used with 结构方块 and/or can overwrite how certain vanilla structures look in Minecraft. It is saved in an NBT format. You can create an NBT file by using a structure block or by exporting a build using a third party program like MCEdit.
To add structures to a data pack, first create a folder named structures inside the namespace folder. Then, put your structure file in this folder or in any of its subfolders. Your structure will be named in the game as (namespace):(name) or (namespace):(subfolder1)/(subfolder2)/.../(name) if the file is located in a subfolder.
Advancements
Advancements can be completed by players and give various rewards.
To add advancements, first create a folder named advancements inside the namespace folder. Then, create a file named (advancement_name).json in this folder or in any of its subfolders. This will be your advancement file. Your advancement will be named in the game as (namespace):(name) or (namespace):(subfolder1)/(subfolder2)/.../(name) if the file is located in a subfolder.
Recipes
Recipes are used to let players craft items.
To add recipes, first create a folder named recipes inside the namespace folder. Then, create a file named (recipe_name).json in this folder or in any of its subfolders. This will be your recipe file. Your recipe will be named in the game as (namespace):(name) or (namespace):(subfolder1)/(subfolder2)/.../(name) if the file is located in a subfolder.
Shaped crafting
The first common type of crafting is shaped crafting.
{
"type": "crafting_shaped",
"pattern": [
"123",
"231",
"312"
],
"key": {
"1": {
"item": "<item ID>"
},
"2": {
"item": "<item ID>"
},
"3": {
"item": "<item ID>"
}
},
"result": {
"item": "<item ID>",
"count": 5
}
}
This is a rough example of a shaped crafting recipe, as specified by the crafting_shaped type. pattern is a list used to specify the shape of the crafting recipe. It contains a maximum of 3 strings, each string standing for one row in the crafting grid. These strings then contain a maximum of 3 single characters next to eachother, each character standing for one spot in the crafting grid. You don't need all 3 strings, nor do you need to have 3 characters in each string. But each string should contain the same amount of characters. You can use spaces to indicate empty spots.
key is a compound used to specify what item should be used for which character in pattern. This can either be specified using item followed by an item ID or tag followed by an item datapack tag.
The result compound speaks for itself, it specified what the resulting item should be. count is used to specify how many of the item should be given.
This is the original recipe for a 活塞 (can be used as a reference):
{
"type": "crafting_shaped",
"pattern": [
"TTT",
"#X#",
"#R#"
],
"key": {
"R": {
"item": "minecraft:redstone"
},
"#": {
"item": "minecraft:cobblestone"
},
"T": {
"tag": "minecraft:planks"
},
"X": {
"item": "minecraft:iron_ingot"
}
},
"result": {
"item": "minecraft:piston"
}
}
Shapeless crafting
There's another common type of recipes, a shapeless recipe.
{
"type": "crafting_shapeless",
"ingredients": [
{
"item": "<item ID>"
},
{
"item": "<item ID>"
},
[
{
"item": "<item ID>"
},
{
"item": "<item ID>"
}
]
],
"result": {
"item": "<item ID>",
"count": 5
}
}
As specified by the crafting_shapeless type, this is a recipe without a pattern. The ingredients can be put in the crafting grid in any shape or form. In the example, there's a list inside the ingredients compound. This means any of the items in this list can be used.
This is the original recipe for 火焰弹 (can be used as a reference):
{
"type": "crafting_shapeless",
"ingredients": [
{
"item": "minecraft:gunpowder"
},
{
"item": "minecraft:blaze_powder"
},
[
{
"item": "minecraft:coal"
},
{
"item": "minecraft:charcoal"
}
]
],
"result": {
"item": "minecraft:fire_charge",
"count": 3
}
}
Tags
Tags are used to group blocks, items, or functions together. The minecraft:tick function tag is also used to run functions every tick.
To add tags, first create a folder named tags inside the namespace folder. Inside this folder, create folders named blocks, items and functions. Then, create a file named (tag_name).json in one of these folders or in any of their subfolders. This will be your tag file. Your tag will be named in the game as (namespace):(name) or (namespace):(subfolder1)/(subfolder2)/.../(name) if the file is located in a subfolder.
另见
| 组件 |
| ||
|---|---|---|---|
| 数据包 | |||
| 教程 | |||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||