#Obtain random number
function zzzzdonotuse:generic/rng/randomnumber


#Store the parameter given into temp, then double it and add one to it.
scoreboard players operation #KyuRandomZTemp KyuDummy = #KyuRandomZ KyuDummy
scoreboard players set #KyuRangeShift KyuDummy 2
scoreboard players operation #KyuRandomZTemp KyuDummy *= #KyuRangeShift KyuDummy
scoreboard players add #KyuRandomZTemp KyuDummy1


#Use our random number and use the %= operator against our 2x+1 range value from above
scoreboard players operation #KyuRandomNumber KyuDummy %= #KyuRandomZTemp KyuDummy


#Subtract the initial parameter value from our remainder from the operation above. Effectively, this makes the final number result have a range that is (-z to +z), with z being the initial parameter value set by the user.
scoreboard players operation #KyuRandomNumber KyuDummy -= #KyuRandomZ KyuDummy


#Get current X coord, subtract the random number from it, and apply it to the position. Center the entity.
execute at @s run execute store result score @s PosX run data get entity @s Pos[0] 1
execute as @s run scoreboard players operation @s PosX -= #KyuRandomNumber KyuDummy
execute as @s run execute store result entity @s Pos[0] double 1 run scoreboard players get @s PosX
execute at @s run tp @s ~.5 ~ ~


#reset
scoreboard players reset #KyuRandomZTemp KyuDummy
#scoreboard players reset #KyuRandomZ KyuDummy






#
#
#
#
#
#
#
#
##same as before, but with the Z coord this time
#execute at @s run execute store result score @s KyuDummy run data get entity @s UUID[2] .1
#scoreboard players set @s KyuDummy2 3
#scoreboard players operation @s KyuDummy %= @s KyuDummy2
#scoreboard players remove @s KyuDummy 1
#execute at @s run execute store result score @s PosZ run data get entity @s Pos[2] 1
#execute as @s run scoreboard players operation @s PosZ -= @s KyuDummy
#execute as @s run execute store result entity @s Pos[2] double 1 run scoreboard players get @s PosZ
#
#
##try to find solid ground with air above it by moving up a few blocks
#execute at @s run execute unless block ~ ~1 ~ #suhc:bloodboltpassthrough run tag @s add MoveUp
#execute at @s run execute unless block ~ ~ ~ #suhc:bloodboltpassthrough run tag @s add MoveUp
#execute at @s run execute if block ~ ~-1 ~ #suhc:bloodboltpassthrough run tag @s add MoveUp
#execute at @s[tag=MoveUp] run tp @s ~ ~1 ~
#tag @s remove MoveUp
#
#execute at @s run execute unless block ~ ~1 ~ #suhc:bloodboltpassthrough run tag @s add MoveUp
#execute at @s run execute unless block ~ ~ ~ #suhc:bloodboltpassthrough run tag @s add MoveUp
#execute at @s run execute if block ~ ~-1 ~ #suhc:bloodboltpassthrough run tag @s add MoveUp
#execute at @s[tag=MoveUp] run tp @s ~ ~1 ~
#tag @s remove MoveUp
#
#execute at @s run execute unless block ~ ~1 ~ #suhc:bloodboltpassthrough run tag @s add MoveUp
#execute at @s run execute unless block ~ ~ ~ #suhc:bloodboltpassthrough run tag @s add MoveUp
#execute at @s run execute if block ~ ~-1 ~ #suhc:bloodboltpassthrough run tag @s add MoveUp
#execute at @s[tag=MoveUp] run tp @s ~ ~1 ~
#tag @s remove MoveUp
#
#execute at @s run execute unless block ~ ~1 ~ #suhc:bloodboltpassthrough run tag @s add MoveUp
#execute at @s run execute unless block ~ ~ ~ #suhc:bloodboltpassthrough run tag @s add MoveUp
#execute at @s run execute if block ~ ~-1 ~ #suhc:bloodboltpassthrough run tag @s add MoveUp
#execute at @s[tag=MoveUp] run tp @s ~ ~1 ~
#tag @s remove MoveUp
#
###if it hasn't found air yet, move back down to the start
#execute at @s run execute unless block ~ ~1 ~ #suhc:bloodboltpassthrough run tag @s add MoveBackDown
#execute at @s run execute unless block ~ ~ ~ #suhc:bloodboltpassthrough run tag @s add MoveBackDown
#execute at @s run execute if block ~ ~-1 ~ #suhc:bloodboltpassthrough run tag @s add MoveBackDown
#execute at @s[tag=MoveBackDown] run tp @s ~ ~-4 ~
##tag @s remove MoveBackDown
#
#
#
#
###same thing, but move down if it fails to find a spot by moving up. If all fails, die.
#execute at @s run execute unless block ~ ~1 ~ #suhc:bloodboltpassthrough run tag @s add MoveUp
#execute at @s run execute unless block ~ ~ ~ #suhc:bloodboltpassthrough run tag @s add MoveDown
#execute at @s run execute if block ~ ~-1 ~ #suhc:bloodboltpassthrough run tag @s add MoveDown
#execute at @s[tag=MoveDown] run tp @s ~ ~-1 ~
#tag @s remove MoveDown
#
#execute at @s run execute unless block ~ ~1 ~ #suhc:bloodboltpassthrough run tag @s add MoveUp
#execute at @s run execute unless block ~ ~ ~ #suhc:bloodboltpassthrough run tag @s add MoveDown
#execute at @s run execute if block ~ ~-1 ~ #suhc:bloodboltpassthrough run tag @s add MoveDown
#execute at @s[tag=MoveDown] run tp @s ~ ~-1 ~
#tag @s remove MoveDown
#
#execute at @s run execute unless block ~ ~1 ~ #suhc:bloodboltpassthrough run tag @s add MoveUp
#execute at @s run execute unless block ~ ~ ~ #suhc:bloodboltpassthrough run tag @s add MoveDown
#execute at @s run execute if block ~ ~-1 ~ #suhc:bloodboltpassthrough run tag @s add MoveDown
#execute at @s[tag=MoveDown] run tp @s ~ ~-1 ~
#tag @s remove MoveDown
#
#execute at @s run execute unless block ~ ~1 ~ #suhc:bloodboltpassthrough run tag @s add MoveUp
#execute at @s run execute unless block ~ ~ ~ #suhc:bloodboltpassthrough run tag @s add MoveDown
#execute at @s run execute if block ~ ~-1 ~ #suhc:bloodboltpassthrough run tag @s add MoveDown
#execute at @s[tag=MoveDown] run tp @s ~ ~-1 ~
#tag @s remove MoveDown
#
#execute at @s run execute unless block ~ ~1 ~ #suhc:bloodboltpassthrough run tag @s add MoveBackUp
#execute at @s run execute unless block ~ ~ ~ #suhc:bloodboltpassthrough run tag @s add MoveBackUp
#execute at @s run execute if block ~ ~-1 ~ #suhc:bloodboltpassthrough run tag @s add MoveBackUp
#execute as @s[tag=MoveBackUp] run kill @s
