execute if score .lucky_blocks settings matches 1 store result score #random temp run random value 1..11
execute if score .lucky_blocks settings matches 0 store result score #random temp run random value 1..9

execute store result score #random2 temp run random value 1..4

$execute if score #random2 temp matches 1 if score #random temp matches 1..7 positioned ~$(x) ~$(y) ~$(z) if block ~ ~ ~ air run summon item ~ ~ ~ {Motion:[0.$(x_motion),0.$(y_motion),0.$(z_motion)],Age:5700,Glowing:1b,Tags:["new","coin"],Item:{id:"minecraft:sunflower",count:1,components:{"minecraft:item_name":{"color":"gold","italic":false,"text":"Coin"},"minecraft:custom_data":{coin:1b}}}}
$execute if score #random2 temp matches 1 if score #random temp matches 8..9 positioned ~$(x) ~$(y) ~$(z) if block ~ ~ ~ air run summon item ~ ~ ~ {Motion:[0.$(x_motion),0.$(y_motion),0.$(z_motion)],Age:5600,Glowing:1b,Tags:["new","gem"],Item:{id:"minecraft:emerald",count:1,components:{"minecraft:item_name":{"color":"green","italic":false,"text":"Gem"},"minecraft:custom_data":{gem:1b}}}}
$execute if score #random2 temp matches 1 if score #random temp matches 10..11 positioned ~$(x) ~$(y) ~$(z) if block ~ ~ ~ air run summon item ~ ~ ~ {Motion:[0.$(x_motion),0.$(y_motion),0.$(z_motion)],Age:5700,Glowing:1b,Tags:["lucky_block_drop","new"],Item:{id:"minecraft:player_head",count:1,components:{"minecraft:max_stack_size":4,"minecraft:item_name":{"text":"Lucky Block"},"minecraft:lore":[[{"color":"gray","italic":false,"text":"Use "},{"color":"white","italic":false,"keybind":"key.use"},{"color":"gray","italic":false,"text":" to open!"}],{"color":"gray","italic":false,"text":"I wonder what\'s inside..."}],"minecraft:hide_additional_tooltip":{},"minecraft:custom_data":{lucky_block:1b,default:1b},"minecraft:food":{nutrition:0,saturation:0,can_always_eat:true},"minecraft:consumable":{consume_seconds:1000001,has_consume_particles:false},"minecraft:profile":{id:[I;-2087206888,1259293576,-1271610310,-1658403980],properties:[{name:"textures",value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZTBhNDQzZTBlY2E3ZjVkMzA2MjJkZDkzN2YxZTVlYTJjZGYxNWQxMGMyN2ExOTljNjhhN2NlMDljMzlmNmI2OSJ9fX0="}]}}}}

$execute if score #random2 temp matches 2 if score #random temp matches 1..7 positioned ~$(x) ~$(y) ~$(z) if block ~ ~ ~ air run summon item ~ ~ ~ {Motion:[-0.$(x_motion),0.$(y_motion),-0.$(z_motion)],Age:5700,Glowing:1b,Tags:["new","coin"],Item:{id:"minecraft:sunflower",count:1,components:{"minecraft:item_name":{"color":"gold","italic":false,"text":"Coin"},"minecraft:custom_data":{coin:1b}}}}
$execute if score #random2 temp matches 2 if score #random temp matches 8..9 positioned ~$(x) ~$(y) ~$(z) if block ~ ~ ~ air run summon item ~ ~ ~ {Motion:[-0.$(x_motion),0.$(y_motion),-0.$(z_motion)],Age:5600,Glowing:1b,Tags:["new","gem"],Item:{id:"minecraft:emerald",count:1,components:{"minecraft:item_name":{"color":"green","italic":false,"text":"Gem"},"minecraft:custom_data":{gem:1b}}}}
$execute if score #random2 temp matches 2 if score #random temp matches 10..11 positioned ~$(x) ~$(y) ~$(z) if block ~ ~ ~ air run summon item ~ ~ ~ {Motion:[-0.$(x_motion),0.$(y_motion),-0.$(z_motion)],Age:5700,Glowing:1b,Tags:["lucky_block_drop","new"],Item:{id:"minecraft:player_head",count:1,components:{"minecraft:max_stack_size":4,"minecraft:item_name":{"text":"Lucky Block"},"minecraft:lore":[[{"color":"gray","italic":false,"text":"Use "},{"color":"white","italic":false,"keybind":"key.use"},{"color":"gray","italic":false,"text":" to open!"}],{"color":"gray","italic":false,"text":"I wonder what\'s inside..."}],"minecraft:hide_additional_tooltip":{},"minecraft:custom_data":{lucky_block:1b,default:1b},"minecraft:food":{nutrition:0,saturation:0,can_always_eat:true},"minecraft:consumable":{consume_seconds:1000001,has_consume_particles:false},"minecraft:profile":{id:[I;-2087206888,1259293576,-1271610310,-1658403980],properties:[{name:"textures",value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZTBhNDQzZTBlY2E3ZjVkMzA2MjJkZDkzN2YxZTVlYTJjZGYxNWQxMGMyN2ExOTljNjhhN2NlMDljMzlmNmI2OSJ9fX0="}]}}}}

