The simplest way to handle this is with a gamerule. If you don't want any mobs bothering you in your creative world, just turn off spawns with /gamerule doMobSpawning false
. No mobs will spawn, which will allow you to have a quiet creative world, free from cows, pigs, sheep, chickens, slimes, etc, while also allowing yourself to do science on mobs at will. Mobs will spawn only when you want them to.
If you're really committed to the idea of doing this with /kill
, however, you can do this one of two ways. You can set up individual command blocks to kill each type of mob, which might be a small set of command blocks if your main problem is slimes.
Alternatively, you can use the methods described in this answer to select exceptions. It uses a scoreboard to set a score for all entities to 1, and simultaneously sets the score of all exceptions to 0. From there, you can select the set of all mobs excluding any exceptions you want with @e[score_select_min=1]
.
The simplest and most flexible way to keep slimes from bothering you though is to turn off mob spawning altogether.
My thought is to use a structure block, to clone the entity.
So this is what I'd do it:
- First, spawn an armor stand (as a marker) in the location of the entity to be cloned.
- Move the entity to a predefined location.
- Clone it with the structure blocks.
- Then move the entity back to the marker, and the new one where you want it.
- Finally remove the marker.
I'll just show how to set up the structure blocks. I'll assume you know what your doing with the teleportation of the entities.
So the cloning device should look like this:
(The command block in the second picture removes the stone block when a red stone block is placed there.)
So the structure block on the left is the saving block, you place the entities to be cloned on top of it.
You must have "Include Entities" set to on, or it won't clone entities.
The block on the right loads the entities. (If you use red stone to save, it will only save to RAM, not your disk, which is good.)
(The structure name doesn't have to be "cloner", but it just has to be the same in both blocks.)
When you have the cloning device set up, you just have to teleport an entity on top of the structure block on the left, place a red stone block in place of the stone one, then one red stone tick later, you'll have two identical entities.
Necro edit: I though I'd clarify why there has to be a red stone tick between them, its because structure blocks are "slow" (compared to command blocks) and require time to save the structure data. A single red stone tick is simply easy to do, but it can be any amount of time, as long as it gives the structure blocks time to do their thing.
Best Answer
In newer versions of Minecraft, you can set the sort mode that will choose how targets are sorted. You can then limit the number of targeted entities to 1, so that you are returned only 1 entity.
Here is a command that lets you do that:
The list of targets is sorted randomly, and then the limit being 1 means only the 1st one of that list is selected, essentially giving you a random entity selection.