快轉到主要內容

Minecraft Add-On 自訂實體掉落物與loot指令用法

分類   遊戲攻略 Minecraft
標籤   Minecraft Add-On Minecraft Command
🗓️ 民國110年 辛丑年
✍ 切換正體/簡體字
目錄

Minecraft基岩版的掉落物,或者說戰利品,都放在 原版行為包loot_tables資料夾,裡面含有大多數生物和寶箱的戰利品表,可自訂實體死亡掉落物或建築生成箱子的物品。

基岩版1.18.0.21加入了/loot指令,可用於生成掉落物。而生成掉落物的依據,就是這些戰利品表。

本文教學如何給實體、方塊、物品添加自訂掉落物,並討論各自的實現方式。

1. 戰利品表的格式
#

以殭屍的為例子:

行為包/loot_tables/entities/zombie.json內容

{
    "pools": [
        { //第一個物件
            "rolls": 1,
            "entries": [
                {
                    "type": "item",
                    "name": "minecraft:rotten_flesh",
                    "weight": 1,
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 0,
                                "max": 2
                            }
                        },
                        {
                            "function": "looting_enchant",
                            "count": {
                                "min": 0,
                                "max": 1
                            }
                        }
                    ]
                }
            ]
        },
        { //第二個物件,有條件
            "conditions": [
                {
                    "condition": "killed_by_player_or_pets"
                },
                {
                    "condition": "random_chance_with_looting",
                    "chance": 0.025,
                    "looting_multiplier": 0.01
                }
            ],
            "rolls": 1,
            "entries": [
                {
                    "type": "item",
                    "name": "minecraft:iron_ingot",
                    "weight": 1
                },
                {
                    "type": "item",
                    "name": "minecraft:carrot",
                    "weight": 1
                },
                {
                    "type": "item",
                    "name": "minecraft:potato",
                    "weight": 1
                }
            ]
        }
    ]
}

由上可知,一個pools裡面可以有多種情況,這裡有二個物件。

第一個物件的情況沒有任何條件,因此都會抽到,rolls是抽取次數。entries裡面可以寫會掉落的物品,weight是權重,functions可以給物品設定隨機數量或者附魔。

第二個物件,裡面有conditions,表明要滿足這二個條件之一(被玩家殺死或隨機掉落),才會掉落這些物品,而裡面就列出了會掉落的鐵錠、紅蘿蔔、馬鈴薯。

如果要掉落生怪蛋,可以使用set_actor_id

{
    "type": "item",
    "name": "minecraft:spawn_egg",
    "weight": 1,
    "functions": [
        {
            "function": "set_actor_id",
            "id": "newmob:mymob"
        }
    ]
}

2. /loot指令用法
#

格式:

/loot spawn <座標: x y z> loot <戰利品表: 字串> [<tool>:mainhand:offhand: 字串]

範例,掉落殭屍的戰利品,.json不用寫出來,指令預設是從loot_tables資料夾下去找戰利品表。

/loot spawn ~ ~ ~ loot "entities/zombie" mainhand

3. 自訂實體死亡後掉落物品
#

在實體的行為檔案添加minecraft:loot組件就可以指定死亡掉落的戰利品表。

例如指定使用mymob.json作為目前實體的戰利品:

"minecraft:loot": {
        "table": "loot_tables/entities/mymob.json"
      }

4. 方塊破壞後掉落物品
#

1.16.100之後的方塊可設定與方塊互動後觸發事件,因此可在方塊的json加入spawn_loot事件來生成掉落物:

{
    "format_version": "1.16.100",
    "minecraft:block": {
        "description": {
            "identifier": "newblock:test"
        },
        "components": {
            "minecraft:on_player_destroyed": { //玩家破壞後
                "event": "newblock:drop_loot",
                "target": "self"
            }
        },
        "events": {
            "newblock:drop_loot": {
                "spawn_loot": {
                    "table": "loot_tables/blocks/my_loot_table.json"
                }
            }
        }
    }
}

5. 物品使用後掉落物品
#

物品並沒有能掉落物品的事件,因此loot指令就派上用場了。

在物品的行為檔案加入spawn_loot組件,執行/loot指令:

{
    "format_version": "1.16.100",
    "minecraft:block": {
        "description": {
            "identifier": "newitem:test"
        },
        "components": {
            "minecraft:on_use": { //使用物品時
                "on_use": {
                    "event": "newitem:spawn_loot",
                    "target": "self"
                }
            }
        },
        "events": {
            "newitem:spawn_loot": {
                "run_command": { //執行指令
                    "command": [
                        "loot spawn ~ ~ ~ loot 'entities/my_loot_table' mainhand"
                    ],
                    "target": "self"
                }
            }
        }
    }
}

參考資料
#

相關文章

Add-On 自訂Minecraft NPC的對話框 & dialogue指令用法
分類   遊戲攻略 Minecraft
標籤   Minecraft Add-On Minecraft World Minecraft Command
Minecraft Add-On 實體 Properties的用法
分類   遊戲攻略 Minecraft
標籤   Minecraft Add-On
合成台方塊自訂UI|Minecraft基岩版Add-On模組製作教學
分類   遊戲攻略 Minecraft
標籤   Minecraft Add-On Minecraft Resource Pack

留言板

此處提供二種留言板。點選按鈕,選擇您覺得方便的留言板。要討論程式碼請用Giscus,匿名討論請用Disqus。

這是Giscus留言板,需要Github帳號才能留言。支援markdown語法,若要上傳圖片請貼Imgur或Postimages。您的留言會在Github Discussions向所有人公開。

這是Disqus留言板,您可能會看到Disqus強制投放的廣告。有時留言可能會被系統判定需審核,導致延遲顯示,請見諒。若要上傳圖片請貼Imgur或Postimages。