var scriptName = "AntiFall"; // The name of your script
var scriptVersion = 1.1; // The version of your script 
var scriptAuthor = "You"; // The author of your script (eg. your username)

var exampleModule = new ExampleModule();
var exampleModuleClient;

var C04PacketPlayerPosition = Java.type('net.minecraft.network.play.client.C03PacketPlayer.C04PacketPlayerPosition');
var AxisAlignedBB = Java.type('net.minecraft.util.AxisAlignedBB');
function ExampleModule() {
	var dis = value.createInteger("FallDis",7,1,15);
	var onlyvoid = value.createBoolean("OnlyVoid",true);
    this.getName = function() {
        return "AntiFall";
    };

    this.getDescription = function() {
        return "This module has been created using LiquidBounce's scripting API.";
    };

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

	this.addValues = function(values) {
		values.add(dis);
		values.add(onlyvoid);
	}
	function isBlockUnder(){
		if (mc.thePlayer.posY < 0){
			return false;
		}
		if(!onlyvoid.get()){
			return false;
		}
		for (var off = 0; off < mc.thePlayer.posY.toFixed(0) + 2; off += 2) {
			if (!mc.theWorld.getCollidingBoundingBoxes(mc.thePlayer, mc.thePlayer.boundingBox.offset(0, -off, 0)).isEmpty()) {
				return true;
			}
		}
		return false;
	}
    this.onMove = function(event) {
        if(mc.thePlayer.fallDistance > dis.get() && !isBlockUnder()){
			mc.thePlayer.sendQueue.addToSendQueue(new C04PacketPlayerPosition(mc.thePlayer.posX,mc.thePlayer.posY + 12, mc.thePlayer.posZ, false));
			//chat.print("Sended");
			mc.thePlayer.fallDistance = 0;
		}
    }
}

function onLoad() {
    // Currently this event has to be in every script even if it is not directly needed.
};

function onEnable() {
    exampleModuleClient = moduleManager.registerModule(exampleModule);
};

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