Uploaded:2023/01/01 Latest-Update:2023/01/01

アドオン作成 - アイテム

目次は右上の「≡」から!

アドオンのアイテムについて説明します。

基本的な流れ

アイテム本体に加えてテクスチャも追加するので、ビヘイビアとリソース両方が必要になります。

全体の作業はこうなります:

  • ① アイテムのテクスチャを追加する
  • ② item_texture.jsonを編集or新規作成する
  • ③ itemsフォルダに新しくJSONを新規作成する
  • ④ .langファイルを編集・新規作成する

リソースに関する詳細はこちら

アイテムを定義するJSON

これはアイテムが定義できるための最小限の内容です。ゼロから作る場合はこれをコピペするといいでしょう。

Dat
items/my_item.json
{ "format_version": "1.16.100", "minecraft:item": { "description": { "identifier": "test:my_item", "category": "Items" }, "components": { "minecraft:icon": { "texture": "my_item" // TerrainID } // コンポーネント } } }

● 主な構成

{ "format_version": "1.16.100", "minecraft:item": { "description": { "identifier": "test:my_item", "category": "Items" }, ~#r"components": { %%%% "minecraft:icon": { %%%% "texture": "my_item" %%%% } %%%% // コンポーネント %%%%}r#~ } }

大きく関わってくるのがこの赤い枠で囲った部分で、もっと言えばその中の{ }内にコンポーネントを書き足していきます。

minecraft:iconもコンポーネントですが、テクスチャを指定するために必須なので書いておきました。

● 発展的な構成

{ "format_version": "1.16.100", "minecraft:item": { "description": { "identifier": "test:my_item", "category": "Items" }, ~#r"components": { %%%% "minecraft:icon": { %%%% "texture": "my_item" %%%% } %%%% // コンポーネント %%%%},r#~ ~#r"events": { %%%% // イベント %%%%}r#~ } }

イベントを用いてより複雑な仕様をもったアイテムを作ることができます。

イベント

イベントをトリガーする(呼び出す)ことができる特定のコンポーネントによって呼び出され、 指定したイベントファンクションを動作させます。

イベントトリガー系コンポーネント
    ↓ 呼び出す
イベント
具体例

● シンプルなアイテム

JSONがシンプルになるように性質を選んできています。

しかし、もともと簡単なコンポーネントが少ないのでスカスカです

Dat
items/simple_item.json
{ "format_version": "1.16.100", "minecraft:block": { "description": { "identifier": "test:simple_item" }, "components": { "minecraft:fuel": { "duration": 80 }, "minecraft:icon": { "texture": "simple_item" }, "minecraft:max_stack_size": 16 } } }

このお手本アイテムは以下のような性質を持ちます↓

  • かまどでの燃焼時間が80秒(アイテム8個分、石炭と同じ)
  • TerrainIDはsimple_itemである
  • 16個までしかスタックできない

● 「使う」ができるアイテム

Dat
items/use_item.json
{ "format_version": "1.16.100", "minecraft:item": { "description": { "identifier": "ex:use_item", "category": "Equipment" }, "components": { "minecraft:can_destroy_in_creative": false, "minecraft:cooldown": { "category": "use_item", "duration": 5 }, "minecraft:display_name": {}, "minecraft:foil": true, "minecraft:icon": { "texture": "use_item" }, "minecraft:max_stack_size": 64, "minecraft:on_use": { "on_use": { "condition": "(1.0)", "event": "use", "target": "self" } }, "minecraft:use_duration": 3600 }, "events": { "use": { "run_command": { "command": [ "playsound mob.evocation_illager.cast_spell @a" ], "target": "holder" } } } } }

● 剣

Dat
items/alt_netherite_sword.json
{ "format_version": "1.16.100", "minecraft:item": { "description": { "identifier": "ex:alt_netherite_sword", "category": "Equipment" }, "components": { "minecraft:can_destroy_in_creative": false, "minecraft:creative_category": { "parent": "itemGroup.name.sword" }, "minecraft:damage": 8, "minecraft:display_name": {}, "minecraft:durability": { "max_durability": 2031 }, "minecraft:enchantable": { "slot": "sword", "value": 15 }, "minecraft:hand_equipped": true, "minecraft:icon": { "texture": "netherite_sword" }, "minecraft:max_stack_size": 1, "minecraft:repairable": { "repair_items": [ { "items": [ "minecraft:netherite_ingot" ], "repair_amount": 507 }, { "items": [ "ex:alt_netherite_sword" ], "repair_amount": "(c.other->q.remaining_durability)+0.05*(c.other->q.max_durability)" } ] }, "minecraft:weapon": { "on_hurt_entity": { "condition": "(1.0)", "event": "attack", "target": "self" } } }, "events": { "attack": { "damage": { "amount": 1, "target": "self", "type": "durability" } } } } }

● ツルハシ

Dat
items/my_pick.json
{ "format_version": "1.16.100", "minecraft:item": { "description": { "identifier": "ex:my_pick", "category": "Equipment" }, "components": { "minecraft:creative_category": { "parent": "itemGroup.name.pickaxe" }, "minecraft:damage": 6, "minecraft:display_name": {}, "minecraft:digger": { "use_efficiency": true, "on_dig": { "event": "other_hit", "target": "self" }, "destroy_speeds": [ { "block": { "tags": "q.any_tag('stone', 'metal')" }, "speed": 8 }, { "block": "minecraft:coal_ore", "speed": 8 }, { "block": "minecraft:iron_ore", "speed": 8 }, { "block": "minecraft:lapis_ore", "speed": 8 }, { "block": "minecraft:lit_redstone_ore", "speed": 8 }, { "block": "minecraft:gold_ore", "speed": 8 }, { "block": "minecraft:diamond_ore", "speed": 8 }, { "block": "minecraft:emerald_ore", "speed": 8 }, { "block": "minecraft:quartz_ore", "speed": 8 } // ... ] }, "minecraft:durability": { "max_durability": 1000 }, "minecraft:enchantable": { "slot": "pickaxe", "value": 10 }, "minecraft:hand_equipped": true, "minecraft:icon": { "texture": "my_pickaxe" }, "minecraft:max_stack_size": 1, "minecraft:mining_speed": 3, "minecraft:repairable": { "repair_items": [ { "items": [ "ex:my_pickaxe" ], "repair_amount": 20 } ] }, "minecraft:stacked_by_data": true, "minecraft:weapon": { "on_hurt_entity": { "event": "other_dam", "target": "self" }, "on_hit_block": { "event": "break_block", "target": "self" } } }, "events": { "other_hit": { "damage": { "type": "durability", "amount": 3 } }, "break_block": { "damage": { "type": "durability", "amount": 1 } } } } }

● 防具

Dat
items/alt_netherite_chestplate.json
{ "format_version": "1.16.100", "minecraft:item": { "description": { "identifier": "ex:alt_netherite_chestplate", "category": "Equipment" }, "components": { "minecraft:armor": { "protection": 11 }, "minecraft:creative_category": { "parent": "itemGroup.name.chestplate" }, "minecraft:display_name": {}, "minecraft:durability": { "max_durability": 550, "damage_chance": { "min": 60, "max": 100 } }, "minecraft:enchantable": { "slot": "armor_torso", "value": 15 }, "minecraft:icon": { "texture": "netherite_chestplate" }, "minecraft:max_stack_size": 1, "minecraft:repairable": { "repair_items": [ { "items": [ "minecraft:netherite" ], "repair_amount": "math.floor(q.max_durability*0.25)" }, { "items": [ "ex:alt_netherite_chestplate" ], "repair_amount": "(c.other->q.remaining_durability)+0.05*(c.other->q.max_durability)" } ] }, "minecraft:stacked_by_data": true, "minecraft:wearable": { "slot": "slot.armor.chest" } } } }

● 食べ物

Dat
items/my_food.json
{ "format_version": "1.12.0", "minecraft:item": { "description": { "identifier": "ex:my_food" }, "components": { "minecraft:food": { "nutrition": 10, "saturation_modifier": "normal", "can_always_eat": false }, "minecraft:use_duration": 32 } } }
©2023 Rinca Hayamine