var scriptName = "Nofall (Criticals compatible)";
var scriptAuthor = "Soulplexis";
var scriptVersion = 1.1;

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;

function Derp() {
	var Mode = value.createList("Mode", ["Normal", "Old", "Packet", "NoGround", "ACP", "ACP2", "Hypixel", "Glide", "NewHypixel", "Eyeshaft"], "Normal");
	var Debug = value.createBoolean("Debug", false);
    this.getName = function() {
        return "SoulNoFall";
    }
    this.getCategory = function() {
        return "Player";   
    }
var tick = 0;
    this.getDescription = function() {
        return "Damns yourself.";
    }
	var pickle = false;
	var swics = false;
	this.onDisable = function() {
	}
	this.onPacket = function(event) {
		var packet = event.getPacket();
		switch(Mode.get()) {
		case "Normal":
		if(mc.thePlayer.fallDistance > 2 && packet instanceof C03PacketPlayer) {
			packet.onGround = true;
			if(Debug.get()) {
		swics = !swics 
		if(swics) {
			chat.print("§c[Debug] §7OnGround! ");
		} else {
			chat.print("§c[Debug] §fOnGround! ");
		}
		}
		}
		break;
		case "Old":
		if(packet instanceof C03PacketPlayer && mc.thePlayer.onGround == false) {
			packet.onGround = true;
			if(Debug.get()) {
		swics = !swics 
		if(swics) {
			chat.print("§c[Debug] §7OnGround! ");
		} else {
			chat.print("§c[Debug] §fOnGround! ");
		}
		}
		}
		break;
		case "Packet":
		if(packet instanceof C03PacketPlayer && mc.thePlayer.onGround == false) {
			packet.onGround = true;
			packet.y = Math.floor(mc.thePlayer.posY);
			if(Debug.get()) {
		swics = !swics 
		if(swics) {
			chat.print("§c[Debug] §7Packet! ");
		} else {
			chat.print("§c[Debug] §fPacket! ");
		}
		}
		}
		break;
		case "NoGround":
		if(packet instanceof C03PacketPlayer) {
		packet.onGround = false;
		if(Debug.get()) {
		swics = !swics 
		if(swics) {
			chat.print("§c[Debug] §7NoGround! ");
		} else {
			chat.print("§c[Debug] §fNoGround! ");
		}
		}
		}
		break;
		case "ACP":
		if(mc.thePlayer.fallDistance > 2 && packet instanceof C03PacketPlayer) {
			packet.onGround = true;
			mc.thePlayer.motionX = 0;
			mc.thePlayer.motionZ = 0;
			packet.x = Math.floor(mc.thePlayer.posX);
			packet.z = Math.floor(mc.thePlayer.posZ);
			packet.y = Math.floor(mc.thePlayer.posY);
			if(Debug.get()) {
		swics = !swics 
		if(swics) {
			chat.print("§c[Debug] §7OnGround! ");
		} else {
			chat.print("§c[Debug] §fOnGround! ");
		}
		}
		}
		break;
		case "ACP2":
		if(mc.thePlayer.fallDistance > 2 && packet instanceof C03PacketPlayer) {
			packet.onGround = true;
			mc.thePlayer.motionX = 0;
			mc.thePlayer.motionZ = 0;
			mc.thePlayer.posX = Math.round(packet.x);
			mc.thePlayer.posY = Math.floor(mc.thePlayer.posY);
			mc.thePlayer.posZ = Math.round(packet.z);
			if(Debug.get()) {
		swics = !swics 
		if(swics) {
			chat.print("§c[Debug] §7OnGround! ");
		} else {
			chat.print("§c[Debug] §fOnGround! ");
		}
		}
		}
		break;
		case "Hypixel":
		pickle = !pickle;
		if(packet instanceof C03PacketPlayer && mc.thePlayer.onGround == false) {
			packet.onGround = pickle;
			if(Debug.get()) {
		swics = !swics 
		if(swics) {
			chat.print("§c[Debug] §7" + pickle);
		} else {
			chat.print("§c[Debug] §f" + pickle);
		}
		}
		}
		break;
		case "NewHypixel":
		if(mc.thePlayer.fallDistance > 2 && packet instanceof C03PacketPlayer) {
			packet.onGround = true;
			mc.thePlayer.posY = mc.thePlayer.posY - 0.12;
			if(Debug.get()) {
		swics = !swics 
		if(swics) {
			chat.print("§c[Debug] §7OnGround! ");
		} else {
			chat.print("§c[Debug] §fOnGround! ");
		}
		}
		}
		break;
		case "Glide":
		if(mc.thePlayer.fallDistance > 2 && packet instanceof C03PacketPlayer) {
			packet.onGround = true;
			mc.thePlayer.motionY *= 0.825;
			if(Debug.get()) {
		swics = !swics 
		if(swics) {
			chat.print("§c[Debug] §7OnGround! ");
		} else {
			chat.print("§c[Debug] §fOnGround! ");
		}
		}
		}
		break;
		case "Eyeshaft":
		if(mc.thePlayer.fallDistance > 2 && packet instanceof C03PacketPlayer) {
			packet.onGround = true;
			mc.thePlayer.setPosition(mc.thePlayer.posX, mc.thePlayer.posY + 1.125, mc.thePlayer.posZ);
			if(Debug.get()) {
		swics = !swics 
		if(swics) {
			chat.print("§c[Debug] §7OnGround! ");
		} else {
			chat.print("§c[Debug] §fOnGround! ");
		}
		}
		}
		break;
		}
		
	}
	this.addValues = function(soul) {
		soul.add(Mode);
		soul.add(Debug);
	}
		this.getTag = function() {
    return Mode.get()
}
}

var derp = new Derp();
var derpClient;

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

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