Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent keep inventory deaths from dropping open container/cursor items #11533

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

NewwindServer
Copy link
Contributor

@NewwindServer NewwindServer commented Oct 30, 2024

When a player has an open inventory—such as with a merchant, anvil or their own crafting grid—and
places items in it, or has an item on their cursor, closing the inventory typically
returns those items to the player's main inventory. However, if the player dies with
the inventory still open, the items are dropped onto the ground.

This usually isn't a problem, as their entire inventory would be dropped anyway.
But when keep inventory is enabled, these items should return directly to the player's inventory
to prevent valuable items from being accidentally dropped—especially
in spawn areas where keep inventory is active.

This patch makes the items return directly to the inventory if they die with keep inventory.

@NewwindServer NewwindServer requested a review from a team as a code owner October 30, 2024 15:20
@NewwindServer
Copy link
Contributor Author

NewwindServer commented Oct 30, 2024

Before:
Dying with item in merchant inventory while in inventory protected area (item drops):
https://github.com/user-attachments/assets/bf14d5a0-6e20-4a7d-b240-578d98d2074e

Dying with item on cursor while in inventory protected area (item drops):
https://github.com/user-attachments/assets/f9da24f3-6128-4d32-b580-e6fd22a4f13e

Dying with item in anvil inventory while in inventory protected area (item drops):
https://github.com/user-attachments/assets/05013e61-ab6e-4831-a3a4-a4698aa18af5

Dying with item in crafting grid while in inventory protected area (item drops):
https://github.com/user-attachments/assets/bc11af09-a1c9-478c-a726-c8799adecd45

@NewwindServer
Copy link
Contributor Author

NewwindServer commented Oct 30, 2024

After (with config option enabled)

Dying with item in merchant inventory while in inventory protected area (item returned to inventory):
https://github.com/user-attachments/assets/9d32951f-1a79-4c95-8d41-05864c89c27c

Dying with item on cursor while in inventory protected area (item returned to inventory):
https://github.com/user-attachments/assets/a692f718-9817-4c69-9c44-8b1dc9d1169e

Dying with item in anvil inventory while in inventory protected area (item returned to inventory):
https://github.com/user-attachments/assets/d453f48e-b47a-48cd-879b-c23896ef470e

Dying with item in crafting grid while in inventory protected area (item returned to inventory):
https://github.com/user-attachments/assets/25a9485a-e574-484f-9a69-bad76c7434d1

@NewwindServer
Copy link
Contributor Author

NewwindServer commented Oct 30, 2024

The only inventory this doesn't apply to is beacons, because they never return items to inventory and always drop (see: https://bugs.mojang.com/browse/MC-177476)

 @Override // where is placeItemBackInInventory here?? MC-177476
    public void removed(Player player) {
        super.removed(player);
        if (!player.level().isClientSide) {
            ItemStack itemstack = this.paymentSlot.remove(this.paymentSlot.getMaxStackSize());

            if (!itemstack.isEmpty()) {
                player.drop(itemstack, false);
            }

        }
    }

I could easily add a fix for this to the patch and add keep inventory support, what do you think?

@RealDestroy
Copy link

ye this would be helpful

@NewwindServer
Copy link
Contributor Author

I have just seem the changes for 1.21.3 and this PR patch will definitely need rewritten, gonna wait a couple weeks for 1.21.3 to be stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Awaiting review
Development

Successfully merging this pull request may close these issues.

2 participants