#generic
execute as @e[type=zombified_piglin] at @s if entity @e[distance=..5,type=!zombified_piglin,predicate=!survivalplus:piglin_safety] run data modify entity @s AngryAt set from entity @n[distance=..5,type=!zombified_piglin,type=!#survivalplus:notalive,nbt=!{Invulnerable:1b},predicate=!survivalplus:piglin_safety] UUID
execute as @e[type=#survivalplus:horse,nbt={Age:0}] at @s unless data entity @s Passengers unless entity @a[distance=..2] as @n[type=#survivalplus:biped_hostile,tag=!merchant_face,tag=!dummy,distance=..2] at @s run ride @s mount @n[type=#survivalplus:horse,tag=!blood]
execute as @a[nbt={AbsorptionAmount:0f}] run effect clear @s minecraft:absorption
execute if entity @a[tag=40healthfull,nbt=!{Health:0f}] as @a[tag=40healthfull,nbt={AbsorptionAmount:0f}] run effect give @s minecraft:instant_health 1 4 true
tag @a[tag=40healthfull,nbt=!{Health:0f}] remove 40healthfull
execute as @a[predicate=survivalplus:upgradekit] at @s run function survivalplus:tools/firecompass/upgradekit
execute as @a[predicate=survivalplus:armorkit] at @s run function survivalplus:tools/firecompass/armorkit
execute if entity @e[tag=trinket] if entity @e[tag=zombmerchant,type=villager] run function survivalplus:merchants/trinketmerch
execute if entity @a[predicate=survivalplus:firecompass] as @a[predicate=survivalplus:firecompass,gamemode=!spectator] at @s anchored eyes run particle small_flame ^ ^ ^.5 .2 .2 .2 .01 5
execute if entity @e[tag=torch,type=item,nbt={Item:{count:1},OnGround:1b}] run function survivalplus:tools/autotorch
execute if entity @e[tag=bait,type=item,nbt={Item:{count:1}}] as @e[tag=bait] run function survivalplus:tools/chum/chum
execute if entity @e[tag=boss,tag=!ngboss] as @e[tag=boss,tag=!ngboss] run scoreboard players add @s time 1
execute if entity @e[tag=queen] at @e[type=bee,tag=queen,nbt={HasNectar:1b}] run particle minecraft:wax_on ~ ~.3 ~ .3 .2 .3 0 3
execute if entity @e[tag=trap] as @e[tag=trap] at @s run function survivalplus:tools/trap/1seceffects
execute if entity @a[predicate=survivalplus:item/cursed,predicate=survivalplus:100thchance] as @a[predicate=survivalplus:item/cursed] at @s run function survivalplus:tools/cursed/cursed
execute if entity @e[tag=itemguard] as @e[tag=itemguard] run function survivalplus:tools/itemguardeffect
execute if entity @e[tag=reforgekey] as @e[tag=reforgekey] at @s run function survivalplus:tools/reforge/reforgekey
execute if entity @e[tag=depthmeter] as @e[tag=depthmeter] at @s run function survivalplus:tools/reforge/add/depthmeter
execute if score wither death matches 1 if score time time matches 13000..23400 if predicate survivalplus:100thchance if predicate survivalplus:10chance at @e[type=!#survivalplus:notalive,limit=1,sort=random,predicate=survivalplus:overworld] run function survivalplus:tools/star/spawn
execute if entity @a[tag=906deaths] as @a[tag=906deaths] at @s run function survivalplus:tools/cursed/906blind
function survivalplus:tools/pot/timer
execute if entity @e[tag=dechant] as @e[tag=dechant] at @s if block ~ ~ ~ enchanting_table if entity @n[type=item,distance=...3,tag=!dechant,nbt={Item:{components:{"minecraft:enchantments":{}}}}] run function survivalplus:tools/ebook/dechant
execute if entity @a[tag=skysafe] at @a[tag=skysafe] run particle minecraft:effect
execute if entity @e[tag=firefuel,nbt={Item:{count:1}}] as @e[tag=firefuel,nbt={Item:{count:1}}] at @s if block ~ ~ ~ #campfires[lit=true] run function survivalplus:tools/campfire/blazefire
execute if entity @e[tag=findmemarker] as @e[tag=findmemarker] at @s if entity @p[distance=..15] run function survivalplus:tools/findmemarker
execute if entity @e[tag=spawnermod] as @e[tag=spawnermod,nbt={Item:{count:1}}] at @s if block ~ ~-.5 ~ spawner run function survivalplus:tools/spawnermod/sort
execute as @e[tag=item_snatcher,tag=!not_stole,predicate=survivalplus:5chance] run tag @s add not_stole
execute if entity @e[tag=wishing_fntn] as @e[tag=wishing_fntn] at @s run function survivalplus:tools/wishing_fountain
execute if entity @e[tag=bigbee,nbt={HasStung:1b}] as @e[tag=bigbee,nbt={HasStung:1b},predicate=survivalplus:10chance] run data merge entity @s {HasStung:0b}
execute if entity @a[predicate=survivalplus:pumpkinhat] run function survivalplus:tools/endermansus/sus

#unbloodmoon
execute unless score time time matches 13000..23400 run function survivalplus:bloodmoon/unupgrade_mob

#armor stuff
execute if entity @e[predicate=survivalplus:goldset] run effect give @e[predicate=survivalplus:goldset] luck 1 0 true
execute as @e[predicate=survivalplus:iceset] at @s run function survivalplus:tools/armor/icefield
#execute as @a[predicate=survivalplus:spacehat,predicate=survivalplus:space,nbt=!{OnGround:1b}] run effect give @s levitation 1 0 true
execute if entity @a[predicate=survivalplus:magicrobes] as @a[predicate=survivalplus:magicrobes,predicate=survivalplus:10chance,level=..24] run xp add @s 1 points
execute if entity @e[predicate=survivalplus:minershirt] run effect give @e[predicate=survivalplus:minershirt] haste 1 0 true
execute if entity @a[predicate=survivalplus:foodhat] run effect give @a[predicate=survivalplus:foodhat,predicate=survivalplus:1chance,scores={hunger=16..19}] saturation 1 0 true
execute as @a[nbt=!{equipment:{head:{components:{"minecraft:custom_data":{illagerhat:tag}}}}},team=illager] run team leave @s

#lucky foot
execute if entity @a[predicate=survivalplus:lucky_foot] run function survivalplus:tools/trinkets/lucky_foot

#hunger
execute if entity @a[scores={hunger=..8}] run function survivalplus:hunger
execute if entity @e[predicate=survivalplus:item/cooked_meat] run function survivalplus:tools/food/cooked_meat
execute if entity @e[predicate=survivalplus:item/raw_meat,predicate=survivalplus:cooking_pot] run function survivalplus:tools/food/raw_meat
execute if entity @e[tag=plantable] as @e[tag=plantable,predicate=survivalplus:plantable_crop] at @s unless entity @e[tag=wild_crop,distance=..1] run function survivalplus:tools/farming/plantsort
execute if entity @e[predicate=survivalplus:item/root_food,predicate=survivalplus:cooking_pot] run function survivalplus:tools/food/wild_pot

#final_destination
execute if entity @e[tag=portal,predicate=survivalplus:framework] if score hardmode hardmode matches 1 run function survivalplus:finale/activate
execute if entity @a[predicate=survivalplus:adventuremode,gamemode=survival] as @a[predicate=survivalplus:adventuremode,gamemode=survival] run gamemode adventure @s
#execute if entity @e[tag=gateway,type=marker] at @e[tag=gateway,type=marker] run function survivalplus:finale/gateway
execute if entity @e[tag=gateway,type=marker] as @e[tag=gateway,type=marker] at @s run function survivalplus:tools/newgame/portal
execute as @a[tag=deathgamemodefix,nbt=!{Health:0f},predicate=!survivalplus:adventuremode] run function survivalplus:tools/deathgamemodefix
execute if entity @e[tag=npc] as @e[tag=npc] at @s run function survivalplus:finale/quest/npcsec
execute if entity @e[tag=noberry] as @e[tag=noberry] at @s run function survivalplus:finale/berry/noberry
execute if entity @e[tag=goldtree] as @e[tag=goldtree,predicate=survivalplus:1chance,predicate=survivalplus:50chance] at @s run function survivalplus:finale/goldtree/tick
execute if entity @a[predicate=survivalplus:damage_wings] as @a[predicate=survivalplus:damage_wings,gamemode=adventure] run function survivalplus:finale/damage_wings

#devil deal
#execute if score challenge hardmode matches 1 run function survivalplus:giant_deal/challenge
execute if score bookstats hardmode matches 1..3 run function survivalplus:giant_deal/bookstats
execute if score bookstats hardmode matches 7 run tag @a add salvagespawner
execute if score bookstats hardmode matches 8 run tag @a add luckyfoot
execute if entity @e[scores={manalvl=1..}] as @e[scores={manalvl=1..},predicate=survivalplus:25chance] if score @s Level < @s manalvl run xp add @s 5 points

#misc
execute as @a run function survivalplus:hardmode_check

schedule function survivalplus:1sec .9s