# block:custom/wizarding_table/place
# called by: block:custom/wizarding_table/scan

## Sound
execute if entity @s[advancements={magical_addons:---/block/place/wizarding_table=true}] run playsound block.wood.place block @a ~ ~ ~ 1 .8

## Block
function magical_addons:block/custom/wizarding_table/set_state with block ~ ~ ~
data modify block ~ ~ ~ components."minecraft:custom_data".magical_addons.generated set value 1b

## Marker
execute if data block ~ ~ ~ {components:{"minecraft:custom_model_data":{flags:[0b]}}} summon item_display run data merge entity @s {data:{magical_addons:{id:"wizarding_table",tick_cmd:"function magical_addons:block/custom/wizarding_table/tick",break_cmd:"execute unless block ~ ~ ~ #magical_addons:wizarding_table{components:{\"minecraft:custom_data\":{magical_addons:{id:wizarding_table}}}} run function magical_addons:block/custom/wizarding_table/break"}},transformation:{scale:[-1f,1f,-1f]},item:{id:"spawner",components:{item_model:"magical_addons:wizarding_table",custom_model_data:{flags:[0b,0b]}}},Tags:[off,maddons.block,maddons.wizarding_table],view_range:64}
execute if data block ~ ~ ~ {components:{"minecraft:custom_model_data":{flags:[1b]}}} summon item_display run data merge entity @s {data:{magical_addons:{id:"wizarding_table",tick_cmd:"function magical_addons:block/custom/wizarding_table/tick",break_cmd:"execute unless block ~ ~ ~ #magical_addons:wizarding_table{components:{\"minecraft:custom_data\":{magical_addons:{id:wizarding_table}}}} run function magical_addons:block/custom/wizarding_table/break"}},transformation:{scale:[-1f,1f,-1f]},item:{id:"spawner",components:{item_model:"magical_addons:wizarding_table",custom_model_data:{flags:[1b,0b]}}},Tags:[on,off,maddons.block,maddons.wizarding_table],view_range:64}

## Engage if state=on
execute if data block ~ ~ ~ {components:{"minecraft:custom_model_data":{flags:[1b]}}} as @n[type=item_display,tag=maddons.wizarding_table,tag=off,tag=on,distance=...5] run return run function magical_addons:block/custom/wizarding_table/engage