mojira.dev
MC-101870

Slimes with Size 0 despawn with Peaceful difficulty

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

  1. Summon a small slime

    /summon minecraft:slime ~ ~ ~ {Size:0}
  2. 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

1.9 versions are outdated, so you might need to redo it in 1.10.2

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

Still present in 1.13.1.

13 more comments

Can confirm in 1.18.2 and 22w19a.

Can confirm in 1.19.

Can confirm in 1.19.1.

Can confirm in 1.19.2.

Can confirm in 1.20.1

marcono1234

(Unassigned)

Confirmed

Mob behaviour

despawn, magma_cube, peaceful, slime

Minecraft 1.9.4, Minecraft 1.10.2, Minecraft 1.11, Minecraft 16w50a, Minecraft 1.13.1, ..., 1.20.1, 1.20.3 Release Candidate 1, 1.21.3, 24w46a, 1.21.5

Retrieved