Paper icon indicating copy to clipboard operation
Paper copied to clipboard

PlayerInteractEvent fails to fire when left clicking an entity from 4 blocks away

Open Alexz1008 opened this issue 2 years ago • 1 comments

Expected behavior

I expect PlayerInteractEvent to be called whenever I left click (I DO NOT ignore cancelled events) with an item in main hand.

Observed/Actual behavior

PlayerInteractEvent is called in every case expected EXCEPT when I am 3-4 blocks away from an entity and facing them (I used a zombie to test, may not be all entities). It starts calling when I'm 5 blocks away.

Steps/models to reproduce

  1. Have a plugin that sends a message anytime PlayerInteractEvent occurs, make sure it does not ignore cancelled events.
  2. Create a box that can fit a zombie (1x1, 2 blocks tall) and be in survival mode after.
  3. Put 3 blocks in between you and the zombie (screenshot: https://gyazo.com/3a0c6a4be3710149e306f33fa4178536)
  4. Left click while looking at the zombie. At this point, you should see that the plugin does NOT send any messages.
  5. Left click while looking elsewhere for a control group. The plugin should be sending messages at this point. The PlayerInteractEvent ONLY fails to fire when you're aiming at an entity (only tested zombie).

I have a hypothesis that this is because spigot is incorrectly using creative mode melee range (which is 1 block longer than survival mode melee range) to calculate when to fire the event. My evidence and reproduction is below:

  1. Do step 0, 1, and 2 of above, but be in CREATIVE mode.
  2. After putting 3 blocks between you and the zombie, left click. If the plugin doesn't send a message, take a very small step back. Left click again. Continue until you receive a message from the plugin. Notice that as SOON as you are not in range to hit the zombie, the plugin starts sending messages again. This is at around 4-5 blocks from the entity. This persists regardless of game mode, it's just easy to illustrate that it seems to use creative mode's range.

Plugin and Datapack List

For the sake of this test, the ONLY plugin I ran was one that let me see if the event fired. I did not have any datapacks. The code is below:

public void onEnable() {
Bukkit.getServer().getLogger().info("NeoDebugger Enabled");
getServer().getPluginManager().registerEvents(this, this);
}

public void onDisable() {
	  org.bukkit.Bukkit.getServer().getLogger().info("NeoDebugger Disabled");
	  super.onDisable();
}

@EventHandler(ignoreCancelled = false)
public void onInteract(PlayerInteractEvent e) {
System.out.println("HERE: " + e.getAction() + " " + e.getHand());
}

Paper version

[16:28:24 INFO]: This server is running Paper version git-Paper-258 (MC: 1.19.2) (Implementing API version 1.19.2-R0.1-SNAPSHOT) (Git: ab1c072) You are running the latest version Previous version: git-Paper-220 (MC: 1.19.2)

Other

No response

Alexz1008 avatar Nov 04 '22 20:11 Alexz1008

That is true, I'm facing this issue right now and I thought it may be a bug. However I've an useful image to show you. These examples are for left clicking with a tool in main hand image

3meraldK avatar Apr 29 '23 14:04 3meraldK

Resolved by #9211

lynxplay avatar Jul 16 '23 15:07 lynxplay