PaperMC / PaperMC/Paper

Off hand gets deleted when tool in main hand breaks when hitting a mob and you replace the item in the main hand at the same time

Open
#13,050 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: needs triage version: 1.21.8
Dominant language
Java
Stars
12.7k
Forks
3.5k
Avg merge
3d 13h
Merged PRs (30d)
11

Description

Expected behavior

Tool breaks and is replaced by the new item

Observed/Actual behavior

tool gets replaced, but itemstack in off hand gets deleted

Steps/models to reproduce

`

@EventHandler
  public void onPlayerJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();

    ItemStack tool = new ItemStack(Material.STONE_SWORD); // Any tool works, as long as you are hitting a mob

    Damageable meta = (Damageable) tool.getItemMeta();

    assert meta != null;
    meta.setDamage(10000); // Making it break in one hit; it does not need to be over the limit

    tool.setItemMeta(meta);

    player.getInventory().setItemInMainHand(tool);
    player.getInventory().setItemInOffHand(new ItemStack(Material.GRASS_BLOCK)); // this item does not matter either, just placeholder
    player.getWorld().spawn(player.getLocation(), Chicken.class); // entity type does not seem to matter
}

@EventHandler
// PlayerItemDamageEvent also works, so long as the tool is replaced immediately as it is broken.
public void onToolBreak(PlayerItemBreakEvent event) {

    Player player = event.getPlayer();
    int slot = player.getInventory().getHeldItemSlot();
    player.getInventory().setItem(slot, new ItemStack(Material.STONE)); // replacement item does not matter

    // off hand item has now disappeared.

}

`

Plugin and Datapack List

no plugins besides one with the above code is required

Paper version

This server is running Paper version 1.21.8-56-main@65641d1 (2025-08-29T20:44:17Z) (Implementing API version 1.21.8-R0.1-SNAPSHOT)
You are running the latest version
Previous version: 1.21.8-31-86b716b (MC: 1.21.8)

Other

this issue goes back several patches, perhaps full minecraft versions. I first noticed it as a paper bug on my 1.21.4 server.

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

Reproduce the issue using the provided PlayerJoinEvent setup and PlayerItemBreakEvent handler on Paper 1.21.8. Start by tracing item-break and inventory handling when the main-hand slot is replaced, then verify that the off-hand ItemStack remains present after the tool breaks. The issue provides no named source files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.