Jump to content

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


Recommended Posts

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.

Posted

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.

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.