Modifying recipes from OPEN_WINDOW_MERCHANT deletes discount
WillFP opened this issue ยท 1 comments
Describe the bug
This code, which modifies metadata of itemstacks in a trade removes all discounts
leading to a client-server mismatch that means an incorrect number of emeralds (or other ingredient) are taken from a players inventory which updates on player.updateInventory()
To Reproduce
Modify any merchantRecipe from PacketType.Play.Server.OPEN_WINDOW_MERCHANT
The discounts will be deleted
Expected behavior
Discounts should be preserved
Version Info
https://pastebin.com/NXcQEzwF
Additional context
Using AbstractPacketAdapter (Custom packet class), but this doesn't affect the bug, it happens either way.
the reason this happens is because bukkit's MerchantRecipe does not store this data you're wanting, so the two hidden values (specialPrice and demand) are completely voided whenever a new MerchantRecipe is given. since the design of MerchantRecipe does not allow you to modify the result (its an NMS thing, the result is final so only new instances are allowed), you can either use reflection to forcibly modify the result item instead of creating new recipe instances, you can complain to someone at bukkit to add methods to manipulate the fields specialPrice and demand, or someone here can create an entirely new wrapper for MerchantRecipes which allow the modification of those values.