矢のhit判定
矢がエンティティにヒットすると消滅することを利用し、プレイヤーが矢を放った時、エンティティにhitしたかブロックにhitしたかを検知します。 ブロックにhit後、矢は消滅します。
ブロック判定をairで行うため、水の中や草などの判定のないブロックにもhit判定が発生します。
誰がエンティティ/ブロックに当てたかの判定が可能です。
どのエンティティに当てたかの判定はしていません。
(leash_knotの200マス下の座標から疑似的に判定は可能です。)
★部:ブロックにhit時に発動
☆部:エンティティにhit時に発動
code:事前準備(必ず一度は実行)
/scorebaord objectives add e dummy
/scorebaord objectives add ar_id dummy
/scorebaord objectives add le_id dummy
/scorebaord objectives add le_time dummy
code:別途用意(固有スコア)
エンティティ固有スコアeを用意します
scoreboard players add @e e 0
scoreboard players operation max e > * e
code:メイン構文
★
execute as @etype=arrow at @s positioned 0.0 0.0 0.0 positioned ^ ^ ^-2 ★
positioned ~ ~ 0.0 positioned ^ ^ ^1 facing 0.0 0.0 0.0 facing ^ ^ ^-1 positioned as @s unless block ^ ^ ^0.1 air at @a if score @s ar_id = @ac=1 e run playsound note.bass @ac=1 ~~~ 1 1 execute as @etype=arrow at @s positioned 0.0 0.0 0.0 positioned ^ ^ ^-2 positioned ~ ~ 0.0 positioned ^ ^ ^1 facing 0.0 0.0 0.0 facing ^ ^ ^-1 positioned as @s unless block ^ ^ ^0.1 air run kill @s ☆
☆
処理内容の言語化
矢セットアップ
矢のar_idにプレイヤーの固有スコアeを代入
プレイヤー以外の矢を判別するためのTAG付与
結び目セットアップ
スコアが代入された矢から結び目を召喚
結び目のar_idに、プレイヤーから代入した矢のar_idを代入
結び目のle_idに、矢の固有スコアeを代入
接地判定
矢がブロックに当たる直前に矢のar_idと固有スコアeが一致するプレイヤーから音を出す
矢がブロックに当たる直前に矢の固有スコアeと一致するle_idの結び目をkill
矢がブロックに当たる直前に矢をkill
飛翔中判定
結び目のtimeスコアが1の時、結び目のle_idとeが一致する矢がいたら結び目をkill
エンティティhit処理
結び目のtimeスコアが2以上になる=紐づいた矢が存在しない=hit
hit時、結び目のar_idと一致する固有スコアeのプレイヤーからコマンドを実行
hit処理後、結び目をkill
le_timeスコア加算