var scriptName = "Hotbar spoof";
var scriptVersion = 1.0;
var scriptAuthor = "Soulplexiz";

var Nolagz = new Nolagz();
var NolagzClient;

var C09PacketHeldItemChange = Java.type('net.minecraft.network.play.client.C09PacketHeldItemChange');
function randomIntFrom(min,max) // Get a random integer from [min] to [max] 
{
    return Math.floor(Math.random()*(max-min+1)+min);
}

function Nolagz() {
	var Hotbar = value.createInteger("Slot", 9, 1, 9);
	var OnUse = value.createBoolean("OnUse", false);
	var Swing = value.createBoolean("Swing", true);
	var RandomSlot = value.createBoolean("RandomSlot", false);
	var Delay = value.createInteger("Delay", 10, 0, 50);
    this.getName = function () {
        return "HotBarSpoof";
    };

    this.getDescription = function () {
        return "When you right click, you will use the item in the specified slot.";
    };

    this.getCategory = function () {
        return "Player";
    };
	var tick = 0;
    this.onUpdate = function () {
		tick++;
		if(((mc.gameSettings.keyBindUseItem.pressed && OnUse.get() == true) || OnUse.get() == false)) {
			if(Swing.get() && mc.gameSettings.keyBindUseItem.pressed) {
			mc.thePlayer.swingItem();
			}
			if(RandomSlot.get() == false) {
				if(tick >= Delay.get()) {
			mc.thePlayer.sendQueue.addToSendQueue(new C09PacketHeldItemChange(Hotbar.get() - 1));
				tick = 0;
				}
			} else {
				if(tick >= Delay.get()) {
				mc.thePlayer.sendQueue.addToSendQueue(new C09PacketHeldItemChange(randomIntFrom(0,8)));
				tick = 0;
				}
			}
		}
    }
    
    this.onDisable = function() {
		returned = false;
		mc.rightClickDelayTimer = 4;
    }
    
    this.onEnable = function() {
			mc.rightClickDelayTimer = FastPlace.get();
    }
	this.addValues = function(ass) {
		ass.add(Hotbar);
		ass.add(OnUse);
		ass.add(Swing);
		ass.add(RandomSlot);
		ass.add(Delay);
	}
}

function onEnable() {
    NolagzClient = moduleManager.registerModule(Nolagz);
};

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