All of you faced this problem. And now me, too. I wrote some code to catch Keyboard events. like:
@SideOnly(Side.CLIENT)
@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
public void onEvent(InputEvent.KeyInputEvent event) {
if (itemIsHoldinHand.equals(ItemHoldInHand.NONE)) {
//Do nothing if it is not hold
return;
}
String keyBindingDescKey = "key.attack";
// make local copy of key binding array
KeyBinding[] keyBindings = Minecraft.getMinecraft().gameSettings.keyBindings;
for (KeyBinding binding : keyBindings) {
if (keyBindingDescKey.equals(binding.getDescriptionKey()) && /*IMPORTANT to do this on second check because its counter based and will reset other key actions when it hits*/ binding.isPressed()) {
return;
}
}
}
This code works well as the attack key is bound to a keyboard key like: R, A, ...
But at default the attack key is bound to
KeyCode: -100 (Left mouse button)
But thats not the main problem, I knew that there is another event for catching mousecation like:
@SideOnly(Side.CLIENT)
@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
public void onEvent(InputEvent.MouseInputEvent event) {
if (itemIsHoldinHand.equals(ItemHoldInHand.NONE)) {
//Do nothing if it is not hold
return;
}
...
String keyBindingDescKey = "key.attack";
// make local copy of key binding array
KeyBinding[] keyBindings = Minecraft.getMinecraft().gameSettings.keyBindings;
for (KeyBinding binding : keyBindings) {
if (keyBindingDescKey.equals(binding.getDescriptionKey()) && /*This same pattern never hits....*/ binding.isPressed())
{
return;
}
}
}
But doing the same thing as before results in nothing.
Even trying to do:
@SideOnly(Side.CLIENT)
@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
public void onEvent(InputEvent.MouseInputEvent event) {
if (itemIsHoldinHand.equals(ItemHoldInHand.NONE)) {
//Do nothing if it is not hold
return;
}
boolean isPressed = Minecraft.getMinecraft().gameSettings.keyBindAttack.isPressed();
if(isPressed){
System.out.println("Hell yeah");
}
}
Is getting me no result. So I am asking you guys . Is there any pattern, how to or possibility to access the left mouse click (user friendly)
PS: I did add it to the EVENT_BUS
MinecraftForge.EVENT_BUS.register(ModItems.ItemGun);