Issue with villager trading
So I used a command block in 1.16.4 to summon a villager who sells dirt with custom name of 'DIRT BLOCK'. Then I /give myself the dirt block also with the name 'DIRT BLOCK' , I can do the trade at the first time, but as I closed the GUI of villager trading, and drop the item, I can't trade it with them anymore. Below is my villager code
summon villager ~ ~1.5 ~ {VillagerData:{profession:librarian,level:5,type:plains},Invulnerable:1,NoAI:1,Offers:{Recipes:[{buy:{id:dirt,Count:1,maxUses:99999,tag:{display:{Name:"\"DIRT BLOCK\""}}},sell:{id:stone,Count:1,maxUses:99999}}]}}
and below is the /give
code I wrote
/give @s dirt{display:{Name:"\"DIRT BLOCK\""}} 64
I cannot reproduce your problem. Here is something you can do to help yourself:
First, hold the item in your main hand, then run the following command. Note the data that your item has on it:
/data get entity @s SelectedItem
Then, drop the item, pick it back up, and run the same command again.
If you notice anything different, that must mean that maybe another command machine is changing the NBT data.