var scriptName = "Jump Modifier";
var scriptAuthor = "Soulplexis"; 
var scriptVersion = 1.4;

var strafe = moduleManager.getModule("Strafe");
function Module() {
	var Motion = value.createFloat("Motion", 0.42, 0.01, 1.00);
	var ChangeJumpMovementFactor = value.createBoolean("ChangeJumpMovementFactor", false);
	var JumpMovementFactor = value.createFloat("JumpMovementFactor", 0.18, 0.01, 1.00);
	var VClip = value.createBoolean("VClip", false);
	var VClipDistance = value.createFloat("VClipDistance", 0.50, 0.00, 5.00);
	var Strafe = value.createBoolean("Strafe", false);
	var Gravity = value.createBoolean("Gravity", false);
	var GravityDown = value.createBoolean("GravityDown", true);
	var GravityDownMode = value.createList("GravityDownMode", ["Multiply", "Reduce"], "Multiply");
	var GravityDownAmount = value.createFloat("GravityDownAmount", 1.03, 1.00, 1.15);
	var GravityUp = value.createBoolean("GravityUp", true);
	var GravityUpMode = value.createList("GravityUpMode", ["Multiply", "Reduce"], "Multiply");
	var GravityUpAmount = value.createFloat("GravityUpAmount", 1.03, 1.00, 1.15);
	var NoFlyZone = value.createBoolean("NoFlying", true);
	//var GravityAmount = value.createFloat("GravityAmount", 1.03, 1.00, 1.10);
	//var GravityMode = value.createList("GravityMode", ["Multiply", "Reduce"], "Multiply");
    this.getName = function() {
        return "HyperJump";
    }
    this.getCategory = function() {
        return "Movement";   
    }

    this.getDescription = function() {
        return "Modify jumping.";
    }
	//
    this.onEnable = function() {
		
    }
	this.onUpdate = function() {
		if(NoFlyZone.get()) {
			mc.thePlayer.capabilities.isFlying = false;
		}
		if(mc.gameSettings.keyBindJump.pressed && mc.thePlayer.onGround) {
					mc.thePlayer.motionY = Motion.get();
					mc.gameSettings.keyBindJump.pressed = false;
			if(VClip.get() == true) {
			mc.thePlayer.setPosition(mc.thePlayer.posX, mc.thePlayer.posY + VClipDistance.get(), mc.thePlayer.posZ);
		}
		} // cant get it to work in onJump i tried N; a method was found, but i'm too lazy to implement it .
		if(ChangeJumpMovementFactor.get() == true) {
		mc.thePlayer.jumpMovementFactor = JumpMovementFactor.get();
		}
		if(Strafe.get() == true) {
			var moveSpeed = MathHelper.sqrt_double(mc.thePlayer.motionX * mc.thePlayer.motionX + mc.thePlayer.motionZ * mc.thePlayer.motionZ);
			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.motionX = forward * moveSpeed * mx + strafe * moveSpeed * mz;
                    mc.thePlayer.motionZ = forward * moveSpeed * mz - strafe * moveSpeed * mx;
	    	}
		if(Gravity.get() == true) {
			if((GravityUp.get() && mc.thePlayer.motionY > 0)){
		    	switch(GravityUpMode.get()) {
			    	case "Multiply":
	         		mc.thePlayer.motionY *= GravityUpAmount.get();
		     		break;
		     		case "Reduce":
		         	mc.thePlayer.motionY += GravityUpAmount.get() - 1;
		    		break;
	    		}
			}
			if((GravityDown.get() && mc.thePlayer.motionY < 0)){
		    	switch(GravityDownMode.get()) {
			    	case "Multiply":
	         		mc.thePlayer.motionY *= GravityDownAmount.get();
		     		break;
		     		case "Reduce":
		         	mc.thePlayer.motionY += GravityDownAmount.get() - 1;
		    		break;
	    		}
			}
		}
	}

	this.onDisable = function() {
		if(Strafe.get() == true) {
			strafe.setState(false);
		}
		
	}
	this.addValues = function(soul) {
		soul.add(Motion);
		soul.add(ChangeJumpMovementFactor);
		soul.add(JumpMovementFactor);
		soul.add(VClip);
		soul.add(VClipDistance);
		soul.add(Strafe);
		soul.add(Gravity);
		soul.add(GravityUp);
		soul.add(GravityUpMode);
		soul.add(GravityUpAmount);
		soul.add(GravityDown);
		soul.add(GravityDownMode);
		soul.add(GravityDownAmount);
		soul.add(NoFlyZone);
		//soul.add(GravityMode);
		//soul.add(GravityAmount);
	}
}

var module = new Module();
var moduleClient;

function onEnable() {
    moduleClient = moduleManager.registerModule(module);
}

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