월드 cmd block 의존 (redstone_block/red_wool 펄스) 을 제거하고 btn.mcfunction 이 직접 summon 하도록 변경. - buttons=-1 초기화 단계에서 기존 mq/<버튼명> interaction 을 모두 kill 후 정확히 1개를 (x+0.5, y, z+0.5) 에 1f×1f 로 재소환. /reload 마다 dup 누적 없이 "버튼당 1개, 올바른 좌표" 로 수렴. - /reload → load → commands/stop 이 buttons 점수를 -1 로 재설정 → 다음 tick 에 ensure 로직 실행. /kill @e 후에도 /reload 한 번으로 복구. - stone_button 직접 감지 fallback 및 잉여 state machine (1→2→0) 제거. 클릭 경로는 interaction 단일화 → trigger 투표 흐름 보존. - README 의 버튼 본체 설명을 새 구조로 갱신. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
37 lines
2.9 KiB
MCFunction
37 lines
2.9 KiB
MCFunction
# 버튼 1개에 대한 매 tick 처리. 매크로 인자: n, x, y, z, f, c
|
|
# buttons 점수 상태:
|
|
# ..-2 : 비활성 (버튼 블록 제거, interaction 응답 차단)
|
|
# -1 : 초기화 단계 (버튼 블록 배치 + interaction entity 보장 후 0 으로)
|
|
# 0 : 정상 (interaction 클릭 대기)
|
|
#
|
|
# interaction entity 는 데이터팩이 직접 summon — /reload 시 commands/stop
|
|
# 에서 buttons 가 -1 로 재설정되어 다음 tick 에 ensure 로직이 실행됨.
|
|
# -1 단계에서 같은 태그 entity 를 모두 kill 후 정확히 1개 summon → dup
|
|
# 누적 없이 항상 "버튼당 1개, 올바른 좌표" 상태로 수렴 (idempotent).
|
|
|
|
# ---- 비활성: 버튼 제거 + interaction 응답 차단 후 종료 ----
|
|
$execute if score $(n) buttons matches ..-2 run setblock $(x) $(y) $(z) minecraft:air
|
|
$execute if score $(n) buttons matches ..-2 run data modify entity @e[type=minecraft:interaction,tag=mq,tag=$(n),limit=1] response set value 0b
|
|
$execute if score $(n) buttons matches ..-2 run return 0
|
|
|
|
# ---- 초기화: 버튼 블록 배치 + interaction entity 보장 ----
|
|
# 기존 mq/$(n) interaction 을 전부 제거 후 정확히 1개 소환.
|
|
# 옛 월드 cmd block 으로 누적 소환된 dup 이나 엉뚱한 좌표에 남은 잔존
|
|
# entity 까지 정리 → "정상 상태(버튼당 정확히 1개, 올바른 좌표)" 가 보장됨.
|
|
$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 ~0.5 ~ ~0.5 run summon minecraft:interaction ~ ~ ~ {Tags:["mq","$(n)"],width:1f,height:1f,response:0b}
|
|
$execute if score $(n) buttons matches -1 run scoreboard players set $(n) buttons 0
|
|
|
|
# ---- 상시: interaction 클릭/타격 → playsound + 명령/투표 실행 ----
|
|
# init main = 0 (퀴즈 시작 전 설정 단계) : 명령 직접 실행
|
|
# 그 외 : trigger 투표 경로
|
|
$execute as @e[type=minecraft:interaction,tag=mq,tag=$(n),limit=1] on target as @s positioned $(x) $(y) $(z) run playsound minecraft:block.stone_button.click_on block @s ~ ~ ~ 1 1
|
|
$execute as @e[type=minecraft:interaction,tag=mq,tag=$(n),limit=1] on target as @s positioned $(x) $(y) $(z) if score init main matches 0 run $(c)
|
|
$execute as @e[type=minecraft:interaction,tag=mq,tag=$(n),limit=1] on target as @s positioned $(x) $(y) $(z) unless score init main matches 0 run trigger $(n)
|
|
|
|
# ---- 처리 후 attack/interaction NBT 클리어 (다음 tick 중복 발화 방지) ----
|
|
$execute as @e[type=minecraft:interaction,tag=mq,tag=$(n)] at @s run data remove entity @s attack
|
|
$execute as @e[type=minecraft:interaction,tag=mq,tag=$(n)] at @s run data remove entity @s interaction
|