手册:实例/附加包/物品/弹射物

来自Minecraft基岩版开发Wiki

引言[编辑]

创建自定义弹射物非常简单——你只需要准备弹射物纹理,创建三个文件即可完成,本实例就将介绍如何自定义弹射物。

教程[编辑]

物品[编辑]

在行为包的items文件夹中新建一个JSON文件,并将下面的代码复制进文件:

{
  "format_version": "1.16.100",
  "minecraft:item": {
    "description": {
      "identifier": "wiki:projectile",
      "category": "equipment"
    },
    "components": {
      "minecraft:creative_category": {
        "parent": "equipment"
      },
      "minecraft:max_stack_size": 16,
      // 该弹射物纹理,填物品纹理短名称
      "minecraft:icon": {
        "texture": "wiki.projectile"
      },
      // 让物品可以扔出去
      "minecraft:throwable": {
        "do_swing_animation": true,
        "launch_power_scale": 2
      },
      // 设置扔出的实体
      "minecraft:projectile": {
        "projectile_entity": "wiki:thrown_projectile"
      }
    }
  }
}

实体[编辑]

实体行为[编辑]

在行为包的entites文件夹中创建一个JSON文件,并将下面的代码复制进文件:

{
  "format_version": "1.16.0",
  "minecraft:entity": {
    "description": {
      // 该实体标识符,要与minecraft:projectile组件的值一致
      "identifier": "wiki:thrown_projectile",
      "is_spawnable": false,
      "is_summonable": true,
      "is_experimental": false,
      "runtime_identifier": "minecraft:snowball"
    },
    "components": {
      "minecraft:collision_box": {
        "width": 0.25,
        "height": 0.25
      },
      "minecraft:projectile": {
        "on_hit": {
          "impact_damage": {
            "filter": "blaze",
            // 弹射物所造成的伤害
            // "filter"指定了弹射物只能对烈焰人造成伤害
            "damage": 3,
            "knockback": true
          },
          "remove_on_hit": {},
          "particle_on_hit": {
            "particle_type": "snowballpoof",
            "num_particles": 6,
            "on_entity_hit": true,
            "on_other_hit": true
          }
        },
        "anchor": 1,
        "power": 1.5,
        "gravity": 0.03,
        "angle_offset": 0,
        "offset": [
          0,
          -0.1,
          0
        ]
      },
      "minecraft:physics": {},
      "minecraft:pushable": {
        "is_pushable": true,
        "is_pushable_by_piston": true
      }
    }
  }
}

实体资源[编辑]

在资源包的entity文件夹中创建一个JSON文件,并将下面的代码复制进文件:

{
  "format_version": "1.10.0",
  "minecraft:client_entity": {
    "description": {
      "identifier": "wiki:thrown_projectile",
      "materials": {
        "default": "snowball"
      },
      // 物品的纹理,在这里我们直接调用物品纹理
      "textures": {
        "default": "textures/items/wiki_projectile"
      },
      "geometry": {
        "default": "geometry.item_sprite"
      },
      "render_controllers": [
        "controller.render.item_sprite"
      ],
      "animations": {
        "flying": "animation.actor.billboard"
      },
      "scripts": {
        "animate": [
          "flying"
        ]
      }
    }
  }
}

纹理[编辑]

物品纹理[编辑]

按照Manual:制作附加包/物品中所述方法给物品分配纹理短名称:

{
    "resource_pack_name": "实例资源包",
    "texture_name": "atlas.items",
    "texture_data": {
        "wiki.projectile": {
            "textures": "textures/items/wiki_projectile"
        }
    }
}

本地化[编辑]

texts目录中的zh_CN.lang插入如下内容:

item.wiki:projectile=自定义弹射物
entity.wiki:thrown_projectile.name=自定义弹射物

至此,你已经学会了自定义弹射物,恭喜你!