Jump to content

[SOLVED] [1.7.10] PlayerInteractEvent - Strange behaviour


Nicnl

Recommended Posts

Hello,

 

I found that the PlayerInteractEvent had a pretty strange behaviour.

 

Let me be a bit more precise.

Here's the minimalistic piece of code I used :

@SubscribeEvent
public void onPlayerBreakBlock(PlayerInteractEvent event) {
    System.out.println("PlayerInteractEvent => " + event);
}

 

Here's the behaviour of this event :

    - In singleplayer, left clicking a block triggers this event with event.action = LEFT_CLICK_BLOCK

    - In singleplayer, right clicking (or placing) a block triggers this event with event.action = RIGHT_CLICK_BLOCK

    - In multiplayer, left clicking a block DOES NOT triggers this event at all.

    - In multiplayer, right clicking (or placing) a block triggers this event with event.action = RIGHT_CLICK_BLOCK

 

Why does this event isn't triggered in multiplayer when left-clicking a block ?

 

This disfunctionment is happening with the two 1.7.10 Forge builds available at this day :

The recommended one (10.13.0.1180) and the latest one (10.13.0.1205).

 

PS : I'm sorry for my English, I'm French.

Link to comment
Share on other sites

When you say multiplayer, you have a vagueness in your description. You have 1) integrated server, 2) standalone server, and 3) client connecting to standalone server.

 

So, please describe in which scenario from those do you experience the oddness.

Link to comment
Share on other sites

Thank you for your response.

 

You're right, i'm totally unclear.

Sorry for the inconvenience.

 

I'm working on a simple inventory manager plugin that select automatically the best tool when you start digging a block.

To do so, I need to know which block I dig, that's why I use the PlayerInteractEvent.

 

That means that i'm working exclusively on the client, and that multiplayer means when i'm connected to a regular Vanilla 1.7.10 server with the client.

 

I hope these informations will be useful.

Link to comment
Share on other sites

Thank you for your help, the MouseEvent is a brilliant replacement for the PlayerInteractEvent.

 

Unfortunately, this one don't have the X, Y and Z coordinates of the block I'm aiming.

The X and Y values provided by this event are not corresponding to what I'm looking for.

That's why I used a raytrace with the player's position and camera angles to find the right values.

 

Thread solved.

Link to comment
Share on other sites

LEFT_CLICK_BLOCK only fires on the server, not the client. You could try using MouseEvent to intercept client side mouse clicks and determine if the player is about to start mining a block.

 

Why not send a packet to client?

 

Also, it does seem a bit weird that these events aren't consistent in their firing.  I mean it kinda makes sense based on the type of click, but it wouldn't really have hurt to fire on both sides...like what if you wanted to add visual effect on left clicks or something?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Why not send a packet to client?

Sometimes, that's just too slow, especially when dealing with things like mouse-clicks. Client clicks mouse -> sends packet to server -> fires interact event -> processes -> sends packet back to client... it's too late, as the server already did its work (barring some convoluted coding).

 

Also, it does seem a bit weird that these events aren't consistent in their firing.  I mean it kinda makes sense based on the type of click, but it wouldn't really have hurt to fire on both sides...like what if you wanted to add visual effect on left clicks or something?

I agree - RIGHT_CLICK_BLOCK is fired on both sides, so why not LEFT_CLICK_BLOCK? It may just be a poor choice of event placement, sort of like the one diesieben07 submitted a PR for last time, or it may be a deeper issue... I haven't looked into it other than noting its behavior.

 

EDIT: Check it out, a PR for this issue: https://github.com/MinecraftForge/MinecraftForge/pull/1121

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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