Slime

Slimes are bouncy cube-shaped [hostile mob]]s that spawn in the swamp, and occasionally, deep underground.

Spawning
Slimes spawn in the Overworld in specific "slime chunks" below layer 40 regardless of light levels. They can also spawn in swamp biomes between layers 50 and 70 in light levels of 7 or less.

Only sizes 1, 2, and 4 spawn naturally. With use of, slimes can potentially range from size 1 to 256 (NBT  tag 0–255).

Slimes will not spawn within 24 blocks (spherical) of any player, and will despawn over time if no player is within 32 blocks and instantly if no player is within 128 blocks.

Slimes require two vertical transparent blocks (e.g., air, signs, torches) to spawn in, with an opaque block underneath. The space they spawn in must also be clear of solid obstructions and liquids. Big slimes require a 3×2½×3 space to spawn, medium slimes require a 3×2×3 space, and small slimes require a 1×2×1 space (or 1×1×1 if the upper block is not opaque).

Slime size is affected by regional difficulty: chances range from 33% for each size at low difficulty to 16% small, 33% medium, and 50% big with higher difficulty.

Swamps
In swamps, slimes may spawn at night between the heights of 50 and 70 provided the light level is 7 or less. They spawn most often on a full moon, and never on a new moon. Slimes only spawn in the normal swamp, not in its variant, swamp hills.

More precisely, the game checks if the light level is equal to or less than a random integer (from 0 to 7), then if the fraction of the moon that is bright is greater than a random number (from 0 to 1). If these conditions are met and the altitude is acceptable, there is a 50% chance of spawning a slime.

"Slime chunks"
Slimes spawn throughout the world (except mushroom islands) below layer 40 regardless of light level, but only in certain chunks, 1 in 10 of all chunks. These "slime chunks" are determined pseudo-randomly by combining their chunk coordinates with the seed of the world: Random rnd = new Random(seed +                       (long) (xPosition * xPosition * 0x4c1906) +                        (long) (xPosition * 0x5ac0db) +                         (long) (zPosition * zPosition) * 0x4307a7L +                        (long) (zPosition * 0x5f24f) ^ 0x3ad8025f); return rnd.nextInt(10) == 0; That is, using the chunk coordinates to help generate a seed, a random number between 0 and 9 inclusive will be generated, and if that number is 0, the chunk will be able to spawn slimes. To convert world coordinates to chunk coordinates, divide by 16 and round down. Note that xPosition and zPosition are 32 bits integers.

Bedrock Edition
The slime chunk algorithm in Bedrock Edition is different from Java Edition. The algorithm doesn't depend on the world seed, thus the chunks slimes can naturally spawn in will be the same for every world. The Bedrock Edition slime chunk algorithm was reverse engineered by @protolambda and @jocopa3 and can be found on: GitHub GitHub

Drops
If a slime's size is 1, it will drop 0-2 slimeballs. The maximum number of slimeballs is increased by 1 per level of Looting, for a maximum of 5 slimeballs.

Slimes also drop experience points equal to their size.

Behavior
Slimes move by hopping, which they will do each 10 to 30 ticks ($1⁄2$ to $1 1⁄2$ seconds), and can swim in water and climb ladders. Unlike other mobs, slimes will not stop moving when no players are nearby. Their exact routine is as follows:

The slime will search for a player (or, failing that, an iron golem) within 16 blocks (spherical) distance.
 * If no target is found, they wait 10 to 30 ticks ($1/2$ to $1 1/2$ seconds). Then they will change direction, by a random amount up to 57.26° (1 radian) left or right, jump, and repeat the process.
 * If a target is found, the delay before jumping will be $1⁄3$ as long (3 to 10 ticks), and the slime's direction will be set directly toward the target before jumping.

A slime's health is equal to their size squared, and its dimensions are 0.51 blocks times its size in each dimension. When a slime attacks, it will deal damage equal to its size, except for size 1 (smallest) slimes, which cannot do damage. Small slimes do not prevent you from sleeping.

A slime's jump distance also depends on their size; a slime will jump a distance slightly farther than its length. When landing, an amount of slime particles 1/8th its size appear.

When the player kills a slime and the slime's size is larger than 1, it will die and spawn 2-4 new slimes equivalent to its size divided by 2, rounding down.

A slime's attack speed is twice that of other melee-combat mobs. This speed is noticeable when the slime has the player cornered at a wall. Mobs like zombies and spiders attack at a rate of one hit per second, while slimes attack at a rate of two hits per second. Slimes damage all players and iron golems they collide with, unlike other mobs that only damage targets they specifically attack.

Data values
Slimes have entity data associated with them that contain various properties of the mob.

Trivia

 * From one large slime, the maximum experience a player can get from killing it and all the slimes that split from it is 28 experience; 4 experience from the largest, 8 experience from the 4 it splits into and 16 experience from the 4 each of those split into.
 * A slime will split into slimes of half its size, rounded down.
 * A named large slime that dies produces smaller slimes with the same name.
 * Dying slimes can still damage the player.
 * With commands, the sizes of slimes can be customized. Sizes go from 1 up to 256; the size-256 slimes the largest of any mob in the game, bigger than the ender dragon.
 * Tiny slimes are the weakest of all mobs: they only have 1 health point, and deal no damage, despite being a hostile mob.