How do I prevent a specific mob from being killed by players?

How do I prevent a specific mob from being killed by players? - Frame with text placed on blackboard with sterile mask

I'm making a map in Minecraft. No mods, no Bukkit, no anything; just command blocks. and I have this one mob that I don't want players to be able to kill.

Normally, I would simply give it a resistance potion so that it couldn't be hurt, but I want other mobs to be able to hurt it, just not players.

Is it possible to make this mob unkillable by players, but still able to die by other mobs?



Best Answer

You could give the player a really strong weakness status effect if they're within melee range of the mob. This isn't exactly what you're looking for, since the player won't be able to kill any mobs within that region, even ones that they normally would elsewhere. If you're fine with that, then go right ahead.

If you also want it to be immune to player-shot arrows you could add

execute at @e[tag=enemy] run kill @e[type=arrow,distance=..2,nbt={pickup:1b}]

This only affects arrows shot by someone in survival or adventure mode, and not in creative. It also ignores arrows from entities like skeletons or pillagers.




Pictures about "How do I prevent a specific mob from being killed by players?"

How do I prevent a specific mob from being killed by players? - From above of face mask on blackboard with I Cant Breathe title during COVID 19 pandemic
How do I prevent a specific mob from being killed by players? - Set of gratitude message for doctors with stethoscope and hearts
How do I prevent a specific mob from being killed by players? - Top view of many clean single use light blue surgical protective face mask lying on top of each other in disorder



Can you disable certain mobs in Minecraft?

Java Edition players can type \u201c/gamerule doMobSpawning false\u201d into the chat bar to disable mobs. You'll need to be a server admin and have cheats enabled. Keep in mind using this setting will also disable friendly spawns as well, like animals.

How do you make a command block kill a specific mob?

If you want to kill mobs all at once then this step is the best.
  • Type /kill.
  • Use @e to target all the entities.
  • Type [type=! player]. This will kill every Mobs.
  • Execute the command by pressing Enter.




  • Minecraft| How to get rid specific Mobs?




    More answers regarding how do I prevent a specific mob from being killed by players?

    Answer 2

    /summon ExampleMob ~ ~ ~ {Invulnerable:1}
    

    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: Brett Sayles, Brett Sayles, Karolina Grabowska, Karolina Grabowska