var scriptName = "SScaffold";
var scriptAuthor = "6Sence";
var scriptVersion = 1.0;

Math.radians = function (degrees) {
    return degrees * Math.PI / 180;
};

// Converts from radians to degrees.
Math.degrees = function (radians) {
    return radians * 180 / Math.PI;
};
function randomIntFrom(min,max) // Get a random integer from [min] to [max] 
{
    return Math.floor(Math.random()*(max-min+1)+min);
}
var C06PlayerPacket = Java.type('net.minecraft.network.play.client.C03PacketPlayer.C06PacketPlayerPosLook');
var C04PacketPlayerPosition = Java.type('net.minecraft.network.play.client.C03PacketPlayer.C04PacketPlayerPosition')
var C05PacketPlayerLook = Java.type('net.minecraft.network.play.client.C03PacketPlayer.C05PacketPlayerLook');
var C03PacketPlayer = Java.type('net.minecraft.network.play.client.C03PacketPlayer');
var S08PacketPlayerPosLook = Java.type("net.minecraft.network.play.server.S08PacketPlayerPosLook");
var packet;
var Scaffold = moduleManager.getModule("Scaffold");
var Tower = moduleManager.getModule("Tower");
var KillAura = moduleManager.getModule("KillAura");
var Eagle = moduleManager.getModule("Eagle");
function motion(offset){
	mc.thePlayer.motionX = 0
	mc.thePlayer.motionZ = 0
if (mc.gameSettings.keyBindRight.pressed == true && mc.gameSettings.keyBindForward.pressed == false && mc.gameSettings.keyBindLeft.pressed == false && mc.gameSettings.keyBindBack.pressed == false){
	mc.thePlayer.motionX = parseFloat(Math.cos(Math.radians(mc.thePlayer.rotationYaw)) * offset * -1)
	mc.thePlayer.motionZ = parseFloat(Math.sin(Math.radians(mc.thePlayer.rotationYaw)) * offset * -1)
}
if (mc.gameSettings.keyBindForward.pressed == true && mc.gameSettings.keyBindRight.pressed == false && mc.gameSettings.keyBindLeft.pressed == false && mc.gameSettings.keyBindBack.pressed == false){
	mc.thePlayer.motionX = parseFloat(Math.cos(Math.radians(mc.thePlayer.rotationYaw + 90.0)) * offset)
	mc.thePlayer.motionZ = parseFloat(Math.sin(Math.radians(mc.thePlayer.rotationYaw + 90.0)) * offset)
}
if (mc.gameSettings.keyBindLeft.pressed == true && mc.gameSettings.keyBindRight.pressed == false && mc.gameSettings.keyBindForward.pressed == false && mc.gameSettings.keyBindBack.pressed == false){
	mc.thePlayer.motionX = parseFloat(Math.cos(Math.radians(mc.thePlayer.rotationYaw)) * offset)
	mc.thePlayer.motionZ = parseFloat(Math.sin(Math.radians(mc.thePlayer.rotationYaw)) * offset)
}
if (mc.gameSettings.keyBindBack.pressed == true && mc.gameSettings.keyBindRight.pressed == false && mc.gameSettings.keyBindForward.pressed == false && mc.gameSettings.keyBindLeft.pressed == false){
	mc.thePlayer.motionX = parseFloat(Math.cos(Math.radians(mc.thePlayer.rotationYaw + 90.0)) * offset * -1)
	mc.thePlayer.motionZ = parseFloat(Math.sin(Math.radians(mc.thePlayer.rotationYaw + 90.0)) * offset * -1)
}

if (mc.gameSettings.keyBindRight.pressed == true && mc.gameSettings.keyBindForward.pressed == false && mc.gameSettings.keyBindLeft.pressed == false && mc.gameSettings.keyBindBack.pressed == true){
	mc.thePlayer.motionX = parseFloat(Math.cos(Math.radians(mc.thePlayer.rotationYaw + 90.0) + 90) * offset)
	mc.thePlayer.motionZ = parseFloat(Math.sin(Math.radians(mc.thePlayer.rotationYaw + 90.0) + 90) * offset)
}
if (mc.gameSettings.keyBindRight.pressed == true && mc.gameSettings.keyBindForward.pressed == true && mc.gameSettings.keyBindLeft.pressed == false && mc.gameSettings.keyBindBack.pressed == false){
	mc.thePlayer.motionX = parseFloat(Math.cos(Math.radians(mc.thePlayer.rotationYaw + 90.0) + 45) * offset)
	mc.thePlayer.motionZ = parseFloat(Math.sin(Math.radians(mc.thePlayer.rotationYaw + 90.0) + 45) * offset)
}
if (mc.gameSettings.keyBindRight.pressed == false && mc.gameSettings.keyBindForward.pressed == true && mc.gameSettings.keyBindLeft.pressed == true && mc.gameSettings.keyBindBack.pressed == false){
	mc.thePlayer.motionX = parseFloat(Math.cos(Math.radians(mc.thePlayer.rotationYaw + 90.0) + -45) * offset)
	mc.thePlayer.motionZ = parseFloat(Math.sin(Math.radians(mc.thePlayer.rotationYaw + 90.0) + -45) * offset)
}
if (mc.gameSettings.keyBindRight.pressed == false && mc.gameSettings.keyBindForward.pressed == false && mc.gameSettings.keyBindLeft.pressed == true && mc.gameSettings.keyBindBack.pressed == true){
	mc.thePlayer.motionX = parseFloat(Math.cos(Math.radians(mc.thePlayer.rotationYaw + 90.0) - 90) * offset)
	mc.thePlayer.motionZ = parseFloat(Math.sin(Math.radians(mc.thePlayer.rotationYaw + 90.0) - 90) * offset)
}
}
function isMoving() {
    if (mc.gameSettings.keyBindForward.pressed == true || mc.gameSettings.keyBindBack.pressed == true || mc.gameSettings.keyBindLeft.pressed == true || mc.gameSettings.keyBindRight.pressed == true) {
        return true;
    }else{
        return false;
    }
}

