This one is hard to explain, so I'll just tell you how to make it happen.
1. Run "/summon villager ~ ~ ~ {UUID:[I;"put UUID here"]}
2. Run "/summon trader_llama ~ ~ ~ {Leash:{UUID:[I;"make UUID here match UUID above"]}}"
3. The trader llama spawns, and then disappears instantly!
4. Spawn a trader llama with a spawn egg
5. Run "/data merge @e[type=trader_llama,limit=1,sort=nearest] {Leash:{UUID:[I;"make UUID here match UUID of the villager"]}}
6. It's gone!
7. Do the same with a normal llama.
8. It works just fine
Code Analysis
The code analysis can be seen with a fix in MC-168188 thanks to @unknown
Linked issues
is duplicated by 1
relates to 2
Comments 3
(1.18.2) It has something to do with MC-168188. So far, I've managed to find out this:
Trader Llamas always spawn with active DespawnDelay tag, while Wandering Traders have it on 0 when spawned manually (they never despawn). When you leash a llama with command from step 2, they "take" the value of DespawnDelay from the trader, but since it's set to 0, the game thinks that the default time ran out, so the llama eventually despawns.
To make it work, you have to actually give the Wandering Trader a DespawnDelay value:
/summon wandering_trader ~ ~ ~ {UUID:[<"Trader UUID">],DespawnDelay:2147483647}
/summon minecraft:trader_llama ~1 ~ ~ {Leash:{UUID:[<"Trader UUID">]}}
All of the newly spawned llamas will now have exactly the same DespawnDelay as the trader currently has.
Leashing to other entities in 1.18.2 worked normally in my case:
/summon cat ~ ~ ~ {UUID:[<"Entity UUID">]}
/summon minecraft:trader_llama ~1 ~ ~ {Leash:{UUID:[<"Entity UUID">]}}
(1.18.2) It has something to do with MC-168188. So far, I've managed to find out this:
Trader Llamas always spawn with active DespawnDelay tag, while Wandering Traders have it on 0 when spawned manually (they never despawn). When you leash a llama with command from step 2, they "take" the value of DespawnDelay from the trader, but since it's set to 0, the game thinks that the default time ran out, so the llama eventually despawns.
To make it work, you have to actually give the Wandering Trader a DespawnDelay value:
/summon wandering_trader ~ ~ ~ {UUID:[<"Trader UUID">],DespawnDelay:2147483647}
/summon minecraft:trader_llama ~1 ~ ~ {Leash:{UUID:[<"Trader UUID">]}}
All of the newly spawned llamas will now have exactly the same DespawnDelay as the trader currently has.
Leashing to other entities in 1.18.2 worked normally in my case:
/summon cat ~ ~ ~ {UUID:[<"Entity UUID">]}
/summon minecraft:trader_llama ~1 ~ ~ {Leash:{UUID:[<"Entity UUID">]}}
Happened to me in 1.17.1, can't leash trader llamas to wandering trader.