Skip to content

Fixes #11921 | Consider off-hand when adding items to player inventory#11993

Closed
niho2 wants to merge 1 commit into
PaperMC:mainfrom
niho2:main
Closed

Fixes #11921 | Consider off-hand when adding items to player inventory#11993
niho2 wants to merge 1 commit into
PaperMC:mainfrom
niho2:main

Conversation

@niho2
Copy link
Copy Markdown
Contributor

@niho2 niho2 commented Jan 20, 2025

Problem

The addItem method in CraftInventory doesn't consider the off-hand when adding items to a full player inventory. When an item is partially in the off-hand and the rest of the inventory is full, it incorrectly indicates that there's no space available, even though there might be space in the off-hand.

Changes

  • Extended the addItem method to check if it's a player inventory
  • Added additional check for the off-hand when no partial stack is found in the main inventory
  • Attempts to stack items in the off-hand before looking for an empty slot
  • Maintains original logic for non-player inventories

Test Cases

  1. Player has an item in off-hand with free stack space
  2. Player attempts to add the same item
  3. Item is correctly added to the off-hand
  4. Remaining items (if any) are placed normally in the inventory

Additional Notes

  • Change respects the maximum stack size of the item
  • No API surface changes
  • Backwards compatible with existing functionality

@niho2 niho2 requested a review from a team as a code owner January 20, 2025 15:25
@github-actions
Copy link
Copy Markdown

Please do not open pull requests from the main branch, create a new branch instead.

@github-actions github-actions Bot closed this Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

1 participant