script.import('lib/turtlBase.js');
scriptName = 'StrafeThing';
scriptVersion = 1.1;
scriptAuthor = 'York';
var sprintModule = moduleManager.getModule("Sprint");

var Values = [
    float = createFloat("StrafeStrenght", 0.5, 0, 1), // (text, defualt value, minimal value, maximal value) [float accepts decimal places]
    bool = createBoolean("NoMoveStop", false), // (text, state)
    secondbool = createBoolean("OnGroundStrafe", false), // (text, state)
    thirdbool = createBoolean("AllDirectionsJumps", false), // (text, state)
    fourthbool = createBoolean("AutoJump", false), // (text, state)
    fifthbool = createBoolean("AutoSprintJump", false), // (text, state)
];

var moduleName, moduleTag, moduleDescription, moduleCategory;

function simpleScript() {
    this.getName = function() {
        moduleName = name('StrafeRemade'); // usage - name(text[var/string]) //name of a module "simpleScript"
        modulesStr.push(moduleName); // pushes moduleName to a modulesStr which fixes values error
        return moduleName;
    };
    //this.getTag = function () {
    //moduleTag = tag(float.get()); // usage - tag(text[var/string]) //this module uses list selected thing as tag
    //return moduleTag;
    //};
    this.getDescription = function() {
        moduleDescription = description(moduleName + 'is a cool script!') //usage - description(text[var/string]); //sets description to "simpleScript is a cool script!"
        return moduleDescription;
    };
    this.getCategory = function() {
        moduleCategory = category('movement'); //usage - category(category[var/string]) //sets category to player
        return moduleCategory;
    };
    this.addValues = function(values) {
        for (val in Values) { //simple for loop
            values.add(Values[val]);
        };
    };
    this.onJump = function(event) {
        if (this.jump || this.jumpTwo) {
            event.cancelEvent()
        }
    }
    this.onUpdate = function() {
        if (mc.thePlayer.onGround && (mc.gameSettings.keyBindJump.isKeyDown() || fourthbool.get()) && thirdbool.get() && (mc.thePlayer.movementInput.moveForward || mc.thePlayer.movementInput.moveStrafe) && !(mc.thePlayer.isInWater() || mc.thePlayer.isInLava() || mc.thePlayer.isOnLadder() || mc.thePlayer.isInWeb)) {
            mc.gameSettings.keyBindJump.pressed = false;
            this.yaw = mc.thePlayer.rotationYaw;
            mc.thePlayer.rotationYaw = getMoveYaw();
            mc.thePlayer.jump();
            mc.thePlayer.rotationYaw = this.yaw;
            this.jump = true;
            mc.gameSettings.keyBindJump.pressed = true;
        } else {
            this.jump = false;
        }
        if (!thirdbool.get() && fourthbool.get() && mc.thePlayer.onGround && (mc.thePlayer.movementInput.moveForward || mc.thePlayer.movementInput.moveStrafe) && !(mc.thePlayer.isInWater() || mc.thePlayer.isInLava() || mc.thePlayer.isOnLadder() || mc.thePlayer.isInWeb)) {
            mc.gameSettings.keyBindJump.pressed = false;
            if (fifthbool.get() || mc.gameSettings.keyBindSprint.isKeyDown() || sprintModule.getState()) {
                mc.thePlayer.setSprinting(true);
            }
            mc.thePlayer.jump();
            this.jumpTwo = true;
            mc.gameSettings.keyBindJump.pressed = false;
        } else {
            this.jumpTwo = false;
        }
    }
    this.onMotion = function(event) { // executed 40times/second (40ticks/1second) - once per 0.025s (pre - 20ticks/s post - 20ticks/s), simply executed when you receive motion
        if (event.getEventState() == "PRE") {
            if (thirdbool.get() && (fifthbool.get() || (mc.gameSettings.keyBindSprint.isKeyDown() || sprintModule.getState())) && mc.thePlayer.onGround && (mc.gameSettings.keyBindJump.isKeyDown() || fourthbool.get()) && (mc.thePlayer.movementInput.moveForward || mc.thePlayer.movementInput.moveStrafe) && !(mc.thePlayer.isInWater() || mc.thePlayer.isInLava() || mc.thePlayer.isOnLadder() || mc.thePlayer.isInWeb)) {
                mc.thePlayer.setSprinting(true);
            } else if ((fifthbool.get() || (mc.gameSettings.keyBindSprint.isKeyDown() || sprintModule.getState())) && mc.thePlayer.moveForward > 0 && mc.thePlayer.onGround && (mc.gameSettings.keyBindJump.isKeyDown() || fourthbool.get()) && !(mc.thePlayer.isInWater() || mc.thePlayer.isInLava() || mc.thePlayer.isOnLadder() || mc.thePlayer.isInWeb)) {
                mc.thePlayer.setSprinting(true);
            }
        }
        if (event.getEventState() == "POST") {
            this.speed = (getSpeed() * float.get())
            this.motionX = (mc.thePlayer.motionX * (1 - float.get()))
            this.motionZ = (mc.thePlayer.motionZ * (1 - float.get()))
            if (!isMoving()) {
                if (bool.get()) {
                    mc.thePlayer.motionX = 0
                    mc.thePlayer.motionZ = 0
                }
                return;
            }
            if (!mc.thePlayer.onGround || secondbool.get()) {
                var yaw = getMoveYaw();
                mc.thePlayer.motionX = (((-Math.sin(Math.toRadians(yaw)) * this.speed) + this.motionX));
                mc.thePlayer.motionZ = (((Math.cos(Math.toRadians(yaw)) * this.speed) + this.motionZ));
            }
        }
    };
};

var modules = [ //add scripts functions here
    new simpleScript(),
];
var modulesStr = [ //add scripts names here
]

function onLoad() { // logs errors, if they are clear print in chat nothing, else print errors
    if (logs != '')
        chat.print(logs);
}

function onEnable() {
    for (r in modules) { //registers module
        moduleManager.registerModule(modules[r]);
    }
};

function onDisable() {
    for (d in modulesStr) { //disabling module before unregistering (fixes values bug)
        moduleManager.getModule(modulesStr[d]).state = false;
    }
    for (u in modules) { //unregistering module
        moduleManager.unregisterModule(modules[r]);
    }
};