Started by
Obzor
on
Topic category: Help with Minecraft modding (Java Edition)
I have a Sheep Protector creature that has a chance to spawn with the sheep. When checking in the world, everything works as intended, Sheep Protectors appear with a 10% chance and that's it. But when re-entering the world, the sheep again has a chance to spawn a Sheep Protector, which is not desirable at all and leads to about 10~ unwanted guests spawning in a pen of 100 sheep.
I don't know how to prevent this. The most I've come up with is to limit their number by checking for their number before spawning a new one.
I think you could probably check a custom nbt logic tag, something like initialSpawn on the sheep, and only spawn the sheep protector if initialSpawn is false. Then, regardless of whether or not the sheep protector spawned, set initialSpawn on the sheep to true.
Also make sure that you set initialSpawn to true at the end of the procedure, not before you check if it is false.
I feel like I am explaining this somewhat poorly, but basically, add an if condition around the 10% chance to spawn a sheep protector, and have that new if condition check if the custom logic nbt tag initialSpawn is false on the sheep. Then after that if condition, set initialSpawn to true, that way you will only check each sheep once.
Yes, it works great. Thank you.