NeoForge icon indicating copy to clipboard operation
NeoForge copied to clipboard

[1.21.1] LivingEntityUseItemEvent.Finish is not safe to grant advancements with rewards in

Open TelepathicGrunt opened this issue 5 months ago • 0 comments

If you try to subscribe to this event to grant an advancements for some special case, any advancement item reward will be replaced with the item's consume remainder stack.

By that, I mean, look at the patched code: image

Notice how finishUsingItem is ran first before the event. This will decrement the held stack. Lets say that stack is an item like 1 Honey Bottle. This will decrement it to an empty stack. Fire the event. If a mod then triggers an advancement that grants an item reward or the mod gives a new extra item to user (without replacing the useRemainder), the setItemInHand will replace that new item with the Glass Bottle remainder.

Making this event dangerous for adding extra items to the user. Perhaps we can adjust the setItemInHand line to check if hand is not empty and itemstack is not empty. Then move the held item in hand to a different spot in inventory and put itemstack remainder back into the hand. That way any item granted into hand in event is not deleted.

TelepathicGrunt avatar Aug 30 '24 14:08 TelepathicGrunt