Minecraft Wiki

除另有声明,转载时均必须注明出处若簡繁轉換出錯,請以遊戲內為準请勇于扩充与修正内容有兴趣逛逛我们的微博沟通交流,欢迎到社区专页需要协助,请在告示板留言

了解更多

Minecraft Wiki
Advertisement
Information icon
此特性為Java版獨有。
Ic translate
此條目的(部分)內容需要翻譯。

你可以幫助我們來翻譯此條目,但請勿使用機器翻譯

本教學介紹如何製作數據包

入門

提示:本教學大約需要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,它是Datapack中大多數檔案的格式。

你可以從這裏下載Notepad++:[1]

注意

確保檔案擴展名為.mcmeta而不是.txt 重新命名時。您可能會收到警吿,變更檔案擴展名可能會導致檔案無法使用。但是,不要擔心這個訊息,無論如何保持正確的檔案擴展名。

如果您看不到檔案擴展名,可以透過轉到檔案資源管理器的「查看」選單並選中檔案擴展名的選取方格來打開它們。

FileExtensions

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.

也可以看看

Advertisement