Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Solved][1.9] PlayerInteractEvent - Returns different coordinates for each hand?

Featured Replies

Posted

Hi, I'm confuse with the way the PlayerInteractEvent is working in 1.9

 

I would guess that the event always would return the coordinates de player is looking at, but apparently, for the Main Hand it does return the block the player is looking at, while for the Off Hand it returns the coordinates the player is standing on.

 

Am I right, or I'm missing something here?

 

This is the code:

 

    @SubscribeEvent
    public void onPlayerInteractEvent(PlayerInteractEvent event)
    {
    	World world = event.getWorld();
    	BlockPos pos = event.getPos();
    	EntityPlayer player = event.getEntityPlayer();
    	
    	if(!world.isRemote)
    	{
    	
    		System.out.println(event.getPos());
    		
    		System.out.println(event.getHand());
    		
    	if(world.getBlockState(pos).getBlock() instanceof BlockCrops)
    	{
    		System.out.println("Crops!!!");
    	}
   	
    	}//END WORLD NO REMOTE
    }

 

And here is an screenshot ingame and what is show on console. (It didn't print twice, I did right click twice)

 

mj85Nbw.png

 

PS: How can I tell if the event was triggered by a Left click or a Right click? Thanks a lot.

In 1.9,

PlayerInteractEvent

has a separate nested subclass for each type of player interaction. Subscribe to one of these rather than

PlayerInteractEvent

itself.

 

I suggest you use Log4J like the rest of Minecraft/Forge rather than printing directly to stdout.

FMLPreInitializationEvent#getModLog

will return a

Logger

that will log messages with your mod ID, store this somewhere and use it to write to the log.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

Thanks Choonster, I will take a look into that Log4j

 

I'm using the event RightClickBlock now that works way better for what I was needing ;)

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.