【定義が必要なアニメーション】

はじめに

▶アニメーションの種類のページでご紹介したもののうちネイティブでは再生されない一人称のアニメーションがありましたが、その部分を適用するには自分でアニメーションを定義する必要があります。
ただ、その部分をゼロから作るとなると大変な作業になりますので、既存アイテムのアニメーションを代用するのがお手軽でしょう。
ここでは弓のアニメーションを例に取り上げて実装する方法をご紹介します。

※基本的な部分は▶ダミーアイテムのページでダミーアイテムが実装済みである事を前提に進めていきます。


定義ファイルの内訳

弓のアニメーションを適用するためには▶ダミーアイテムのページで実装していたファイルに加えて、以下の黄色の部分で示したJSONファイルも追加で必要になります。
ビヘイビアパック内で必要になるファイル
/<ビヘイビアパックのルート>
    /items
        dummy_item.json
                    
リソースパック内で必要になるファイル
/<リソースパックのルート>

    /animations
        dummy_item.animation.json
    /attachables
        dummy_item.json
    /models
        /entity
            dummy_item.geo.json
    /render_controllers
        dummy_item.render_controllers.json

    /texts
        en_US.lang
    /textures
        item_texture.json
                    


定義ファイルの内容

ここでは今回追加となる4つのJSONファイルの内容を順に見ていきます。
全てのファイルはバニラの弓のJSONデータに手を加えたものです。

※以降の黄色の部分は今回用に修正した箇所です。
※三人称アニメーションについてはuse_animationで指定されたものが優先されます(三人称アニメーションに関わる定義箇所は必要ないため赤色で表記しています)。
<リソースパック>/attachables/dummy_item.json
{
    "format_version": "1.10.0",
    "minecraft:attachable": {
        "description": {
            "identifier": "customize:dummy_item",
            "materials": {
                "default": "entity_alphatest",
                "enchanted": "entity_alphatest_glint"
            },
            "textures": {
                "default": "textures/items/dummy_item",

                "dummy_item_pulling_0": "textures/items/dummy_item_pulling_0",
                "dummy_item_pulling_1": "textures/items/dummy_item_pulling_1",
                "dummy_item_pulling_2": "textures/items/dummy_item_pulling_2",

                "enchanted": "textures/misc/enchanted_item_glint"
            },
            "geometry": {
                "default": "geometry.dummy_item"

                "dummy_item_pulling_0": "geometry.dummy_item_pulling_0",
                "dummy_item_pulling_1": "geometry.dummy_item_pulling_1",
                "dummy_item_pulling_2": "geometry.dummy_item_pulling_2"

            },
            "animations": {
                "wield": "animation.dummy_item.wield",
                "wield_first_person_pull": "animation.dummy_item.wield_first_person_pull"
            },
            "scripts": {
                "pre_animation": [
                    "variable.charge_amount = math.clamp((query.main_hand_item_max_duration - (query.main_hand_item_use_duration - query.frame_alpha + 1.0)) / 10.0, 0.0, 1.0f);"
                ],
                "animate": [
                    "wield",
                    {
                        "wield_first_person_pull": "query.main_hand_item_use_duration > 0.0f && c.is_first_person"
                    }
                ]
            },
            "render_controllers": [ "controller.render.dummy_item" ]
        }
    }
}
                    

このファイルには今回追加しているファイルをマッピングする役割があります。
マッピングしている各データブロックは次の通りです。
textures
テクスチャファイルが存在する<リソースパック>textures/items/dummy_itemへのパスがマッピングされています。
geometry
モデル定義ファイルである<リソースパック>/models/entity/dummy_item.geo.jsonの定義がマッピングされています。
animations
アニメーション定義ファイルである<リソースパック>/animations/dummy_item.animation.jsonの定義がマッピングされています。
render_controllers
レンダーコントローラ定義ファイルである<リソースパック>/render_controllers/dummy_item.render_controllers.jsonの定義がマッピングされています。
<リソースパック>/models/entity/dummy_item.geo.json
{
    "format_version" : "1.16.0",
    "minecraft:geometry" : [

        {
        	"description" : {
        		"identifier" : "geometry.dummy_item_pulling_0",
        		"texture_width" : 16.0,
        		"texture_height" : 16.0
        	},
        	"bones" : [
        		{
        			"name" : "rightitem",
        			"texture_meshes" : [
        				{
        					"local_pivot" : [ 6.0, 0.0, 6.0 ],
        					"position" : [ 2.0, 1.0, -1.0 ],
        					"rotation" : [ 0.0, -135.0, 90.0 ],
        					"texture" : "dummy_item_pulling_0"
        				}
        			]
        		}
        	]
        },
        {
        	"description" : {
        		"identifier" : "geometry.dummy_item_pulling_1",
        		"texture_width" : 16.0,
        		"texture_height" : 16.0
        	},
        	"bones" : [
        		{
        			"name" : "rightitem",
        			"texture_meshes" : [
        				{
        					"local_pivot" : [ 6.0, 0.0, 6.0 ],
        					"position" : [ 2.01, 1.0, -1.0 ],
        					"rotation" : [ 0.0, -135.0, 90.0 ],
        					"texture" : "dummy_item_pulling_1"
        				}
        			]
        		}
        	]
        },
        {
        	"description" : {
        		"identifier" : "geometry.dummy_item_pulling_2",
        		"texture_width" : 16.0,
        		"texture_height" : 16.0
        	},
        	"bones" : [
        		{
        			"name" : "rightitem",
        			"texture_meshes" : [
        				{
        					"local_pivot" : [ 6.0, 0.0, 6.0 ],
        					"position" : [ 2.01, 1.0, -1.0 ],
        					"rotation" : [ 0.0, -135.0, 90.0 ],
        					"texture" : "dummy_item_pulling_2"
        				}
        			]
        		}
        	]
        },

        {
            "description" : {
                "identifier" : "geometry.dummy_item",
                "texture_width" : 16.0,
                "texture_height" : 16.0
            },
            "bones" : [
                {
                    "name" : "rightitem",
                    "texture_meshes" : [
                        {
                            "local_pivot" : [ 6.0, 0.0, 6.0 ],
                            "position" : [ 2.0, 1.0, -2.0 ],
                            "rotation" : [ 0.0, -135.0, 90.0 ],
                            "texture" : "default"
                        }
                    ]
                }
            ]
        }
    ]
}
                    
