Tutorials/Managing slimes in superflat mode
On superflat maps, slimes spawn in enormous numbers, and dealing with them can become extremely tedious. Three main tricks are commonly used to handle them, although the first two are outdated methods. The first of these are to build walls or fences around areas you wish to keep slime-free. Fences would stop all slimes as well as any other mobs, or spaced columns of dirt two blocks high with a one-block gap between each will keep out medium and large slimes while still permitting all other mobs (and the harmless tiny slimes) to pass through. The second common trick is to build a slime pit or a 'slime cage' that traps any slime that blunders into it, thereby controlling the problem by coralling the slimes into known locations. Iron golems will attract slimes, so adding an iron golem to the slime cage will drastically increase the catch (fencing the iron golem in via fences will prevent it from killing the slimes). Finally, there is a third method for versions 1.9 and up. This version uses a clock with a command block. If no Slimes at all are desired, then the world can simply be generated with a surface y level above 40, which will stop the slime spawns.
Slime pit (Outdated)
This slime pit is 5×5×3, and has been dug down to to bedrock and given a one-block 'lip'. The lip ensures slimes already in the pit don't sometimes push new arrivals away before they can fall in. Recommended size is about 7×7. 4×4 is about the minimum practical size because otherwise larger slimes arriving at an angle won't fall in. Rather than making one enormous pit, it's usually better to make several medium-sized pits in different areas.
Slime cage (Outdated)
This simple slime cage made of dirt blocks traps small and large slimes but not any other mob type. Note the one-block 'steps' that allow slimes to climb into the cage, but not back out again. Their only escape is to be destroyed or to despawn. If you want to use a slime cage to help keep an area slime-free, put the steps on the inside, then any slime that does appear inside can find its way out, but not back in again.
The key idea behind both trap types is to ensure the slimes are trapped rather than killed; once enough slimes are trapped, the mob spawn rate in that area is greatly reduced and new mobs — slime or not — will largely stop spawning. When you want to do some mob farming, simply move 128+ meters away from the slime pit, at which point all the slimes in it will despawn and mobs of all types will then start reappearing elsewhere as they nomally would. A good tip is to do this either shortly before nightfall or shortly before dawn to maximise the number of farmable non-slime mobs that appear. By this method you can roughly control the numbers of mobs appearing in an area by luring more or fewer slimes into your slime pits.
One minor tip is to ensure your slime pits are dug out of earshot of the areas you spend most time in, otherwise the sound of dozens of constantly-jumping slimes can also become very wearing.
Note that given the large area covered by a typical NPC village, if you enclose an entire village inside a single wall, it's highly probable that there will be at least one slime-spawning chunk inside the village. You may wish to place blocks allowing slimes to exit certain areas and not re-enter them in order to keep their numbers manageable.
Using snowballs the player can push a slime away from the village or other area. Best for creative. Lava pits are good for pushing them into.
A moat uses the same principle as a slime pit, but it takes advantage of the fact that slimes cannot swim. For simply stopping slimes, a one-block deep moat will freeze them in their tracks, but it will only drown the smallest ones. To kill all kinds of slimes, make it three blocks wide and three blocks deep. A water moat has the advantage that it forms a complete barrier against slimes, but is completely harmless to the player and other mobs. Dry moats will capture other mobs and fail to kill the slimes. Moats are also easy to build and look nice. In 1.13 it is possible to use magma blocks to pull slimes and all other mobs down using bubble columns. If there are a lot of nearby villages, the player might be able to fill the moat with lava to kill mobs of all kinds although the only downside is that it destroys the items they drop and experience orbs unless they use hoppers.
Command block auto-killer (Creative with cheats only)
This simple trick can be achieved by using a repeating command block with the setting always active on. In the command block, use this simple command:
/kill @e[type=minecraft:slime] Or
/teleport @e[type=minecraft:slime] ~ -5 ~ (The second command will make it so the drops are not left on the ground).
The player can also type the following commands directly into the chatbox:
/gamerule doMobSpawning false (This method will make it so no mobs (including slimes) will spawn in the world)