john.sk

Created by ThatOneLilypad

Just so you know, we don't know the file format for every file. If it's just a bunch of random characters, it's probably a .zip or .jar.

function doTheCubePhysicsStuff(il: location, i: itemtype):
    set {_id} to first element of (random uuid split at "-")

    set {-cube::%{_id}%::1::loc} to loc(.5, -.5, .5)
    set {-cube::%{_id}%::2::loc} to loc(-.5, -.5, -.5)
    set {-cube::%{_id}%::3::loc} to loc(-.5, -.5, .5)
    set {-cube::%{_id}%::4::loc} to loc(.5, -.5, -.5)

    set {-cube::%{_id}%::5::loc} to loc(.5, .5, .5)
    set {-cube::%{_id}%::6::loc} to loc(-.5, .5, -.5)
    set {-cube::%{_id}%::7::loc} to loc(-.5, .5, .5)
    set {-cube::%{_id}%::8::loc} to loc(.5, .5, -.5)

    loop indices of {-cube::%{_id}%::*}:
        set {-cube::%{_id}%::%loop-value%::vel} to vector(0, 0, 0)
    
    loop indices of {-cube::%{_id}%::*}:
        set {-cube::%{_id}%::%loop-value%::loc} to {_il} ~ (vector from {-cube::%{_id}%::%loop-value%::loc})
    
    spawn 1 armor stand at {_il} with nbt "{Rotation:[0f,0f],NoGravity:1,Silent:1,Invisible:1}"
    set {_e} to last spawned entity
    equip {_e} with {_i}
    add "specialCube" to scoreboard tags of {_e}
    add "ID: %{_id}%" to scoreboard tags of {_e}
    add {_e} to {-cube::*}
    set {_sl} to 1
    set {_dl} to sqrt({_sl}^2 + {_sl}^2)
    set {_il} to sqrt({_dl}^2 + {_sl}^2)
    while {_e} is alive:
        loop indices of {-cube::%{_id}%::*}:
            applyForces(1, 5, {_sl}, {_id})
            applyForces(2, 6, {_sl}, {_id})
            applyForces(3, 7, {_sl}, {_id})
            applyForces(4, 8, {_sl}, {_id})

            applyForces(5, 7, {_sl}, {_id})
            applyForces(8, 6, {_sl}, {_id})
            applyForces(1, 3, {_sl}, {_id})
            applyForces(4, 2, {_sl}, {_id})

            applyForces(7, 6, {_sl}, {_id})
            applyForces(5, 8, {_sl}, {_id})
            applyForces(3, 2, {_sl}, {_id})
            applyForces(1, 4, {_sl}, {_id})

            applyForces(5, 4, {_dl}, {_id})
            applyForces(8, 2, {_dl}, {_id})
            applyForces(6, 3, {_dl}, {_id})
            applyForces(7, 1, {_dl}, {_id})

            applyForces(7, 8, {_dl}, {_id})
            applyForces(5, 6, {_dl}, {_id})
            applyForces(1, 2, {_dl}, {_id})
            applyForces(4, 3, {_dl}, {_id})

            applyForces(8, 1, {_dl}, {_id})
            applyForces(5, 3, {_dl}, {_id})
            applyForces(7, 2, {_dl}, {_id})
            applyForces(6, 4, {_dl}, {_id})

            applyForces(8, 3, {_il}, {_id})
            applyForces(7, 4, {_il}, {_id})
            applyForces(5, 2, {_il}, {_id})
            applyForces(6, 1, {_il}, {_id})

            if block at ({-cube::%{_id}%::%loop-value%::loc} ~ {-cube::%{_id}%::%loop-value%::vel}) is not air:
                set {-cube::%{_id}%::%loop-value%::vel} to {-cube::%{_id}%::%loop-value%::vel} ** vector(-.9, -.9, -.9)
            else:
                set {-cube::%{_id}%::%loop-value%::vel} to {-cube::%{_id}%::%loop-value%::vel} ++ vector(0, -.05, 0) if {-cube::gravity} is true
                set {-cube::%{_id}%::%loop-value%::loc} to {-cube::%{_id}%::%loop-value%::loc} ~ {-cube::%{_id}%::%loop-value%::vel}
                set {-cube::%{_id}%::%loop-value%::vel} to {-cube::%{_id}%::%loop-value%::vel} ** vector(.95, .95, .95)
            add {-cube::%{_id}%::%loop-value%::loc} to {_l::*}

        set {_o} to mid({_l::*})
        clear {_l::*}

        set {_vx} to normalized vector from {_o} to mid(({-cube::%{_id}%::1::loc}, {-cube::%{_id}%::4::loc}, {-cube::%{_id}%::5::loc} and {-cube::%{_id}%::8::loc}))

        set {_vy} to normalized vector from {_o} to mid(({-cube::%{_id}%::5::loc}, {-cube::%{_id}%::6::loc}, {-cube::%{_id}%::7::loc} and {-cube::%{_id}%::8::loc}))

        set {_vz} to normalized vector from {_o} to mid(({-cube::%{_id}%::1::loc}, {-cube::%{_id}%::3::loc}, {-cube::%{_id}%::5::loc} and {-cube::%{_id}%::7::loc}))

        set {_dx} to angle between {_vx} and vector(1, 0, 0)
        set {_dy} to angle between {_vy} and vector(0, 1, 0)
        set {_dz} to angle between {_vz} and vector(0, 0, 1)

        add "{Pose:{Head:[%{_dx}%f,%{_dz}%f,%{_dy}%f]}}" to nbt of {_e}
        teleport {_e} to {_o} ~ vector(0, -1.5, 0)

        loop all players in radius 1.5 of {_e}:
            loop indices of {-cube::%{_id}%::*}:
                set {-cube::%{_id}%::%loop-value-2%::vel} to {-cube::%{_id}%::%loop-value-2%::vel} ++ (vector between loop-player and ({_e} ~ vector(0, 1.5, 0))) // vector(3, 3, 3)

        wait 1 tick

