var scriptName = "CustomFastUse";
var scriptAuthor = "By Virus";
var scriptVersion = 1.0;

var Food = Java.type('net.minecraft.item.ItemFood');
var C03PacketPlayer = Java.type('net.minecraft.network.play.client.C03PacketPlayer');
var C04PacketPlayerPosition = Java.type('net.minecraft.network.play.client.C03PacketPlayer.C04PacketPlayerPosition');
var KeyBinding = Java.type('net.minecraft.client.settings.KeyBinding');

function StopMove() {
    KeyBinding.setKeyBindState(mc.gameSettings.keyBindForward.getKeyCode(), false);
    KeyBinding.setKeyBindState(mc.gameSettings.keyBindBack.getKeyCode(), false);
    KeyBinding.setKeyBindState(mc.gameSettings.keyBindLeft.getKeyCode(), false);
    KeyBinding.setKeyBindState(mc.gameSettings.keyBindRight.getKeyCode(), false);
    KeyBinding.setKeyBindState(mc.gameSettings.keyBindJump.getKeyCode(), false);
}

function SpeedMotion(Speed) {
    mc.thePlayer.motionX *= Speed;
    mc.thePlayer.motionZ *= Speed;
}

function EatModule() {
    var Modes = value.createList("Mode", ["Packet1", "Packet2", "Packet3", "Custom Packet", "Timer", "Timer1"], "Packet1");
    var Duration = value.createInteger("Duration", 1, 1, 31);
    var Speed = value.createInteger("Custom Speed Packet", 5, 1, 100);
    var Timer = value.createFloat("Timer", 1.15, 1.01, 1.50);
    var TimerTick = value.createInteger("Custom Timer Tick", 1, 1, 30);
    var NoMove = value.createBoolean("NoMove", false);
    var NoAir = value.createBoolean("NoAir", true);
    
    this.getName = function() {
        return "CustomFastUse";
    }
    this.getDescription = function() {
        return "Allows you to use items faster.";
    }
    this.getCategory = function() {
        return "Player"; 
    }
    this.getTag = function() {
        return Modes.get(); 
    };    
    this.onEnable = function() {   
        
    }
    this.onDisable = function() {
        mc.timer.timerSpeed = 1.0;
    }
    this.onUpdate = function() {
        if(NoAir.get() == true) {
            if(mc.thePlayer.onGround) {
                if(Modes.get() == "Custom Packet" && mc.thePlayer.getItemInUseDuration() > Duration.get() && mc.thePlayer.isEating() && mc.thePlayer.getHeldItem().getItem() instanceof Food) {
                    for (var x = 0; x < Speed.get(); x++) {
                        mc.thePlayer.sendQueue.addToSendQueue(new C03PacketPlayer(true));
                    }
                }
                if(Modes.get() == "Packet3" && mc.thePlayer.getItemInUseDuration() > Duration.get() && mc.thePlayer.isEating() && mc.thePlayer.getHeldItem().getItem() instanceof Food) {
                    for (var x = 0; x < 2; x++) {
                        mc.thePlayer.sendQueue.addToSendQueue(new C03PacketPlayer(false));
                    }
                }                
                if(Modes.get() == "Timer" && mc.thePlayer.getItemInUseDuration() > Duration.get() && mc.thePlayer.isEating() && mc.thePlayer.getHeldItem().getItem() instanceof Food) {
                    if(mc.thePlayer.ticksExisted % TimerTick.get() == 0) {
                        mc.timer.timerSpeed = Timer.get();
                    }else{
                        mc.timer.timerSpeed = 1.0;

                    }
                    
                }
                if(Modes.get() == "Timer1" && mc.thePlayer.getItemInUseDuration() > Duration.get() && mc.thePlayer.isEating() && mc.thePlayer.getHeldItem().getItem() instanceof Food) {
                    mc.timer.timerSpeed = Timer.get();
                    SpeedMotion(0.30);
                }else{
                    mc.timer.timerSpeed = 1.0;

                }
                if(Modes.get() == "Packet1" && mc.thePlayer.getItemInUseDuration() > Duration.get() && mc.thePlayer.isEating() && mc.thePlayer.getHeldItem().getItem() instanceof Food) {
                    mc.thePlayer.sendQueue.addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(mc.thePlayer.posX, mc.thePlayer.posY + 0.01, mc.thePlayer.posZ, false));
                }
                if(Modes.get() == "Packet2" && mc.thePlayer.getItemInUseDuration() > Duration.get() && mc.thePlayer.isEating() && mc.thePlayer.getHeldItem().getItem() instanceof Food) {
                    if(mc.thePlayer.ticksExisted % 5 == 0) {
                        mc.thePlayer.sendQueue.addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ, false));
                        mc.thePlayer.sendQueue.addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ, false));

                    }
                }
            }

        }

        if(NoAir.get() == false) {
            if(mc.thePlayer.onGround || !mc.thePlayer.onGround) {
                if(Modes.get() == "Custom Packet" && mc.thePlayer.getItemInUseDuration() > Duration.get() && mc.thePlayer.isEating() && mc.thePlayer.getHeldItem().getItem() instanceof Food) {
                    for (var x = 0; x < Speed.get(); x++) {
                        mc.thePlayer.sendQueue.addToSendQueue(new C03PacketPlayer(true));
                    }
                }
                if(Modes.get() == "Packet3" && mc.thePlayer.getItemInUseDuration() > Duration.get() && mc.thePlayer.isEating() && mc.thePlayer.getHeldItem().getItem() instanceof Food) {
                    for (var x = 0; x < 2; x++) {
                        mc.thePlayer.sendQueue.addToSendQueue(new C03PacketPlayer(false));
                    }
                }    
                if(Modes.get() == "Timer" && mc.thePlayer.getItemInUseDuration() > Duration.get() && mc.thePlayer.isEating() && mc.thePlayer.getHeldItem().getItem() instanceof Food) {
                    if(mc.thePlayer.ticksExisted % TimerTick.get() == 0) {
                        mc.timer.timerSpeed = Timer.get();
                    }else{
                        mc.timer.timerSpeed = 1.0;

                    }
                    
                }
                if(Modes.get() == "Timer1" && mc.thePlayer.getItemInUseDuration() > Duration.get() && mc.thePlayer.isEating() && mc.thePlayer.getHeldItem().getItem() instanceof Food) {
                    mc.timer.timerSpeed = Timer.get();
                    SpeedMotion(0.30);
                }else{
                    mc.timer.timerSpeed = 1.0;

                }
                if(Modes.get() == "Packet1" && mc.thePlayer.getItemInUseDuration() > Duration.get() && mc.thePlayer.isEating() && mc.thePlayer.getHeldItem().getItem() instanceof Food) {
                    mc.thePlayer.sendQueue.addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(mc.thePlayer.posX, mc.thePlayer.posY + 0.01, mc.thePlayer.posZ, false));
                }
                if(Modes.get() == "Packet2" && mc.thePlayer.getItemInUseDuration() > Duration.get() && mc.thePlayer.isEating() && mc.thePlayer.getHeldItem().getItem() instanceof Food) {
                    if(mc.thePlayer.ticksExisted % 5 == 0) {
                        mc.thePlayer.sendQueue.addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ, false));
                        mc.thePlayer.sendQueue.addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ, false));

                    }
                }

            }

        }     
        if(NoMove.get() == true) {
            if(mc.thePlayer.isEating() && mc.thePlayer.getHeldItem().getItem() instanceof Food) {
                StopMove();
            }
              
        }        

        
    }
    this.addValues = function(values) {
        values.add(Modes);
        values.add(Duration);
        values.add(Speed);
        values.add(Timer);
        values.add(TimerTick);
        values.add(NoAir);
        values.add(NoMove);
    }
}
var eatModule = new EatModule();
var eatModuleClient;

function onLoad() {}

function onEnable() {
    eatModuleClient = moduleManager.registerModule(eatModule);
}

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