手冊:實例/附加包/物品/武器

出自Minecraft基岩版开发Wiki

{

   "format_version": "1.16.100",
   "minecraft:item": {
       "description": {
           "identifier": "wiki:my_sword",
           "category": "equipment"
       },
       "components": {
           "minecraft:creative_category": {
               "parent": "itemGroup.name.sword"
           },
           "minecraft:max_stack_size": 1,
           "minecraft:hand_equipped": true,
           "minecraft:durability": {
               "max_durability": 600
           },
           "minecraft:damage": 10,
           "minecraft:enchantable": {
               "value": 10,
               "slot": "sword"
           },
           "minecraft:icon": {
               "texture": "my_sword"
           },
           "minecraft:display_name": {
               "value": "我的自定义剑"
           },
           "minecraft:repairable": {
               "repair_items": [{
                   "items": "minecraft:stick",
                   "repair_amount": "context.other->query.remaining_durability + 0.05 * context.other->query.max_durability"
               }]
           }
       }
   }

}

引言[編輯]

自1.16.100以來,製作自訂武器變得非常簡單。你只需要這些簡單地在資料夾中定義一個物品JSON檔案,並在資料夾中提供相應的紋理,就能擁有一個屬於自己的武器。

近戰武器[編輯]

行為包[編輯]

基本程式碼[編輯]

我們先自訂一個簡單的近戰武器,在行为包/items資料夾下新建一個名為custom_sword.json的檔案,插入如下內容:

{
	"format_version": "1.16.100",
	"minecraft:item": {
		"description": {
			"identifier": "wiki:custom_sword",
			"category": "equipment"
		},
		"components": {
			// 此组件将这个物品加入创造模式物品栏的“剑”分组
			"minecraft:creative_category": {
				"parent": "itemGroup.name.sword"
			},
			// 将最大堆叠设为1
			"minecraft:max_stack_size": 1,
			// 使纹理像工具一样竖直显示
			"minecraft:hand_equipped": true,
			"minecraft:durability": {
				"max_durability": 500// 耐久,这里设置为500
			},
			// 该物品的伤害
			"minecraft:damage": 10,
			// 此组件使该物品可以被附魔
			"minecraft:enchantable": {
				"value": 15,// 这里的数值越大附魔台出的附魔越好
				"slot": "sword"
			},
			// 该物品使用的纹理,填纹理短名称
			"minecraft:icon": {
				"texture": "wiki.custom_sword"
			},
			// 使其可以被自身与wiki:custom_item修复
			"minecraft:repairable": {
				"repair_items": [
					{
						"items": "wiki:custom_item",
						"repair_amount": "context.other->q.remaining_durability + 0.05 * context.other->q.max_durability"
					},
					{
						"items": "wiki:custom_sword",
						"repair_amount": "context.other->q.remaining_durability + 0.05 * context.other->q.max_durability"
					}
				]
			}
		}
	}
}

耐久[編輯]

在1.16.100中,資料驅動的耐久系統產生很大的變更,我們需要自己設定事件來實現耐久的掉落。

資源包[編輯]

按照Manual:製作附加包/物品中所述方法為這個物品註冊紋理與名稱:

{
	"resource_pack_name": "实例资源包",
	"texture_name": "atlas.items",
	"texture_data": {
	    // 纹理短名称,应该与minecraft:icon组件所填的值一致
		"wiki.custom_sword": {
			// 该物品纹理的路径,不带后缀名
			"textures": "textures/items/custom_sword"
		}
	}
}

遠程武器[編輯]