I am looking for a way to trap a limited number of mobs and stop them from despawning

Started by Catnip on

Topic category: Advanced modding

Last seen on 23:17, 26. Apr 2024
Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I am looking for a way to trap a limited number of mobs and stop them from despawning

I have created a system for a mod where mobs that walk onto a special pedestal become trapped, but one pedestal can only trap a couple of mobs, to prevent overcrowding. I have another block that automatically produces items based on what mobs are trapped on nearby pedestals, and I have found a way to make it work with nearly any mob, vanilla or modded. My new problem is that when I trap hostile mobs, they eventually despawn, and I imagine that it would be frustrating, especially in survival mode, if you went through the time and effort of luring mobs to a pedestal, only to have them despawn, and you get nothing for it. I haven't found a way to prevent or stop the despawning of mobs so far, as far as I can tell, and I looked several times, there is no cancelable global trigger for a mob despawning, and there isn't an easy way to set a mob to not despawn. I have tried naming the mobs, as listed in https://mcreator.net/forum/99818/how-stop-vanilla-mobs-despawning-when-idle but it didn't work for some of the mobs I spawned in. I also don't think that the other solutions listed will work, since I want it to be compatible with almost any modded mob, depending on it's position in the world, and as far as I know, there is no way to spawn in a mob by using a registry name, or to detect if it is about to despawn, both of which would be needed to create a workaround.

My ultimate question is "Is there any simple custom code that can be applied to a mob to completely prevent it from despawning?" I already have the mod's features set up so that overcrowding shouldn't happen, so all I need to do is stop the despawning of mobs.

Last seen on 03:15, 26. Apr 2024
Joined Aug 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i don't know coding, but you…
Sun, 02/18/2024 - 01:16

i don't know coding, but you could make a procedure rename all the entities of a specific type, or within a specific area, or on a specific block, or even just by looking at them. you would want "if entity collides with block,' rename them"  (display name)

renaming prevents despawning

Last seen on 23:17, 26. Apr 2024
Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I am currently using…
Sun, 02/18/2024 - 01:39

I am currently using procedures to rename the mobs, but it isn't working. I'm pretty sure that name tags set a specific nbt tag on mobs because mobs from named spawn eggs in vanilla Minecraft still despawn even though they are named. I have not yet figured out how to set the name tag nbt value on mobs. Thank you for taking the time to try and help though, I appreciate it.