手冊:實例/附加包/物品/彈射物

出自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=自定义弹射物

至此,你已經學會了自訂彈射物,恭喜你!