<リソースパック>/animations/dummy_item.animation.json
{
    "format_version": "1.10.0",
    "animations": {
        "animation.dummy_item.wield": {
            "loop": true,
            "bones": {
                "rightitem": {
                    "position": [ "c.is_first_person ? -5.5 : 0.5", "c.is_first_person ? -3.0 : -2.5", "c.is_first_person ? -3.0 : 1.0" ],
                    "rotation": [ "c.is_first_person ? 38.0 : 0.0", "c.is_first_person ? -120.0 : 0.0", "c.is_first_person ? -63.0 : 0.0" ]
                }
            }
        },
        "animation.dummy_item.wield_first_person_pull": {
            "loop": true,
            "bones": {
                "rightitem": {
                    "position": [ -1.5, " 2.5 + ( variable.charge_amount  >= 1.0 ? math.sin( (q.life_time) * 1000.0 * 1.3) * 0.1 - math.sin(q.life_time * 45.0) * 0.5 : 0.0)", -4.8 ],
                    "rotation": [ -53.0, 8.0, 35.0 ]
                }
            }
        }
    }
}
                    
<リソースパック>/render_controllers/dummy_item.render_controllers.json
{
    "format_version": "1.10",
    "render_controllers": {
        "controller.render.dummy_item": {
            "arrays": {
                "textures": {
                    "array.dummy_item_texture_frames": [
                        "texture.default",

                        "texture.dummy_item_pulling_0",
                        "texture.dummy_item_pulling_1",
                        "texture.dummy_item_pulling_2"

                    ]
                },
                "geometries": {
                    "array.dummy_item_geo_frames": [
                        "geometry.default",

                        "geometry.dummy_item_pulling_0",
                        "geometry.dummy_item_pulling_1",
                        "geometry.dummy_item_pulling_2"

                    ]
                }
            },
            "geometry": "array.dummy_item_geo_frames[query.get_animation_frame]",
            "materials": [ { "*": "variable.is_enchanted ? material.enchanted : material.default" } ],
            "textures": [ "array.dummy_item_texture_frames[query.get_animation_frame]", "texture.enchanted" ]
        }
    }
}
                    

今回追加したファイル内の赤色の部分は、テクスチャファイルも含め参照されないのであってもなくても構いません。
また、attachableを定義するとアイテムの持ち方はhand_equippedの定義よりも優先されますので、こちら(”hand_equipped”)もあってもなくても構いません。

テストしてみる

まずは▶ダミーアイテムのページでご紹介させて頂いた方法でテストしてみてください。
もしJSONファイルが正しく認識されない場合は、対応する括弧の過不足かないかどうかとカンマの位置が正しいかどうかを先に確認しておいた方がいいでしょう。

以下ではJSONファイルが正しく認識されている前提で動作を確認しています。

use_animationを"bow"で設定している場合は以下のようになります。


ちなみに今回定義したアニメーションはuse_animationの設定如何に関わらず、一人称では今回定義したアニメーションが優先して再生されます。
但し"eat"にした場合は、これに加えて食片が飛び散るエフェクトが以下のように表示されます。


おわりに

トライデントを投げる動作についても同じようにしてバニラからJSONデータを取ってくる事で定義できますが、一人称の画面ではトライデントの先の部分が見えるだけなので、実装するアイテムの見た目がトライデントより短い場合には画面に全く表示されない事も考えられます。
とは言え何も動きがなければボタンに反応しているのかどうかも判断できないので、見た目にこだわらずに簡易的に済ませたい場合には、とりあえず一人称のアニメーションが存在するもので代用しておくのがいいでしょう。