手册:实例/附加包/物品/武器

来自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"
		}
	}
}

远程武器[编辑]