diff --git a/music_quiz/data/mq/function/init/buttons.mcfunction b/music_quiz/data/mq/function/init/buttons.mcfunction index 87c5eef..c144705 100644 --- a/music_quiz/data/mq/function/init/buttons.mcfunction +++ b/music_quiz/data/mq/function/init/buttons.mcfunction @@ -1,25 +1,17 @@ # 버튼 정의. 각 항목 의미: -# n : 이름 (= 트리거/태그) x,y,z : 버튼 블록 좌표 f : facing +# n : 이름 (= 트리거/태그) +# x,y,z : 버튼 블록 좌표 +# f : facing (south / north / east / west) # c : 클릭 시 실행 명령 (init=0 직접, 그 외 trigger $(n) 투표) -# ox,oy,oz : interaction entity 소환 위치 오프셋 (블록 좌표 기준) -# w,h : interaction width / height (float) # -# stone_button[face=wall] hitbox: 가로 6/16 (0.375), 세로 4/16 (0.25), -# 두께 2/16 (0.125), 벽 반대편으로만 튀어나옴. interaction 의 horizontal -# hitbox 는 width × width 정사각형 강제 → width 를 가로(0.375) 에 맞추고 -# 위치 보정으로 "튀어나온 쪽 면 = visible face" 가 되게 함. 반대편은 -# 벽 블록 속으로 들어가 invisible. -# -# facing 별 오프셋: -# south : ox=0.5 oy=0.375 oz=-0.0625 -# north : ox=0.5 oy=0.375 oz=1.0625 -# east : ox=-0.0625 oy=0.375 oz=0.5 -# west : ox=1.0625 oy=0.375 oz=0.5 +# interaction entity 의 위치/크기는 facing 만 보면 결정됨 — 매번 손으로 +# ox/oy/oz/w/h 를 적지 않는다. 실제 오프셋 테이블은 repeat/buttons/btn +# 안에서 한 곳에만 정의되어 있다 (stone_button[face=wall] 면 정합용). data modify storage mq:main button_defs set value [] -data modify storage mq:main button_defs append value {n:"start", x:140, y:62, z:-225, f:"south", c:"function mq:commands/start with storage mq:main", ox:"0.5", oy:"0.375", oz:"-0.0625", w:"0.375", h:"0.25"} -data modify storage mq:main button_defs append value {n:"stop", x:142, y:62, z:-225, f:"south", c:"function mq:commands/stop with storage mq:main", ox:"0.5", oy:"0.375", oz:"-0.0625", w:"0.375", h:"0.25"} -data modify storage mq:main button_defs append value {n:"skip", x:144, y:62, z:-225, f:"south", c:"function mq:commands/skip", ox:"0.5", oy:"0.375", oz:"-0.0625", w:"0.375", h:"0.25"} -data modify storage mq:main button_defs append value {n:"hint", x:146, y:62, z:-225, f:"south", c:"function mq:commands/hint", ox:"0.5", oy:"0.375", oz:"-0.0625", w:"0.375", h:"0.25"} -data modify storage mq:main button_defs append value {n:"replay", x:148, y:62, z:-225, f:"south", c:"function mq:commands/replay", ox:"0.5", oy:"0.375", oz:"-0.0625", w:"0.375", h:"0.25"} -data modify storage mq:main button_defs append value {n:"test", x:144, y:62, z:-213, f:"north", c:"function mq:commands/test", ox:"0.5", oy:"0.375", oz:"1.0625", w:"0.375", h:"0.25"} +data modify storage mq:main button_defs append value {n:"start", x:364, y:146, z:-263, f:"east", c:"function mq:commands/start with storage mq:main"} +data modify storage mq:main button_defs append value {n:"stop", x:364, y:146, z:-265, f:"east", c:"function mq:commands/stop with storage mq:main"} +data modify storage mq:main button_defs append value {n:"skip", x:364, y:146, z:-267, f:"east", c:"function mq:commands/skip"} +data modify storage mq:main button_defs append value {n:"hint", x:364, y:146, z:-269, f:"east", c:"function mq:commands/hint"} +data modify storage mq:main button_defs append value {n:"replay", x:364, y:146, z:-271, f:"east", c:"function mq:commands/replay"} +data modify storage mq:main button_defs append value {n:"test", x:144, y:62, z:-213, f:"north", c:"function mq:commands/test"} diff --git a/music_quiz/data/mq/function/repeat/buttons/btn.mcfunction b/music_quiz/data/mq/function/repeat/buttons/btn.mcfunction index 0771a4f..33935b4 100644 --- a/music_quiz/data/mq/function/repeat/buttons/btn.mcfunction +++ b/music_quiz/data/mq/function/repeat/buttons/btn.mcfunction @@ -1,7 +1,5 @@ # 버튼 1개에 대한 매 tick 처리. -# 매크로 인자: n, x, y, z, f, c, ox, oy, oz, w, h -# ox/oy/oz : interaction 소환 위치 오프셋 (블록 좌표 기준, facing 별) -# w / h : interaction width / height (float, 버튼 hitbox 정합용) +# 매크로 인자(mq:tmp.btn): n, x, y, z, f, c # buttons 점수 상태: # ..-2 : 비활성 (버튼 블록 제거, interaction 응답 차단) # -1 : 초기화 단계 (버튼 블록 배치 + interaction entity 보장 후 0 으로) @@ -11,6 +9,21 @@ # 에서 buttons 가 -1 로 재설정되어 다음 tick 에 ensure 로직이 실행됨. # -1 단계에서 같은 태그 entity 를 모두 kill 후 정확히 1개 summon → dup # 누적 없이 항상 "버튼당 1개, 올바른 좌표" 상태로 수렴 (idempotent). +# +# ---- facing → 소환 오프셋 (이 파일 한 곳에서만 정의) ---- +# stone_button[face=wall] hitbox: 가로 6/16 (0.375), 세로 4/16 (0.25), +# 두께 2/16 (0.125). 벽 블록의 한 면에서만 튀어나오고 반대편은 안쪽으로 +# 들어감. interaction 의 horizontal hitbox 는 width × width 정사각형 +# 강제 → width 를 가로(0.375) 에 맞추고 위치를 튀어나온 쪽 면에 정렬. +# +# facing 의미: "플레이어가 그 방향을 보면서 누른다". 즉 button 머리는 +# facing 의 반대쪽 면에 붙어 있다. +# south : 머리는 블록의 -z 쪽 면(north face) → 소환 z = -0.0625 +# north : 머리는 블록의 +z 쪽 면(south face) → 소환 z = 1.0625 +# east : 머리는 블록의 -x 쪽 면(west face) → 소환 x = -0.0625 +# west : 머리는 블록의 +x 쪽 면(east face) → 소환 x = 1.0625 +# interaction entity Y 는 hitbox 의 바닥(=발 위치) — 버튼 머리가 블록의 +# 세로 중앙(y+0.5) 에 있고 높이 0.25 라 바닥은 y+0.375. # ---- 비활성: 버튼 제거 + interaction 응답 차단 후 종료 ---- $execute if score $(n) buttons matches ..-2 run setblock $(x) $(y) $(z) minecraft:air @@ -24,7 +37,10 @@ $execute if score $(n) buttons matches ..-2 run return 0 $execute unless score $(n) buttons matches -1.. run scoreboard players set $(n) buttons -1 $execute if score $(n) buttons matches -1 run setblock $(x) $(y) $(z) minecraft:stone_button[face=wall,facing=$(f),powered=false] $execute if score $(n) buttons matches -1 run kill @e[type=minecraft:interaction,tag=mq,tag=$(n)] -$execute if score $(n) buttons matches -1 positioned $(x) $(y) $(z) positioned ~$(ox) ~$(oy) ~$(oz) run summon minecraft:interaction ~ ~ ~ {Tags:["mq","$(n)"],width:$(w)f,height:$(h)f,response:0b} +$execute if score $(n) buttons matches -1 if data storage mq:tmp btn{f:"south"} positioned $(x) $(y) $(z) run summon minecraft:interaction ~0.5 ~0.375 ~-0.0625 {Tags:["mq","$(n)"],width:0.375f,height:0.25f,response:0b} +$execute if score $(n) buttons matches -1 if data storage mq:tmp btn{f:"north"} positioned $(x) $(y) $(z) run summon minecraft:interaction ~0.5 ~0.375 ~1.0625 {Tags:["mq","$(n)"],width:0.375f,height:0.25f,response:0b} +$execute if score $(n) buttons matches -1 if data storage mq:tmp btn{f:"east"} positioned $(x) $(y) $(z) run summon minecraft:interaction ~-0.0625 ~0.375 ~0.5 {Tags:["mq","$(n)"],width:0.375f,height:0.25f,response:0b} +$execute if score $(n) buttons matches -1 if data storage mq:tmp btn{f:"west"} positioned $(x) $(y) $(z) run summon minecraft:interaction ~1.0625 ~0.375 ~0.5 {Tags:["mq","$(n)"],width:0.375f,height:0.25f,response:0b} $execute if score $(n) buttons matches -1 run scoreboard players set $(n) buttons 0 # ---- 상시: interaction 클릭/타격 → playsound + 명령/투표 실행 ---- diff --git a/music_quiz/data/mq/function/repeat/buttons/handler.mcfunction b/music_quiz/data/mq/function/repeat/buttons/handler.mcfunction index a3db64a..87a6ab5 100644 --- a/music_quiz/data/mq/function/repeat/buttons/handler.mcfunction +++ b/music_quiz/data/mq/function/repeat/buttons/handler.mcfunction @@ -1,6 +1,16 @@ -function mq:repeat/buttons/btn with storage mq:main button_defs[0] -function mq:repeat/buttons/btn with storage mq:main button_defs[1] -function mq:repeat/buttons/btn with storage mq:main button_defs[2] -function mq:repeat/buttons/btn with storage mq:main button_defs[3] -function mq:repeat/buttons/btn with storage mq:main button_defs[4] -function mq:repeat/buttons/btn with storage mq:main button_defs[5] +# 각 button_defs 항목을 mq:tmp.btn 으로 복사 후 btn 호출. +# btn 안에서 facing 별 분기 (if data storage mq:tmp btn{f:"..."}) 를 +# 사용하기 위해 현재 항목을 같은 storage 에 노출시킨다. + +data modify storage mq:tmp btn set from storage mq:main button_defs[0] +function mq:repeat/buttons/btn with storage mq:tmp btn +data modify storage mq:tmp btn set from storage mq:main button_defs[1] +function mq:repeat/buttons/btn with storage mq:tmp btn +data modify storage mq:tmp btn set from storage mq:main button_defs[2] +function mq:repeat/buttons/btn with storage mq:tmp btn +data modify storage mq:tmp btn set from storage mq:main button_defs[3] +function mq:repeat/buttons/btn with storage mq:tmp btn +data modify storage mq:tmp btn set from storage mq:main button_defs[4] +function mq:repeat/buttons/btn with storage mq:tmp btn +data modify storage mq:tmp btn set from storage mq:main button_defs[5] +function mq:repeat/buttons/btn with storage mq:tmp btn