var scriptName = "Speed (NCPHop)"; 
var scriptVersion = 1.1; 
var scriptAuthor = "soulplexis";

var bHop = new BHop();
var bHopClient;
var MathHelper = Java.type("net.minecraft.util.MathHelper");
 Math.rad = function(deg) {
    return deg * Math.PI / 180;
  };
var Potion = Java.type("net.minecraft.potion.Potion");
var BlockPos = Java.type("net.minecraft.util.BlockPos");
function BHop() {
    this.getName = function() {
        return "NCPHop";
    };

    this.getDescription = function() {
        return "Basic bunny-hop speed."; 
    };

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

	this.onEnable = function() {
		var amped = false;
		var ampx = 0;
	}

    this.onUpdate = function() {
		if(!mc.thePlayer.onGround) {
			mc.thePlayer.setSprinting(true);  // this doesn't rly work i don't know why
		}
		if(mc.thePlayer.movementInput.moveForward != 0 || mc.thePlayer.movementInput.moveStrafe != 0) {
			mc.timer.timerSpeed = 1.08; 
        if(mc.thePlayer.onGround) {
	         mc.thePlayer.jump();
        }
       } else {
			mc.timer.timerSpeed = 1;
		}
		var moveSpeed = (MathHelper.sqrt_double(mc.thePlayer.motionX * mc.thePlayer.motionX + mc.thePlayer.motionZ * mc.thePlayer.motionZ));
		 if (mc.thePlayer.isPotionActive(Potion.moveSpeed)) {	
		var amp = mc.thePlayer.getActivePotionEffect(Potion.moveSpeed).getAmplifier();
	    } else {
			amp = undefined;
		}
		 switch(amp) { // is above 5 necessary? I'll try to do it sometime anyway but this is a workaround for now and should cover most speed effects you'll be seeing on servers
		     case 0:
			 moveSpeed = 0.31;
		     break;
			 case 1:
			 moveSpeed = 0.37;
			 break;
			case 2:
			moveSpeed = 0.41;
			break;
			case 3:
			moveSpeed = 0.45;
			break;
			case 4:
			moveSpeed = 0.49;
			break;
			case 5:
			moveSpeed = 0.53;
			break;
		}
			        var forward = mc.thePlayer.movementInput.moveForward;
                    var strafe = mc.thePlayer.movementInput.moveStrafe;
                    var yaw = mc.thePlayer.rotationYaw;
                    if (forward == 0 && strafe == 0) { 
                        mc.thePlayer.motionX = 0;
                        mc.thePlayer.motionZ = 0;
                    } else if (forward != 0) {
                        if (strafe >= 1.0) {
                            yaw = mc.thePlayer.rotationYaw + ((forward > 0.0) ? -45 : 45);
                            strafe = 0;
                        } else if (strafe <= -1.0) {
                            yaw = mc.thePlayer.rotationYaw + ((forward > 0.0) ? 45 : -45);
                            strafe = 0;
                        }
                    }

                    if (forward > 0) {
                        forward = 1;
                    } else if (forward < 0) {
                        forward = -1;
                    }
                    var mx = Math.cos(Math.rad(yaw + 90));
                    var mz = Math.sin(Math.rad(yaw + 90));
					mc.thePlayer.jumpMovementFactor = 0.029;
                    mc.thePlayer.motionX = forward * moveSpeed * mx + strafe * moveSpeed * mz;
                    mc.thePlayer.motionZ = forward * moveSpeed * mz - strafe * moveSpeed * mx;
    }
    this.onDisable = function() {
    	mc.timer.timerSpeed = 1.0;
    }
	this.addValues = function(soul) {
	}
}
function onLoad() {
};

function onEnable() {
    bHopClient = moduleManager.registerModule(bHop);
};

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