queue_commandが最強レベルで使いやすい話【マインクラフト】

スポンサーリンク

ようこそぷっこ村へ、ししゃもだよ。

(・∀・)ノ

1.20.60でついにqueue_commandが正式実装されましたね!おじちゃんずっと待ってたんだよ!

こんな気分

今までは、run_command として、試験的機能の一部で使えてました。エンティティやブロック、アイテムなどで、ビヘイビアファイルのイベント内に入れることで、そのままコマンドを実行できるっていう最強の機能でした。もちろん変なバグとかありました。

それがこの度、queue_command として正式に使えるようになったんだぜ!お前のことが好きだったんだよ!

queue_command 最強伝説の始まり

具体的に何が幸せなのかって話なのですが、超絶簡単に言うと、エンティティを介したイベントなどで、今までの半分くらいの記述で簡単なコマンドをトリガーできるってところです。

例えば、「なってる木の実を右クリックでゲットできる、10個集める必要がある」みたいなイベントを作りたくなったとします。

今まで

まず木の実エンティティを作成。用意するのは(拡張性を考え厳密に作っておく場合)

  • トリガー用のpropertyを一つ
  • クリックできるようにinteractコンポーネントを付ける。
  • interactでトリガーするeventにset_propertyを付けて、propertyを変更できるようにする
  • トリガー判定用にアニコン
  • トリガーした後にスコアなどをいじるアニメーション

が必要です。

まずビヘイビアファイル

{
	"format_version": "1.20.60",
	"minecraft:entity": {
		"description": {
			"identifier": "syamo_hoge:kinomi",
			"is_summonable": true,
			"is_experimental": false,
			"properties": {
				"syamo_hoge:event_trigger": {"type": "bool","default": false}
			},
			"animations": {
				"detect_state": "controller.animation.kinomi.detect_state",
                "get_kinomi": "animation.kinomi.get_this",
			},
			"scripts": {
				"animate": ["detect_state"]
			}
		},
		"component_groups": {
			"syamo_hoge:despawn_self": {"minecraft:instant_despawn": {}}
		},
		"components": {
            "syamo_hoge:interact_this": {
              "minecraft:interact": {
                "interactions": [
                  {"on_interact": {
                    "event": "syamo_hoge:get_this"
                  },
                  "cooldown": 10}
                ]
              }
            }
		},
		"events": {
			"syamo_hoge:despawn_self": {"add": {"component_groups": ["syamo_hoge:despawn_self"]}},
			"syamo_hoge:get_this": {"set_property": {"ikai_syamo:event_trigger":true}}
		}
	}
}

次にアニコン

{
	"format_version" : "1.10.0",
	"animation_controllers" : {
		"controller.animation.kinomi.detect_state" : {
			"initial_state" : "default",
			"states" : {
				"default" : {
					"transitions" : [
						{"get_this" : "q.property('syamo_hoge:event_trigger')"}
					]
				},
			  "give_key_item" : {"get_this": ["animations" : ["get_kinomi"]}
			}
		}
    }
}

ラストのアニメーション

{
	"format_version": "1.20.0",
	"animations": {
		"animation.kinomi.get_this": {
			"animation_length": 1.5,
			"loop": false,
			"timeline": {
				"0.2": [
                    "/titleraw @a actionbar {\"rawtext\":[{\"text\":\"木の実げっつ!\"}]}",
					"/give @p syamo_hoge:kinomi_item",,
					"/playsound 何か適当なの"
					"/playanimation @s 何か適当なの"
                ],
				"1.4": [
					"/event entity @s syamo_hoge:despawn_self"
                ]
			}
		}
    }
}

最小構成なのにこの記事のためだけに編集するのしんどい……、メンドイ……、ってくらい色々用意せんとあかんねん……。さらにきちんとやらなければならないマケプレ制作とかだと、langファイルもいるしね。モデル、テクスチャ、リソパ側のアニメーション、音、etc……と、禿げ散らかすこと山の如しな位用意しないといけないものがあります。

まぁ、右クリした瞬間パッと消えるとかで良ければ別にアニメーションいらんけどね。求める完成度とご相談ください。

queue_commandの場合

  • interact コンポーネント
  • interact でトリガーするイベント ←ここにqueue_command

だけでできる!強い!簡単な内容だとビヘイビアのエンティティファイルだけで完結できるのがすごく楽なんですね。

{
	"format_version": "1.20.60",
	"minecraft:entity": {
		"description": {
			"identifier": "syamo_hoge:kinomi",
			"is_summonable": true,
			"is_experimental": false
		},
		"component_groups": {
			"syamo_hoge:despawn_self": {"minecraft:instant_despawn": {}}
		},
		"components": {
            "syamo_hoge:interact_this": {
              "minecraft:interact": {
                "interactions": [
                  {"on_interact": {
                    "event": "syamo_hoge:get_this"
                  },
                  "cooldown": 10}
                ]
              }
            }
		},
		"events": {
			"syamo_hoge:despawn_self": {"add": {"component_groups": ["syamo_hoge:despawn_self"]}},
			"syamo_hoge:get_this": {
				"queue_command": {
					"command":[
						"playsound effect.get_item @a[r=5] ~~~ 1 1 1",
						"scoreboard players add kinomi foundObject 1",
						"execute if score kinomi foundObject matches 1 run replaceitem entity @a slot.inventory 1 syamo_hoge:kinomi 1 0 {\"minecraft:item_lock\":{\"mode\": \"lock_in_slot\"}}",
						"execute if score kinomi foundObject matches 2.. run give @a syamo_hoge:kinomi 1 0 {\"minecraft:item_lock\":{\"mode\": \"lock_in_slot\"}}",
						"titleraw @a actionbar {\"rawtext\":[{\"text\":\"木の実げっつ!\"}]}",
						"execute if score kinomi foundObject matches 10 run titleraw @a actionbar {\"rawtext\":[{\"text\":\"もう十分やで!\"}]}",
						"event entity @s syamo_hoge:despawn_self"
					]
				}
			}
		}
	}
}

なんか最低限こんな感じでできてまいます。強くね!?これ強くね!?ゲット時に何かアニメーション使って動かしたいなら、timer で遅延入れてから消すとかでいいから、これもらくちんちんちん!

まとめ

簡単な内容ならqueue_command で完結できるようになったのはホントにありがたいことです。かなり開発スピードが上がるし、めんどくさいからこれは辞めとくか、が減るのもとてもいい!

もちろん万能ではなく、時間差が必要で複雑なコマンドはビヘイビアのアニメーションが必要ではあります。ここは従来の方法との組み合わせにはなるのですが、煩雑になりがちなアニコンを簡素にできるのも魅力ですね!

てなわけで、マケプレ用の個人製作頑張るぞー(・∀・)

それではこの辺で、お帰りの際はお気をつけて~(・∀・)ノシ

コメント