커맨드 질문 있는 게이는 여따 댓글로 달아줘라 질문글 쓰지 말고

내가 답해드림


이 글에선 시야에 들어온 엔티티 감지하는 방법 질문한 게이가 있어서 알려드림



> 조건적

| 무조건적


1.

[기본] execute as @p at @s anchored eyes run summon marker ^ ^ ^1 {Tags:["markers","marker1"]}

| execute as @p at @s anchored eyes positioned ^ ^ ^2 {Tags:["markers","marker2"]}

| execute as @p at @s anchored eyes positioned ^ ^ ^3 {Tags:["markers","marker3"]}

| execute as @p at @s anchored eyes positioned ^ ^ ^4 {Tags:["markers","marker4"]}

...

| execute as @p at @s anchored eyes positioned ^ ^ ^30 {Tags:["markers","marker30"]}

| scoreboard players set @e[tag=marker1] marker 1

| scoreboard players set @e[tag=marker2] marker 2

...

| scoreboard players set @e[tag=marker30] marker 30

이거 한번 작동시켜서 마커 소환하고


2.

[반복] execute as @p at @s anchored eyes run tp @n[tag=marker1] ^ ^ ^1

| execute as @p at @s anchored eyes run tp @n[tag=marker2] ^ ^ ^2

| execute as @p at @s anchored eyes run tp @n[tag=marker3] ^ ^ ^3

...

| execute as @p at @s anchored eyes run tp @n[tag=marker30] ^ ^ ^30

이걸로 플레이어 시선 앞으로 계속 마커 tp 시키고

(if entity 넣거나 해서 없는 마커는 작동 안 되게 하면 최적화에 좋긴 한데 그렇게까지 최적화를 할 필요는 없음)


3.

[반복] execute if entity @a[tag=you_shall_not_execute] run tag @a remove you_shall_not_execute

| execute if entity @etag=detected] run tag @e remove detected

| execute at @e[tag=markers] if entity @e[tag=entity,distance=0..1] run tag @s add detected

> execute at @p as @e[tag=markers] if score @s marker < @n[tag=detected] marker at @s unless block ~ ~ ~ #air run tag @p add you_shall_not_execute

> execute unless entity @a[tag=you_shall_not_execute] run function func:tion

이걸로 마커 주변에 엔티티가 있다면 명령어 실행하면 된다.

(만약 주변에 엔티티가 있는 마커의 앞을 어떤 블럭이 가로막고 있다면 실행하지 않기 위해 if score 저거 쓴 거)



만약 더 상세하게(?) 감지하고 싶으면 0.5칸씩 앞으로 가면서 소환하면 된다.



그럼 이제 활용을 해보자

"게임 시작"이라 써 있는 텍스트 디스플레이랑 인터렉션을 겹쳐 놓고

그 텍스트를 클릭하면 게임이 시작되는데

그 텍스트에 시선이 갔을 때 "게임 시작"의 글자 색을 바꾸는 걸 만들려면,

3번에 있는 func:tion의 내용을

execute at @e[tag=markers] if entity @e[tag=interaction,distance=0..1] at @n[tag=interaction] run data merge entity @n[tag=startgame] {text:'{"color":"yellow","text":"게임 시작"}'}

execute as @n[tag=startgame] at @s unless entity @e[tag=markers,distance=0..1] run data merge entity @s {text:'{"text":"계엄 시작"}'}


이렇게 쓰면 되겠지?


근데 텍스트 디스플레이는 옆으로 긴 경우가 많음. 그러므로

execute at @e[tag=markers] positioned ~-0.5 ~ ~ if entity @e[tag=interaction,distance=0..1] at @n[tag=interaction] run data merge entity @n[tag=startgame] {text:'{"color":"yellow","text":"게임 시작"}'}

execute at @e[tag=markers] positioned ~0.5 ~ ~ if entity @e[tag=interaction,distance=0..1] at @n[tag=interaction] run data merge entity @n[tag=startgame] {text:'{"color":"yellow","text":"계엄 시작"}'}

execute as @n[tag=startgame] at @s positioned ~0.5 ~ ~ unless entity @e[tag=markers,distance=0..1] positioned ~-1 ~ ~ unless entity @e[tag=markers,distance=0..1] run data merge entity @s {text:'{"text":"게임 시작"}'}

뭐.. 대충 이런 식으로 하면 된다. (당연히 z축으로 긴 경우엔 바꿔야 됨)

참고로 positioned 쓰면서 종종 나올 수 있는 실수인데,

positioned ~0.5 ~ ~를 한번 쓴 다음에 뒤에다가 positioned ~-0.5 ~ ~를 쓰면 제자리로 돌아온다.

~-1 ~ ~을 써야 0.5칸 뒤로 갈 수 있음



TMI ) 텍디플의 히트박스는 텍스트의 가운데 아래 있다.

커맨드로 텍디플을 감지하는 것 또한 히트박스를 감지하는 것이다.




근데 지금 내가 마크 켜고 쓰는 게 아니라서 버그가 있을 수도 있는데 뭐 나한테 버그 생기는 거 아니니까 괜찮음.


시가콰



원래는 이런 거 안 해주는데 특별히 해줬으니 한 30,000원이면 될 것 같음. 고맙다.