Topic category: Help with Minecraft modding (Java Edition)
have a mod where i have added Inquisitors and crossbow zombies who everytime they get a kill spawn a new mob of the same type. In regards to the inquisitors they spawn villagers as well. I was curious if there is a way to make the game check to see if there are a certain number of the same mob in a chunk. If there is then they would delay being spawned at that point or would be spawned 32 chunks away. I have noticed that my game will quickly be over run with mobs which greatly effects FPS. The villagers spawning is not a huge problem because if the are spawning underground zombies and things will kill them and if they are close to villages they will populate them. However the special zombies and the inquisitors I would like there to be a limit of say 10 to 20 in a chunk
Off the top of my head, Mcreator doesn't have many built in chunk based procedures and as I'm guessing you want to avoid custom code, you're next best option is to calculate all this for yourself. You can use the entity spawn event to create a list of x,z coordinates where these mobs have spawned, this doesnt make up for mobs moving between chunks but in your use case it will work fine, whenever another mob attempts to spawn you will calculate the x,z coordinate ranges of the chunk it is in and compare that to your existing list to find how many have already spawned in that chunk. If you're worried about this method potentially preventing mobs from spawning in often loaded chunks, just wipe the list based on a timer or such.
I am asking because there appears to be procedure that says does entity exist at x y z of type in cube the size of 16 . I assume this is meant to check to see if that particular mob is present. in the vicinity. If I want it to check for that mob in a chunk I would keep it at 16. I would to make this equal true and then add another variable which includes 0<20 which I would assume is saying it should be less than 20 before that entity should spawn.
Oh if you want to go that route then use the "for each entity of type in a square cube" procedure and for each of the mobs within the cube iterate a counter by 1, if the counter is >20 or so, cancel the spawn.
I will say that this solution will break if mobs spawn in caves or anything as it will only check 16 blocks in every direction, including on the y axis.
I would assume i can make the y axis deeper. My main purpose is to make it so that mob type does not produce so many mobs that it crashes the game. I have noticed I will start with 1 inquisitor and within minutes I would have 100s of them.
You can't make the y-axis deeper for that code block, that's now how "square cube of size x" works.
If you do want to go ahead with this method though, you need to use the "on entity spawn" global event or whatever trigger you're using for custom spawning. Then do your check for how many of the entity are in the area and cancel the event if there's too many.