$execute if score #random2 temp matches 3 if score #random temp matches 1..7 positioned ~$(x) ~$(y) ~$(z) if block ~ ~ ~ air run summon item ~ ~ ~ {Motion:[-0.$(x_motion),0.$(y_motion),0.$(z_motion)],Age:5700,Glowing:1b,Tags:["new","coin"],Item:{id:"minecraft:sunflower",count:1,components:{"minecraft:item_name":{"color":"gold","italic":false,"text":"Coin"},"minecraft:custom_data":{coin:1b}}}}
$execute if score #random2 temp matches 3 if score #random temp matches 8..9 positioned ~$(x) ~$(y) ~$(z) if block ~ ~ ~ air run summon item ~ ~ ~ {Motion:[-0.$(x_motion),0.$(y_motion),0.$(z_motion)],Age:5600,Glowing:1b,Tags:["new","gem"],Item:{id:"minecraft:emerald",count:1,components:{"minecraft:item_name":{"color":"green","italic":false,"text":"Gem"},"minecraft:custom_data":{gem:1b}}}}
$execute if score #random2 temp matches 3 if score #random temp matches 10..11 positioned ~$(x) ~$(y) ~$(z) if block ~ ~ ~ air run summon item ~ ~ ~ {Motion:[-0.$(x_motion),0.$(y_motion),0.$(z_motion)],Age:5700,Glowing:1b,Tags:["lucky_block_drop","new"],Item:{id:"minecraft:player_head",count:1,components:{"minecraft:max_stack_size":4,"minecraft:item_name":{"text":"Lucky Block"},"minecraft:lore":[[{"color":"gray","italic":false,"text":"Use "},{"color":"white","italic":false,"keybind":"key.use"},{"color":"gray","italic":false,"text":" to open!"}],{"color":"gray","italic":false,"text":"I wonder what\'s inside..."}],"minecraft:hide_additional_tooltip":{},"minecraft:custom_data":{lucky_block:1b,default:1b},"minecraft:food":{nutrition:0,saturation:0,can_always_eat:true},"minecraft:consumable":{consume_seconds:1000001,has_consume_particles:false},"minecraft:profile":{id:[I;-2087206888,1259293576,-1271610310,-1658403980],properties:[{name:"textures",value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZTBhNDQzZTBlY2E3ZjVkMzA2MjJkZDkzN2YxZTVlYTJjZGYxNWQxMGMyN2ExOTljNjhhN2NlMDljMzlmNmI2OSJ9fX0="}]}}}}

$execute if score #random2 temp matches 4 if score #random temp matches 1..7 positioned ~$(x) ~$(y) ~$(z) if block ~ ~ ~ air run summon item ~ ~ ~ {Motion:[0.$(x_motion),0.$(y_motion),-0.$(z_motion)],Age:5700,Glowing:1b,Tags:["new","coin"],Item:{id:"minecraft:sunflower",count:1,components:{"minecraft:item_name":{"color":"gold","italic":false,"text":"Coin"},"minecraft:custom_data":{coin:1b}}}}
$execute if score #random2 temp matches 4 if score #random temp matches 8..9 positioned ~$(x) ~$(y) ~$(z) if block ~ ~ ~ air run summon item ~ ~ ~ {Motion:[0.$(x_motion),0.$(y_motion),-0.$(z_motion)],Age:5600,Glowing:1b,Tags:["new","gem"],Item:{id:"minecraft:emerald",count:1,components:{"minecraft:item_name":{"color":"green","italic":false,"text":"Gem"},"minecraft:custom_data":{gem:1b}}}}
$execute if score #random2 temp matches 4 if score #random temp matches 10..11 positioned ~$(x) ~$(y) ~$(z) if block ~ ~ ~ air run summon item ~ ~ ~ {Motion:[0.$(x_motion),0.$(y_motion),-0.$(z_motion)],Age:5700,Glowing:1b,Tags:["lucky_block_drop","new"],Item:{id:"minecraft:player_head",count:1,components:{"minecraft:max_stack_size":4,"minecraft:item_name":{"text":"Lucky Block"},"minecraft:lore":[[{"color":"gray","italic":false,"text":"Use "},{"color":"white","italic":false,"keybind":"key.use"},{"color":"gray","italic":false,"text":" to open!"}],{"color":"gray","italic":false,"text":"I wonder what\'s inside..."}],"minecraft:hide_additional_tooltip":{},"minecraft:custom_data":{lucky_block:1b,default:1b},"minecraft:food":{nutrition:0,saturation:0,can_always_eat:true},"minecraft:consumable":{consume_seconds:1000001,has_consume_particles:false},"minecraft:profile":{id:[I;-2087206888,1259293576,-1271610310,-1658403980],properties:[{name:"textures",value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZTBhNDQzZTBlY2E3ZjVkMzA2MjJkZDkzN2YxZTVlYTJjZGYxNWQxMGMyN2ExOTljNjhhN2NlMDljMzlmNmI2OSJ9fX0="}]}}}}

execute as @e[type=item,tag=!lucky_block_item,tag=!lucky_block_drop,tag=new,tag=coin] run team join coin
execute as @e[type=item,tag=!lucky_block_item,tag=!lucky_block_drop,tag=new,tag=gem] run team join gem
execute as @e[type=item,tag=!lucky_block_item,tag=lucky_block_drop,tag=new] run team join lucky_block
tag @e[tag=new] remove new