function mid(l: locations) :: location:
    loop {_l::*}:
        add x location of loop-value to {_x}
        add y location of loop-value to {_y}
        add z location of loop-value to {_z}
    return location(({_x} / size of {_l::*}), ({_y} / size of {_l::*}), ({_z} / size of {_l::*}), world of {_l::1})

function loc(x: number, y: number, z: number) :: location:
    return location({_x}, {_y}, {_z}, world "world")

function calcSpringStuff(al: location, bl: location, l: number, s: number) :: vectors:
    set {_f} to vector from {_al} to {_bl}
    set {_x} to (vector length of {_f}) - {_l}
    set {_f} to (normalized {_f}) ** vector({_s}, {_s}, {_s}) ** vector({_x}, {_x}, {_x})
    return {_f} and {_f} ** vector(-1, -1, -1)

function applyForces(a: integer, b: integer, l: number, id: text):
    set {_f::*} to calcSpringStuff({-cube::%{_id}%::%{_a}%::loc}, {-cube::%{_id}%::%{_b}%::loc}, {_l}, .5)
    set {-cube::%{_id}%::%{_a}%::vel} to {-cube::%{_id}%::%{_a}%::vel} ++ {_f::1} ** vector(.1, .1, .1)
    set {-cube::%{_id}%::%{_b}%::vel} to {-cube::%{_id}%::%{_b}%::vel} ++ {_f::2} ** vector(.1, .1, .1)

on load:
    set {-cube::gravity} to true if {-cube::gravity} is not set

command /john <text> [<text>] [<integer=1>]:
    usage: &c/john (spawn | kill | gravity | debug) <item type> [count]
    trigger:
        if arg-1 = "spawn":
            set {_i} to arg-2 parsed as itemtype
            if {_i} is set:
                loop arg-3 times:
                    doTheCubePhysicsStuff((player ~ vector(0, 2, 0)), {_i})
                    wait 1 tick
            else:
                send "&c/john spawn <item type> [count]"
        else if arg-1 = "debug":
            loop {-cube::*}:
                set display name of loop-value to 2nd element of scoreboard tags of loop-value
            wait 15 seconds
            loop {-cube::*}:
                reset display name of loop-value
        else if arg-1 = "kill":
            loop {-cube::*}:
                kill loop-value
            send "&aThe deed has been done"
        else if arg-1 = "gravity":
            set {-cube::gravity} to true if {-cube::gravity} is false, else false
            send "&aGravity is now set to %{-cube::gravity}%"
        else:
            send "&c/john (spawn | kill | gravity | debug) <item type> [count]"

on arm swing:
    if player's tool is blaze rod:
        kill target entity if target entity has scoreboard tag "specialCube"