Posted July 20, 20223 yr Hello, I have a simple Minecraft mod. I want to add a system that can track my mouse clicks and run commands when I left click or right click. I tried some solutions but I couldn't find any good resource about it. I tried some methods but no help at all. Can someone just tell which event I need to subscribe? Edited July 20, 20223 yr by FantaLaTone
July 20, 20223 yr 48 minutes ago, FantaLaTone said: Can someone just tell which event I need to subscribe? InputEvent.RawMouseEvent, depends on what the command should do you need to send a custom network packet to the server which performs there the action of the command Edited July 20, 20223 yr by Luis_ST Correcting
July 20, 20223 yr Author 5 minutes ago, Luis_ST said: InputEvent.MouseButton.Pre, depends on what the command should do you need to send a custom network packet to the server which performs there the action of the command i meant methods by saying "commands". like just print something i tried this code but it doesnt seem to be working @SubscribeEvent public void a(InputEvent.MouseButton.Pre event) { System.out.println(event); }
July 20, 20223 yr 24 minutes ago, FantaLaTone said: i meant methods by saying "commands". like just print something i tried this code but it doesnt seem to be working please post the full class Edited July 20, 20223 yr by Luis_ST
July 20, 20223 yr Author 1 minute ago, Luis_ST said: please post the full class package com.fantalatone.soccermod.event; import com.fantalatone.soccermod.SoccerMod; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import java.awt.event.InputEvent; @Mod.EventBusSubscriber(modid = SoccerMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class SoccerModEvents { @SubscribeEvent public void a(InputEvent.MouseButton.Pre event) { System.out.println(event); } }
July 20, 20223 yr Does that even compile? You are using the AWT event when you should be using the forge event. Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
July 20, 20223 yr 33 minutes ago, Luis_ST said: InputEvent.MouseButton.Pre Correction, this is for 1.19 in 1.18 you need to use InputEvent.RawMouseEvent
July 20, 20223 yr Author 1 hour ago, Luis_ST said: Correction, this is for 1.19 in 1.18 you need to use InputEvent.RawMouseEvent ok, i got it working with this code but i have simple question how i can test if it is in world not gui? @SubscribeEvent public static void a(InputEvent.RawMouseEvent event) { System.out.println("3131313!"); if (event.getButton() == 0) { System.out.println("SOl CLİK!"); } }
July 20, 20223 yr Ironically, you can do the opposite with the ScreenEvent.MouseClickedEvent.Pre The only way I can think of doing this to use Minecraft.getScreen() and test if it is null (i.e. no gui screen)? Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
July 20, 20223 yr Author 5 minutes ago, warjort said: Ironically, you can do the opposite with the ScreenEvent.MouseClickedEvent.Pre The only way I can think of doing this to use Minecraft.getScreen() and test if it is null (i.e. no gui screen)? this only detects when im on gui it is not detecting my normal clicks @SubscribeEvent public static void a(ScreenEvent.MouseClickedEvent event) { if (event.getScreen() == null) { System.out.println("boıiş!"); } if (event.getButton() == 0) { System.out.println("SOl CLİK!"); } } (i tried ScreenEvent.MouseClickedEvent.Pre too same thing)
July 20, 20223 yr I didn't say use ScreenEvent, that is only for guis. You should use the RawMouseEvent and add an additional check in your handler. public static void a(InputEvent.RawMouseEvent event) { if (Minecraft.getInstance().getScreen() != null) return; // GUI screen // Your code here } If that doesn't work, I don't know how to do it. Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
July 20, 20223 yr Author 9 minutes ago, warjort said: I didn't say use ScreenEvent, that is only for guis. You should use the RawMouseEvent and add an additional check in your handler. public static void a(InputEvent.RawMouseEvent event) { if (Minecraft.getInstance().getScreen() != null) return; // GUI screen // Your code here } If that doesn't work, I don't know how to do it. theres no command like .getScreen() i just used .screen instead. latest code for 1.18.2 forge click detection package com.fantalatone.soccermod.event; import com.fantalatone.soccermod.SoccerMod; import net.minecraft.client.Minecraft; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.InputEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(modid = SoccerMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class SoccerModEvents { @SubscribeEvent public static void a(InputEvent.RawMouseEvent event) { if (Minecraft.getInstance().screen != null) return; if (event.getButton() == 0) { System.out.println("Left Click Detected!"); } } }
July 20, 20223 yr Author @Luis_ST@warjort i am sorry for pinging but can you tell me can i get the player with this click event? how i can get the player?
July 20, 20223 yr Author 11 minutes ago, diesieben07 said: RawMouseEvent is client side only, there is only one player. i know, i am asking for how i can get player's x and other things like LivingEntity p = event.clicker;
July 20, 20223 yr Author 3 minutes ago, diesieben07 said: Minecraft#player is the client side player ok, thanks it worked
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.