PaperMC / PaperMC/Paper

PlayerInteractEvent calls LEFT_CLICK_AIR after RIGHT_CLICK_BLOCK in Adventure game mode.

Open
#6,315 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: accepted type: bug version: 1.16 version: 1.21.10
Dominant language
Java
Stars
12.7k
Forks
3.5k
Avg merge
3d 13h
Merged PRs (30d)
11

Description

Expected behavior

Only one event call for the PlayerInteractEvent when a player in Adventure interacts with an item that is in their hand on a block. For example: trying to spawn a Pig from a PIG_SPAWN_EGG item.

Observed/Actual behavior

The PlayerInteractEvent was triggered twice claiming a LEFT_CLICK_AIR action after a RIGHT_CLICK_BLOCK.

[11:02:38 INFO]: [paper-test] PlayerInteractEvent: LoonyRules - HAND - RIGHT_CLICK_BLOCK - ALLOW - DEFAULT
[11:02:38 INFO]: [paper-test] PlayerInteractEvent: LoonyRules - HAND - LEFT_CLICK_AIR - DENY - DEFAULT
Steps/models to reproduce
  1. Download latest Paper 1.16.5.
  2. Create a plugin with code in that debugs the PlayerInteractEvent. In our example we printed into console every time the event got triggered and subtracted the quantity of the item used in the interaction. This is our own code on the whole server to show the bug.
@EventHandler
public void onPlayerInteractEvent(@NotNull final PlayerInteractEvent event) {
  this.getLogger().info(
    String.format(
      "PlayerInteractEvent: %s - %s - %s - %s - %s",
      event.getPlayer().getName(), event.getHand(), event.getAction(), event.useInteractedBlock(),
      event.useItemInHand()
    )
  );
        
  // Visually show the bug by decreasing itemstack amount every interact.
  final ItemStack itemStack = event.getItem();
  if (itemStack != null) {
    itemStack.subtract();
  }
}
  1. Upload the plugin to the server's plugins folder and start the server.
  2. Join the server and set your gamemode to Adventure.
  3. Give yourself an item that adventure mode users can interact with. A good example here is a PIG_SPAWN_EGG. Make sure you have 2 of these at least.
  4. Right-click a block to spawn the Pig. Ensure you click once.
  5. You should no longer have the item even though you spawned 1 pig. Look at the debug in console, you should see what was outlined in the "Observed/Actual behavior" section.
Plugin list

Custom plugin that only has the PlayerInteractEvent code shared in reproduction steps.

Paper version

Checking version, please wait...
This server is running Paper version git-Paper-783 (MC: 1.16.5) (Implementing API version 1.16.5-R0.1-SNAPSHOT)
You are running the latest version

Agreements
  • I am running the latest version of Paper available from https://papermc.io/downloads.
  • I have searched for and ensured there isn't already an open issue regarding this.
  • My version of Minecraft is supported by Paper.
Other

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Adventure-mode interaction with a PIG_SPAWN_EGG and observe the PlayerInteractEvent sequence described in the issue. Trace the interaction path that emits RIGHT_CLICK_BLOCK and the subsequent LEFT_CLICK_AIR event. Done means one interaction produces only the expected event and consumes only one item.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.