Skip to content

物品入门指南

本页面镜像自
BedrockWiki

根据原始项目协议授权。本文经过AI翻译处理,如有内容遗漏,可以提交PR进行补充。

Minecraft 基岩版允许我们在世界中添加具有多种原版特性的自定义物品。

本教程将介绍如何为稳定版 Minecraft 创建基础物品。

注册物品

物品定义的结构与实体类似:包含描述信息和定义物品行为的组件列表。

以下是让自定义物品出现在创造模式物品栏的最低限度行为端代码。

json
{
    "format_version": "1.20.50",
    "minecraft:item": {
        "description": {
            "identifier": "wiki:custom_item",
            "menu_category": {
              "category": "construction"
            }
        },
        "components": {} // 必须存在,即使为空!
    }
}

物品描述

  • 定义物品唯一标识符,格式为 命名空间:标识符
  • 配置物品在哪个menu_category分组显示
    • 可额外设置group分组和is_hidden_in_commands是否隐藏于命令提示

添加组件

当前我们的自定义物品使用的是默认组件值(详见物品组件文档)。

现在让我们配置自定义功能!

json
{
    "format_version": "1.20.50",
    "minecraft:item": {
        "description": {
            "identifier": "wiki:custom_item",
            "menu_category": {
                "category": "construction"
            }
        },
        "components": {
            "minecraft:damage": {
                "value": 10
            },
            "minecraft:durability":{
                "max_durability": 36
            },
            "minecraft:hand_equipped": {
                "value": true
            }
        }
    }
}

查看完整物品组件列表请访问物品组件文档

应用纹理

我们需要在RP/textures/item_texture.json中创建纹理简称来关联图片。

json
{
    "resource_pack_name": "wiki",
    "texture_name": "atlas.items",
    "texture_data": {
        "custom_item": {
            "textures": "textures/items/custom_item"
        }
    }
}

在物品文件中添加minecraft:icon组件来应用纹理。

json
{
    "format_version": "1.20.50",
    "minecraft:item": {
        "description": {
            "identifier": "wiki:custom_item",
            "menu_category": {
                "category": "construction"
            }
        },
        "components": {
            "minecraft:icon": {
                "texture": "custom_item"
            }
        }
    }
}

定义名称

最后为物品添加名称。你还可以使用显示名称组件

c
tile.wiki:custom_item.name=自定义物品

成果总结

本节教程您已掌握以下内容: