execute unless entity @s[tag=rerolling] run particle minecraft:poof ~ ~0.5 ~ 0 0 0 0.5 75 force @a
execute unless entity @s[tag=rerolling] run playsound minecraft:item.wolf_armor.damage block @a ~ ~ ~ 1 0
execute unless entity @s[tag=rerolling] run playsound minecraft:block.glass.break block @a ~ ~ ~ 1 1
execute unless entity @s[tag=rerolling] run playsound minecraft:block.vault.reject_rewarded_player block @a ~ ~ ~ 0.75 0.65

execute unless entity @s[tag=rerolling] run execute if entity @s[tag=default] run particle block{block_state:"minecraft:yellow_stained_glass"} ~ ~0.75 ~ 0.5 0.5 0.5 1 50 normal

execute store result score #random temp run random value 1..73

# for testing outcomes (turn it into a comment when not testing)
# scoreboard players set #random temp 73

execute if entity @s[tag=unlucky] store result score #random temp run random value 16..30
execute if entity @s[tag=ultra_rare] run scoreboard players set #random temp -1

tag @s add lucky_block

## solo affecting outcomes
# solo positive outcomes (1-15)
execute if score #random temp matches 1 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/bouncy_stick
execute if score #random temp matches 2 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/bouncy_bow
execute if score #random temp matches 3 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/coins40
execute if score #random temp matches 4 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/gems15
execute if score #random temp matches 5 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/notch_apple
execute if score #random temp matches 6 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/phaic_blade
execute if score #random temp matches 7 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/ender_pearl
execute if score #random temp matches 8 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/bridge_snowball
execute if score #random temp matches 9 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/invulnerable
execute if score #random temp matches 10 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/lucky_boots
execute if score #random temp matches 11 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/flag_tp
execute if score #random temp matches 12 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/johnfry/start
execute if score #random temp matches 13 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/elytra
execute if score #random temp matches 14 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/enemy_teleport
execute if score #random temp matches 15 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/blocks
execute if score #random temp matches 62..70 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/random_scroll
execute if score #random temp matches 71 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/coins/init
execute if score #random temp matches 72 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/solo/gems/init

# solo negative outcomes (16-30)
execute if score #random temp matches 16 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/solo/bob
execute if score #random temp matches 17 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/solo/tax_collector/start
execute if score #random temp matches 18 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/solo/explode
execute if score #random temp matches 19 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/solo/poison_cloud
execute if score #random temp matches 20 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/solo/anvils/start
execute if score #random temp matches 21 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/solo/jump_rabbit/no_jump
execute if score #random temp matches 22 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/solo/infected
execute if score #random temp matches 23 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/solo/pie
execute if score #random temp matches 24 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/solo/dox
execute if score #random temp matches 25 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/solo/munchies
execute if score #random temp matches 26 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/solo/fountain/start
execute if score #random temp matches 27 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/solo/trap
execute if score #random temp matches 28 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/solo/launch
execute if score #random temp matches 29 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/solo/pants
execute if score #random temp matches 30 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/solo/donation
execute if score #random temp matches 73 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/solo/chicken_jockey

## team affecting outcomes
# team positive outcomes (31-40)
execute if score #random temp matches 31 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/team/explosive_arrows/start
execute if score #random temp matches 32 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/team/coins
execute if score #random temp matches 33 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/team/trap
execute if score #random temp matches 34 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/team/upgrade/start
execute if score #random temp matches 35 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/team/enchant/start
execute if score #random temp matches 36 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/team/invulnerable
execute if score #random temp matches 37 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/team/bridge_snowball
execute if score #random temp matches 38 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/team/hp
execute if score #random temp matches 39 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/team/lucky_block
execute if score #random temp matches 40 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/positive/team/crashing_economy/start

# team negative outcomes (41-50)
execute if score #random temp matches 41 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/team/smite/start
execute if score #random temp matches 42 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/team/enemy_heal
execute if score #random temp matches 43 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/team/cave_spiders/start
execute if score #random temp matches 44 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/team/blindness/start
execute if score #random temp matches 45 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/team/unlucky_blocks
execute if score #random temp matches 46 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/team/hole
execute if score #random temp matches 47 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/team/launch
execute if score #random temp matches 48 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/team/trap
execute if score #random temp matches 49 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/team/weak_knees
execute if score #random temp matches 50 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/negative/team/no_blocks

## global/neutral outcomes
# global or neutral outcomes (51-60)
execute if score #random temp matches 51 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/global/floor_is_lava/start
execute if score #random temp matches 52 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/global/wind_storm/start
execute if score #random temp matches 53 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/global/redlight_greenlight/start
execute if score #random temp matches 54 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/global/milk/start
execute if score #random temp matches 55 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/global/horses
execute if score #random temp matches 56 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/global/railgun/start
execute if score #random temp matches 57 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/global/invisible
execute if score #random temp matches 58 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/global/move_flags
execute if score #random temp matches 59 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID run function pctf:logic/items/lucky_block/outcomes/global/meteor_storm/start
execute if score #random temp matches 60 as @a[distance=..250] if score @s real_ID = @n[tag=lucky_block] real_ID at @s run function pctf:logic/items/lucky_block/outcomes/global/swap_places

## rare lucky block (61 only)
execute if score #random temp matches 61 run function pctf:logic/items/lucky_block/outcomes/rare_attempt

## rare outcomes (-1 only)
execute if score #random temp matches -1 run function pctf:logic/items/lucky_block/outcomes/rare/roll

tag @s remove lucky_block

execute as @e[type=item,tag=lucky_block_item] run data merge entity @s {Glowing:1b,PersistenceRequired:1b}