var scriptName = "FlyHCF";
var scriptAuthor = "LaVacheMilka";
var scriptVersion = 0.1;

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

function vClip(offset) {
    mc.thePlayer.setPosition(mc.thePlayer.posX, mc.thePlayer.posY + offset, mc.thePlayer.posZ);
}

function hClip(offset) {
    var playerYaw = Math.radians(mc.thePlayer.rotationYaw);
    mc.thePlayer.setPosition(mc.thePlayer.posX - (Math.sin(playerYaw) * offset), mc.thePlayer.posY, mc.thePlayer.posZ + (Math.cos(playerYaw) * offset));
}

function FlyModule() {
  var ticks = 0;
    this.getName = function() {
        return "FlyHCF";
    }

    this.getDescription = function() {
        return "Fly for hcfServer"
    }

    this.getCategory = function() {
        return "Movement";
    }

    this.onMotion = function() {
        mc.thePlayer.motionY *= 0.5;
        mc.timer.timerSpeed = 0.3;
        mc.thePlayer.onGround = true;

        if(mc.gameSettings.keyBindJump.isKeyDown())
            mc.thePlayer.motionY += 4.0;

        if(mc.gameSettings.keyBindSneak.isKeyDown())
            mc.thePlayer.motionY -= 4.0;

        if(mc.gameSettings.keyBindForward.isKeyDown()) {

            var yaw = Math.radians(mc.thePlayer.rotationYaw);

            mc.thePlayer.motionX = -Math.sin(yaw) * 8.0;
            mc.thePlayer.motionZ = Math.cos(yaw) * 8.0;
   } else {
            mc.thePlayer.motionX = 0.0;
            mc.thePlayer.motionZ = 0.0;
            mc.timer.timerSpeed = 0.3;
        }
}
    this.onDisable = function() {
        mc.timer.timerSpeed = 1;
        mc.thePlayer.motionX =0;
        mc.thePlayer.motionY =0;
        mc.thePlayer.motionZ =0;
    }
}

var flyModule = new FlyModule();
var devModuleClient;

function onEnable() {
    flyModuleClient = moduleManager.registerModule(flyModule);
}

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