Hi I'm having a problem at the moment where when I try to detect when the player left clicks. The code works but not exactly. When the player right clicks it changes the value not by 1 because they only clicked once but by how long they held down the button. Here is the code I'm using for it:
//TODO Get the left clicks to count each time instead of the time it was held down
if(Minecraft.getMinecraft().gameSettings.keyBindAttack.isKeyDown())
{
Clicks++;
}
Hi I'm having a problem at the moment where when I try to detect when the player left clicks. The code works but not exactly. When the player right clicks it changes the value not by 1 because they only clicked once but by how long they held down the button. Here is the code I'm using for it:
if(Minecraft.getMinecraft().gameSettings.keyBindAttack.isKeyDown())
{
Clicks++;
}
Clicks is the value I'm using to display on screen the clicks. If anyone knows how to do this please tell me.
Here is the full listener class:
package me.toast.leftclickcounter.listeners;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
public class LeftClickCounterListener
{
void Clicks() {
}
int Clicks = 0;
private Minecraft mc = Minecraft.getMinecraft();
@SubscribeEvent
public void onRenderTick(TickEvent.RenderTickEvent e)
{
FontRenderer fr = mc.fontRendererObj;
if(mc.theWorld != null)
{
fr.drawStringWithShadow("§6Left Clicks: " + Clicks , 0, 0, -1 );
}
//TODO Get the left clicks to count each time instead of the time it was held down
if(Minecraft.getMinecraft().gameSettings.keyBindAttack.isKeyDown())
{
Clicks++;
}
}
}