Fix count in origin ItemStack for InventoryMoveItemEvent#8087
Conversation
| + foundItem = true; | ||
| + ItemStack origItemStack = item; | ||
| + ItemStack itemstack = origItemStack; | ||
| + ItemStack itemstack = origItemStack.copy(); |
There was a problem hiding this comment.
the issue says about use clone.. but NMS have a method for this.. my issue if can be this method or can be cloneItemStack(true)
There was a problem hiding this comment.
I just said clone because thats what bukkit uses but copy should work too
|
On a quick glance there's more in the patch to be cleaned up if you clone the original item. also, here's how you properly fixup patches https://youtu.be/K_lym3WHoFA |
|
blindly cloning the original item negates a good chunk of the perf improvements here, would defo need that to at least be in the fire event, but, afaik, the patch currently maintains the behavior of upstream in terms of how the event works but I'd need to double check |
not sure why now works.. i try the same thing (based in contribution) and the class was reverted to the original.. maybe a WSL cache thing... i rebased this and add the same thing to the pull... About the copy thing not sure if can be another thing i can do in this... i dont tested only with the change in count ignoring the copy... |
|
What about if we just sets the amount of item before calling PushMoveEvent and adding the item into the hopper instead of hard-copying the item? I mean final int origCount = origItemStack.getCount();
final int moved = Math.min(level.spigotConfig.hopperAmount, origCount);
origItemStack.setCount(moved);
// We only need to fire the event once to give protection plugins a chance to cancel this event
// Because nothing uses getItem, every event call should end up the same result.
if (!skipPushModeEventFire) {
+ itemstack.setCount(origCount);
itemstack = callPushMoveEvent(destination, itemstack, hopper);
if (itemstack == null) { // cancelled
origItemStack.setCount(origCount);
return false;
}
}
final ItemStack itemstack2 = addItem(hopper, destination, itemstack, enumdirection);
+ itemstack.setCount(moved);
final int remaining = itemstack2.getCount();or we could just move this |
Owen1212055
left a comment
There was a problem hiding this comment.
See above. It's a bit eh all the sudden cloning items like this in code that can get very hot like this. It might be worth looking into what we can do to avoid having to reclone the entire item but properly update the count to try to keep things performant here.
This fixs #8086 based in the same issue the problem is the item passed to the event not have the change in the amount to pass.
note: need learn more git because when make https://github.com/PaperMC/Paper/blob/master/CONTRIBUTING.md#method-1 this i cannot modify the patch... this was a directly edition in patch.. tested with applyPatches