-
Bug
-
Resolution: Unresolved
-
None
-
1.15, 1.15.1, 1.15.1 Pre-release 1, 1.15.2 Pre-release 2, 1.15.2, 20w06a, 20w08a, 20w09a, 20w11a, 20w12a, 20w13b, 20w18a, 20w19a, 20w20b, 20w21a, 1.16 Pre-release 2, 1.16 Pre-release 5, 1.16 Pre-release 6, 1.16 Pre-release 7, 1.16 Release Candidate 1, 1.16, 1.16.1, 20w27a, 20w30a, 1.16.2 Pre-release 1, 1.16.2, 1.16.3 Release Candidate 1, 1.16.3, 1.16.4 Release Candidate 1, 1.16.4, 20w46a, 20w51a, 1.16.5, 21w05a, 21w05b, 21w06a, 21w07a, 21w11a, 1.17, 1.17.1 Pre-release 1, 1.18.2, 22w16b, 1.19.3
-
Confirmed
-
Commands, Mob behaviour
-
Low
-
Platform
The bug
The trader llama's DespawnDelay tag is active, even when spawned with commands or with their own spawn egg. After spawning a trader llama with commands or spawn egg, the tag starts at 47999 and begins to go down to 0 instead of the tag being default to 0 similar to wandering traders spawned by commands and their own spawn egg (and also makes them not despawn).
How to reproduce
- Spawn trader llama using a spawn egg (untamed)
- Run
/data get entity @e[type=trader_llama,limit=1] DespawnDelay
→ The trader llama's DespawnDelay tag is active as it is not default to 0.
- Spawn a wandering trader with a spawn egg
- Use the /data get again
→ It's DespawnDelay is default to 0
Code Analysis
Code Analysis done by Thumpbacker
This issue is that there is no check if the despawn delay is greater then zero allowing the counter to go down. Along with this the default value of the despawnDelay is always 47999 by default. This should be set when the trader llama spawns via wandering trader event
Current Code
private void maybeDespawn() { if (this.canDespawn()) { this.despawnDelay = this.isLeashedToWanderingTrader() ? ((WanderingTrader)this.getLeashHolder()).getDespawnDelay() - 1 : this.despawnDelay - 1; if (this.despawnDelay <= 0) { this.dropLeash(true, false); this.discard(); } } }
private void tryToSpawnLlamaFor(ServerLevel p_35918_, WanderingTrader p_35919_, int p_35920_) { BlockPos blockpos = this.findSpawnPositionNear(p_35918_, p_35919_.blockPosition(), p_35920_); if (blockpos != null) { TraderLlama traderllama = EntityType.TRADER_LLAMA.spawn(p_35918_, (CompoundTag)null, (Component)null, (Player)null, blockpos, MobSpawnType.EVENT, false, false); if (traderllama != null) { traderllama.setLeashedTo(p_35919_, true); } } }
Fixed Code
//Setting this despawnDelay to nothing allows for it to be zero by default helping fix MC-168188 private int despawnDelay; ... private void maybeDespawn() { if (this.canDespawn()) { //Removing this line stops the constat updates to the despawn delay helping fix MC-168188 & MC-210224 //this.despawnDelay = this.isLeashedToWanderingTrader() ? ((WanderingTrader)this.getLeashHolder()).getDespawnDelay() - 1 : this.despawnDelay - 1; //Doing a check for if the despawnDelay is greater then zero and then subtracting it helps fix MC-168188 & MC-210224 if (this.despawnDelay > 0 && --this.despawnDelay == 0) { this.dropLeash(true, false); this.discard(); } } }
private void tryToSpawnLlamaFor(ServerLevel p_35918_, WanderingTrader p_35919_, int p_35920_) { BlockPos blockpos = this.findSpawnPositionNear(p_35918_, p_35919_.blockPosition(), p_35920_); if (blockpos != null) { TraderLlama traderllama = EntityType.TRADER_LLAMA.spawn(p_35918_, (CompoundTag)null, (Component)null, (Player)null, blockpos, MobSpawnType.EVENT, false, false); if (traderllama != null) { //Setting the trader llama despawn delay here still allows it to despawn when spawned by wander trader so MC-168188 & MC-210224 fix doesn't affect it traderllama.setDespawnDelay(47999); traderllama.setLeashedTo(p_35919_, true); } } }