var scriptName = "FlyTp";
var scriptAuthor = "LaVacheMilka";
var scriptVersion = 1.0;

// 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 "FlyTp";
    }

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

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

    this.onUpdate = function() {
        mc.thePlayer.motionY *= 0.58;
        if(mc.thePlayer.ticksExisted % (20 * 1) == 0)
            vClip(2)

        if(mc.gameSettings.keyBindJump.isKeyDown()) 
           if(mc.thePlayer.ticksExisted % (2 * 1) == 0)
              vClip(2)

        if(mc.gameSettings.keyBindSneak.isKeyDown()) 
           if(mc.thePlayer.ticksExisted % (2 * 1) == 0)
              vClip(-2)

        if(mc.gameSettings.keyBindForward.isKeyDown()) {
           if(mc.thePlayer.ticksExisted % (2 * 1) == 0)
              hClip(2)
    } else {
            mc.thePlayer.motionX = 0.0;
            mc.thePlayer.motionZ = 0.0;
            mc.timer.timerSpeed = 1.0;
        }

}
    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);
}