The bug
When you trade an item with a villager the crafting stat for the received item increases.
How to reproduce
Summon a villager
/summon villager ~ ~ ~ {NoAI:1b,Offers:{Recipes:[{buy:{id:"stone",Count:1b},sell:{id:"stone",Count:1b},maxUses:2147483647}]}}Setup the scoreboard objective
/scoreboard objectives add craftedStone minecraft.crafted:minecraft.stone /scoreboard objectives setdisplay sidebar craftedStoneTrade with the villager
→ The score increases
The reason
The following is based on a decompiled version of Minecraft 1.10 using MCP 9.30.
The method net.minecraft.inventory.SlotMerchantResult.onCrafting(ItemStack) calls the method net.minecraft.item.ItemStack.onCrafting(World, EntityPlayer, int).
Confirmed that this bug is still reproducible in 1.15.2
For scoreboards, is there a workaround or another trade state we can track to keep our score-based datapacks accurate?