So, I spawn some zombie Piglins and/or Slimes because they're cute. I name them, give them some potion effects to make them pretty much immune to receiving damage, and for the zombie Piglins give it maxed out armor. They chill in my base for a couple days and then randomly disappear but it's like only 1 or 2 that disappear of the multiple zombie Piglins or Slimes (I don't have more than 5 of them in the base at once, so I know that it isn't entity cramming). So, why does this happen? My graveyard is getting too full too quick and My friends yell at me when they come online and their pets are gone because it happens for them too. (This is in realms btw)
1 Answer
Only pets that you have actually tamed(horses,cats,dogs,parrots,foxes) or nametagged mobs are marked with the PersistenceRequired tag. Because I assume you are in creative mode
/execute as @e[type=<mob>] run data merge @s {PersistenceRequired:1b}
Run the command after you spawn your mobs, and they should never despawn. And, regarding them not taking damage, you can put this in a repeating command block:
/effect give @e[type=<mob>] resistance 1 4
You might also wanna get rid of the chat hogging, so run
/gamerule commandBlockOutput false
-
Also, <mob> is the mob you want to make resistant to damage or never despawn.– KorogueCommented Apr 20, 2021 at 14:48
-
So, all of the mobs were spawned with persistence and their respective names with their potion effects. I'm not sure what would be causing it because I have been using commands since 1.12 and I'm still learning but I'm just incredibly confused and baffled about what's going on. I was thinking it might just be realms bugging but at this point I'm not sure. These mobs should be pretty much invincible and shouldn't despawn. Thank you for the help but I don't think it's what I'm looking for. Have a great day.– CreepsyCommented Apr 20, 2021 at 16:31
-
4