How can I stop mobs from despawning?
I am using Spigot, some plugins, and I want to make like a zoo on a map, with mobs behind glass cubes. The problem is that when I load my map, every time some of the mobs just vanish, empty cages. I put eggs again, they spawn, I go to my other map in the multiverse (/mv tp my_other_map
) and when I come back, empty cages again, always the same ones...
I've read it's a question of distance of me (distance in cubes unit), if I'm too far away, the mobs will despawn... Is there a way for them to stay?
For question 1 (as they should really be two separate questions):
Mobs despawn if you are more than 32 blocks from them, as shown in this chart:
To stop a mob from despawning, you need to give it the PersistenceRequired NBT tag. You can do this when you summon the mob like this:
/summon creeper ~ ~ ~ {PersistenceRequired:1b}
Or by changing the mob's data after summoning them:
/data merge entity @e[type=creeper,distance=..10,limit=1] {PersistenceRequired:1b}
Just as an extra option to colorfusion's solution: putting a name tag on a mob will prevent them from despawning as if they were a tamed animal like a cow or chicken. This obviously does not work if the difficulty is set to peaceful as that will despawn the mobs,