Minecraft – How to make an entity unkillable

minecraft-bukkitminecraft-java-editionminecraft-java-edition-server

I want to protect my custom entity but everyone can kill it. I tried to loop setting health to max, I tried to protect it with events but it could still die.

How to protect it? Or is there any built-in-minecraft method which makes the entity unkillable?​

Best Answer

Use the Invulnerable tag. Spawn the Entity with the extra tag {Invulnerable:1}.

Another choice is the resistance potion effect:

/effect <Target> minecraft:resistance 1000000 255 true