本站文本内容除另有声明外,均在知识共享 署名-非商业性使用-相同方式共享 3.0 协议下提供。(详情… 本站文本内容除另有声明外,均在知识共享 署名-非商业性使用-相同方式共享 3.0 协议下提供。(详情…中文Minecraft Wiki是完全公开的。欢迎持续参与翻译工作中文Minecraft Wiki是完全公开的。欢迎持续参与翻译工作Minecraft中文Wiki微博正在更新!或许有兴趣去看看Minecraft中文Wiki微博正在更新!或许有兴趣去看看翻译或创建页面之前,不妨看看译名标准化Wiki条例页面。翻译或创建页面之前,不妨看看译名标准化Wiki条例页面。想与其他用户进行编辑上的沟通?社区专页正是为此创建的。想与其他用户进行编辑上的沟通?社区专页正是为此创建的。需要管理员的协助?在管理员告示板留言也许可以帮到您。需要管理员的协助?在管理员告示板留言也许可以帮到您。

教程/制作数据包

来自Minecraft Wiki
跳转至: 导航搜索
Java Edition.png
Ic translate.svg
此页面的(部分)内容需要被翻译。
你可以帮助我们来翻译此页面

本教程介绍如何制作数据包

入门[编辑 | 编辑源代码]

提示:本教程大约需要1到1.5个小时才能完成。'

数据包允许玩家自定义命令函数掉落物,世界结构成就合成,这将改变这个游戏游戏。在安装之前,首先需要制作一个数据包。

不该做什么[编辑 | 编辑源代码]

在制作数据包之前,您不应该做一些事情。这是一个“不应该做”的列表:

  • 做任何违反MojangMinecraft使用条款”的事情。
  • 发布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您可能会收到警告:更改文件扩展名可能会导致文件不可用。但是,不要担心这个消息;无论如何都该保持正确的文件扩展名。

如果您看不到文件扩展名,可以通过转到文件资源管理器的“查看”菜单并选中文件扩展名的复选框来打开它们。

FileExtensions.png

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文件夹。 Most things in the game have a namespace, so that if both, something and a mod (or map, or whatever) are added to the game, they both act as different "somethings".

Whenever you're asked to name something, for example, a loot table, you're expected to also provide what namespace that thing comes from. If you don't specify the namespace it will be minecraft by default. The game uses the minecraft namespace, which means that this namespace should be used when the data pack needs to overwrite existing Minecraft data.

Make sure to always use your own namespace for anything new that you add, and only use other namespaces if you're explicitly overriding something else, or in the case of tags appending to something else. Basically, try not to add new things in minecraft. Namespace and other folder and file names in the data pack should only contain the following symbols:

0123456789 Numbers

abcdefghijklmnopqrstuvwxyz Lowercase letters

_ Underscore

- Hyphen/minus

/ Forward Slash/Directory separator (Can't be used in namespace)

. Period (Can't be used in namespace)

The preferred naming convention is lower_case_with_underscores.

Testing your Pack[编辑 | 编辑源代码]

Once you have created your data pack, try testing it out in-game! Launch Minecraft and open the world, then type /datapack list. It should say two things. One is for “vanilla”, the second one should start with “file/”.

Troubleshooting[编辑 | 编辑源代码]

If you don’t see your pack working, make sure your pack.mcmeta is correct. If it isn't, look for any missing curly braces { }, commas, colons :, quotation marks “”, or square brackets [ ]. Remember that for each open brace, quotation, or square bracket, you must have a closing brace, quotation, or square bracket.

函数[编辑 | 编辑源代码]

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.

另见[编辑 | 编辑源代码]