
# -> Untag ent
tag @s remove OverlyRealistic.Item.TempSpearEnt

# -> Set rotation data based on origin
execute rotated as @p[tag=OverlyRealistic.Player.TempPlayerThrewSpear,distance=..5] run \
    rotate @s ~ ~

# -> Create display
summon minecraft:item_display ~ ~ ~ {Tags:["OverlyRealistic.TempEntSpear","OverlyRealistic.Item.SpearDisplayEnt"],teleport_duration:1,item: {count: 1, id: "minecraft:stick"}, transformation: {left_rotation: [0.2705981f, 0.6532815f, 0.2705981f, 0.6532815f], right_rotation: [0.0f, 0.0f, 0.0f, 1.0f], scale: [1.0f, 0.99999994f, 0.99999994f], translation: [0.0f, 0.0f, 0.0f]}}

# -> Attach display
ride @n[type=item_display,tag=OverlyRealistic.TempEntSpear,distance=..3] mount @s

# -> Operate on display
execute on passengers run \
    tag @s remove OverlyRealistic.TempEntSpear
execute rotated as @s \
    on passengers run \
        rotate @s ~ ~
execute on passengers run \
    scoreboard players operation @s OverlyRealistic.Player.UsingSpearID = @p[tag=OverlyRealistic.Player.TempPlayerThrewSpear] OverlyRealistic.Player.UsingSpearID
execute on passengers run \
    item replace entity @s contents from entity 00000001-0000-002b-0000-00010000002b contents

# -> Add motion
execute store result score #or.pos_x_0 OverlyRealistic.General.ArbitraryData run \
    data get entity @s Pos[0] 1000
execute store result score #or.pos_y_0 OverlyRealistic.General.ArbitraryData run \
    data get entity @s Pos[1] 1000
execute store result score #or.pos_z_0 OverlyRealistic.General.ArbitraryData run \
    data get entity @s Pos[2] 1000

execute at @s run \
    tp @s ^ ^ ^1

execute store result score #or.pos_x_1 OverlyRealistic.General.ArbitraryData run \
    data get entity @s Pos[0] 1000
execute store result score #or.pos_y_1 OverlyRealistic.General.ArbitraryData run \
    data get entity @s Pos[1] 1000
execute store result score #or.pos_z_1 OverlyRealistic.General.ArbitraryData run \
    data get entity @s Pos[2] 1000

scoreboard players operation #or.pos_x_1 OverlyRealistic.General.ArbitraryData -= #or.pos_x_0 OverlyRealistic.General.ArbitraryData
scoreboard players operation #or.pos_y_1 OverlyRealistic.General.ArbitraryData -= #or.pos_y_0 OverlyRealistic.General.ArbitraryData
scoreboard players operation #or.pos_z_1 OverlyRealistic.General.ArbitraryData -= #or.pos_z_0 OverlyRealistic.General.ArbitraryData

execute store result entity @s Motion[0] double 0.005 run \
    scoreboard players get #or.pos_x_1 OverlyRealistic.General.ArbitraryData

execute store result entity @s Motion[2] double 0.005 run \
    scoreboard players get #or.pos_z_1 OverlyRealistic.General.ArbitraryData

execute if score #or.pos_y_1 OverlyRealistic.General.ArbitraryData matches ..-200 \
    store result entity @s Motion[1] double 0.0015 run \
        return run \
            scoreboard players get #or.pos_y_1 OverlyRealistic.General.ArbitraryData

execute if score #or.pos_y_1 OverlyRealistic.General.ArbitraryData matches -199..600 \
    store result entity @s Motion[1] double 0.0035 run \
        return run \
            scoreboard players get #or.pos_y_1 OverlyRealistic.General.ArbitraryData

execute if score #or.pos_y_1 OverlyRealistic.General.ArbitraryData matches 600.. \
    store result entity @s Motion[1] double 0.0023 run \
        return run \
            scoreboard players get #or.pos_y_1 OverlyRealistic.General.ArbitraryData


