Jump to content

[SOLVED][1.18.2] Implementing player left clicks and right clicks


FantaLaTone

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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);
    }

 

Link to comment
Share on other sites

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);
    }

}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

}

 

Link to comment
Share on other sites

  • FantaLaTone changed the title to [SOLVED][1.18.2] Implementing player left clicks and right clicks

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi everyone  I'm trying to make a custom door and give it a custom sound. In order to do so I've registered the sounds like this   private static final DeferredRegister<SoundEvent> SOUNDS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, MineWorld.MOD_ID); ... public static final RegistryObject<SoundEvent> SCULK_DOOR_CLOSE = SOUNDS.register("sculk_door_close", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(MineWorld.MOD_ID, "sculk_door_close"))); public static final RegistryObject<SoundEvent> SCULK_DOOR_OPEN = SOUNDS.register("sculk_door_open", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(MineWorld.MOD_ID, "sculk_door_open"))); call the register method of the Sounds registry as the first thing in my mod initialize method IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus(); SOUNDS.register(eventBus); Then I create a BlockSetType like this   public static final BlockSetType SCULK = BlockSetType.register(new BlockSetType(new ResourceLocation(MineWorld.MOD_ID, "sculk").toString(), true, SoundType.WOOD, SCULK_DOOR_CLOSE.get(), SCULK_DOOR_OPEN.get(), SoundEvents.WOODEN_TRAPDOOR_CLOSE, SoundEvents.WOODEN_TRAPDOOR_OPEN, SoundEvents.WOODEN_PRESSURE_PLATE_CLICK_OFF, SoundEvents.WOODEN_PRESSURE_PLATE_CLICK_ON, SoundEvents.WOODEN_BUTTON_CLICK_OFF, SoundEvents.WOODEN_BUTTON_CLICK_ON); And finally the door block like this private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MineWorld.MOD_ID); ... BLOCKS.register("sculk_door", () -> new DoorBlock(BlockBehaviour.Properties.copy(Blocks.OAK_DOOR), blockSetType)); But when I launch the game I get this error   Registry Object not present: mineworld:sculk_door_close Am I doing something wrong? Maybe the BlockSetType registration needs to be done in a different way? I have other BlockSetTypes registered like this that only uses vanilla sounds and they work just fine. You can see an example in my GitHub repo here: https://github.com/JimiIT92/MineWorld/blob/master/src/main/java/org/mineworld/core/MWBlockSetTypes.java
    • it was eldritch end, thank you
    • Okay. Thank you. I think it works now. I added the jdk-17 path to the batch instead of the jvm arguments txt file. The windows command prompt is just blank, but when I close the native windows command prompt, the java command prompt opens & loads the server. If that won't cause issues then I'm all good. 
    • I have no idea - the last mentioned mods are eldritch_end, supplementaries and mahoutsukai Start with removing mahoutsukai
  • Topics

×
×
  • Create New...

Important Information

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