矢の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
execute as @etag=!e_set,scores={e=0} at @etag=!e_set,scores={e=0} run scoreboard players add @s e 1
scoreboard players operation @etag=!e_set,scores={e=0..} e += max e
tag @etag=!e_set,scores={e=0..} add e_set
code:メイン構文
execute as @etype=arrow,tag=!a at @s positioned ~~-1.62001~ run scoreboard players operation @s ar_id = @ac=1,r=0.5 e
tag @etype=arrow add a
execute as @etype=arrow,scores={ar_id=0..} at @s positioned ~~200~ run summon leash_knot ~~~
execute as @etype=arrow,scores={ar_id=0..} at @s positioned ~~200~ run scoreboard players operation @etype=leash_knot,c=1,r=2 ar_id = @s ar_id
execute as @etype=arrow,scores={ar_id=0..} at @s positioned ~~200~ run scoreboard players operation @etype=leash_knot,c=1,r=2 le_id = @s e
★
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 as @s at @etype=leash_knot if score @s e = @etype=leash_knot,c=1 le_id run kill @etype=leash_knot,c=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
execute as @etype=leash_knot,scores={le_time=1} at @etype=arrow if score @s le_id = @etype=arrow,c=1 e run kill @s
☆
execute as @etype=leash_knot,scores={le_time=2} at @a if score @s ar_id = @ac=1 e run playsound random.orb @ac=1 ~~~ 1 1
☆
kill @etype=leash_knot,scores={le_time=2..}
scoreboard players add @etype=leash_knot,scores={le_id=0..} le_time 1
処理内容の言語化
矢セットアップ
矢の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スコア加算