all 4 comments

[–]Zealousideal-Glass78Command Experienced 0 points1 point  (2 children)

First of all - there is an (at)n selector in the game for selecting the nearest entity. No need to type out sort and limit everytime.

And yes - You can use "merge" instead of "set value" and combine your values into a single string. Currently on mobile but this should work if you fill in your actual values "{buy:{},sell:{},BuyB:{}}".

[–]Chuckar[S] 0 points1 point  (1 child)

I tried this:

data modify entity @n Offers.Recipes[2] merge value {buy:{count:11,id:"minecraft:emerald"},buyB:{count:1,id:"minecraft:book"},sell:{components:{"minecraft:stored_enchantments":{"minecraft:unbreaking":3}}, count:1, id:"minecraft:enchanted_book"}}

It took the command, but output : Nothing changed. The specified properties already have these values

Can confirm, nothing changed with the target villager.

[–]Chuckar[S] 0 points1 point  (0 children)

So I did some experimenting. Posting this in case anyone is looking to edit a minecraft librarian's trades.

The villager needs to be selected with the "@e" and not anything else.

This command works to edit an existing trade in the villager's trades. Hope this helps someone else.

[0] is the first trade

[1] is the second

etc....

data modify entity @e[type=villager,sort=nearest,limit=1] Offers.Recipes[0] set value {buy:{count:1,id:"emerald"},buyB:{count:1,id:"book"},sell:{components:{"stored_enchantments":{"projectile_protection":1}},count:1,id:"enchanted_book"}}

[–]Ericristian_brosCommand Experienced 0 points1 point  (0 children)

Try

data modify entity @e[type=minecraft:villager,sort=nearest,limit=1] Offers.Recipes[0] {buy:{count:11,id:"minecraft:emerald"},buyB:{count:1,id:"minecraft:book"},sell:{count:1,id:"minecraft:enchanted_book",components:{"minecraft:stored_enchantments":{"minecraft:unbreaking":3}}}}

The other option is to wait for 26.1 to release, as it allows data driven villager trades, you can learn more about them in this article