Jump to content

Recommended Posts

Posted (edited)

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 by FantaLaTone
Posted (edited)
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 by Luis_ST
Correcting
Posted
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);
    }

 

Posted (edited)
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 by Luis_ST
Posted
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);
    }

}

 

Posted

Does that even compile?

You are using the AWT event when you should be using the forge event.

  • Thanks 1

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.

Posted
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!");
        }
    }

 

Posted

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.

Posted
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)

Posted

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.

  • Thanks 1

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.

Posted
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!");
        }
    }

}

 

  • FantaLaTone changed the title to [SOLVED][1.18.2] Implementing player left clicks and right clicks
Posted
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;

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.