fix: item-drop rollback discards item instead of returning it to player#381
Open
netcrafts wants to merge 1 commit into
Open
fix: item-drop rollback discards item instead of returning it to player#381netcrafts wants to merge 1 commit into
netcrafts wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this change?
Fixes
ItemDropActionType.rollback()so that rolling back anitem-dropaction correctly returns the item to the player in all cases — including when the dropped entity has already despawned.Why?
When a player rolls back an
item-dropaction, the expected behaviour is that the drop is undone — the item should return to the dropping player's inventory. The previous implementation had two bugs:entity.remove(DISCARDED)on the dropped entity, removing the item from the world without placing it anywhere. The rollback reported success, but the item was gone.How?
The rollback now removes the dropped
ItemEntityif it is still present (safe no-op if already gone), then always proceeds to restore the item:ItemStackfrom the logged action data (via the existinggetStack()helper).server.playerList.getPlayer().ItemEntityat the logged drop coordinates (Vec3.atCenterOf(pos)) — so the item is never lost. The fallback entity is created with a new UUID rather than restored from the original NBT, avoiding UUID collisions.Note on duplication: if the item was picked up by another player and only the
item-dropis rolled back (not the subsequentitem-pick-up), this will duplicate the item. In practice, Ledger rollbacks are run with a player + time range which catches both actions; cross-referencing related actions is the operator's responsibility.Testing
item-dropis logged./ledger rollbackimmediately (item still on ground).Failed to rollback item-drop.