function SScaffold() {
	var Mode = value.createList("Mode", ["Vanilla", "Cubecraft","Mineplex","Hypixel"], "Cubecraft");
	this.addValues = function(soul) {
        soul.add(Mode);
    }
    this.getName = function () {
        return "BlockFly";
    }
    this.getCategory = function () {
        return "Fun";
    }

    this.getDescription = function () {
        return "BlockFly";
    }

    this.onUpdate = function () {	
		mc.timer.timerSpeed = 1;
		if (isMoving()){
			ticks++;
		}else{
			ticks = 0;
		}
			
		if (mc.thePlayer.onGround) {
			offGroundTicks = 0;
		} else {
			offGroundTicks += 1;
		}
		if (isMoving() && mc.gameSettings.keyBindJump.pressed == false){
				Tower.setState(false);
				Scaffold.setState(true);
		}else if (isMoving() && mc.gameSettings.keyBindJump.pressed == true){
				if (Mode.get() != "Mineplex" && Mode.get() != "Cubecraft"){
					motion(0.1);
					Tower.setState(true);
					Scaffold.setState(false);
				}
				if (Mode.get() == "Cubecraft"){
					Tower.setState(false);
					Scaffold.setState(true);
				}
		}else if (!isMoving() && mc.gameSettings.keyBindJump.pressed == true){
				if (Mode.get() != "Mineplex"){
					Scaffold.setState(false);
				}
				if (Mode.get() == "Cubecraft"){
					Tower.setState(true);
				}
				if (Mode.get() == "Hypixel"){
					Tower.setState(true);
				}
				if (Mode.get() == "Vanilla"){
					Tower.setState(true);
				}
		}else{
			Tower.setState(false);
			Scaffold.setState(true);
			motion(0);
		}
		if (ticks == 3){
			ticks = 0;
		}
		if (Mode.get() == "Mineplex"){
			motion(0.16);
			if (mc.gameSettings.keyBindJump.pressed){
				mc.thePlayer.motionY -= 0.025;
				if (mc.thePlayer.onGround){
					mc.thePlayer.jump();
				}
			}
		}

		if (Mode.get() == "Cubecraft"){
			if (mc.gameSettings.keyBindJump.pressed){
				if (mc.thePlayer.onGround){
					motion(0);
				}
			}
		}

		if (Mode.get() == "Mineplex"){
			Scaffold.setState(true);
		}
	} 
    this.onEnable = function () {
		ticks = 0;	
		KillAura.getValue("fov").set(0);
		wasonground = false;
		oPosX = mc.thePlayer.posX;
		oPosZ = mc.thePlayer.posZ;
		offGroundTicks = 0;
    }
    this.onDisable = function () {
		Scaffold.getValue("Rotations").set(true);
		KillAura.getValue("fov").set(180);
		mc.timer.timerSpeed = 1;
		Tower.setState(false);
		Scaffold.setState(false);
		motion(0.13);
	}

}

var SScaffold = new SScaffold();
var derpClient;

function onEnable() {
    derpClient = moduleManager.registerModule(SScaffold);
}

function onDisable() {
    moduleManager.unregisterModule(derpClient);
}