On Minecraft, can you change villager NBT tags without changing trades?

Basically, I want to make a datapack that modifies the maxUses tag of every villager for every trade, making them never lock up. Is this possible?


Solution 1:

In 1.12.2:

This is not possible.


In 1.13.2:

First you have to create a scoreboard and put a value in it:

/scoreboard objectives add constants dummy
/scoreboard players set $1000000 constants 1000000

The name "$1000000" can never be a player name, because it starts with a dollar sign.

Now you can copy that value to the villager's NBT like this:

/execute store result entity <selector> Offers.Recipes[0].maxUses int 1 run scoreboard players get $1000000 constants
/execute store result entity <selector> Offers.Recipes[1].maxUses int 1 run scoreboard players get $1000000 constants
/execute store result entity <selector> Offers.Recipes[2].maxUses int 1 run scoreboard players get $1000000 constants
...

You can go to an arbitrarily high trade number, it will just do nothing if the trade doesn't exist.


In 1.14:

/data modify entity <selector> Offers.Recipes[].maxUses set value 1000000

The "[]" syntax is new in 1.14, it applies the operation to all elements in the list. /data modify is also new in 1.14, it allows a wide range of things, but in this case it's just used to avoid needing a scoreboard.