The bug
Based on the code slimes with a Size
value of 0 are probably not supposed to despawn. This makes sense because they cannot damage the player.
Note that this does not apply to magma cubes since they can always damage the player, even when their Size
is 0.
Reproduction steps
Summon a small slime
/summon minecraft:slime ~ ~ ~ {Size:0}
Change the difficult to Peaceful
❌ The slime despawns
Code analysis
The following is based on a decompiled version of Minecraft 1.17.1-pre1 with Mojang names
The reason for this is that the method net.minecraft.world.entity.monster.Slime.readAdditionalSaveData(CompoundTag)
adds 1 to the read Size
value before storing its value as net.minecraft.world.entity.monster.Slime.ID_SIZE
(and the value is clamped between 1 and 127, both inclusive).
However the method net.minecraft.world.entity.monster.Slime.shouldDespawnInPeaceful()
tests if the value is greater than 0, which is therefore always the case.
Instead that method should possibly call isDealsDamage()
to determine whether the slime should despawn (though this would allow NoAI
slimes to remain in the world even if they would normally, with AI, would damage players).
Attachments
Comments 23
In 1.10.2 small slimes still despawn so I added the affected version. I cannot confirm however that the code is still the same.
This is caused by the fact that slimes are seen as hostile mobs by the game, even if they can't hurt you because a specific variable(integer): Size
for this reason, this is technically not a bug
1.9 versions are outdated, so you might need to redo it in 1.10.2