Jump to content

[Solved] [1.14.4] Entity Natural Spawning Bug?


Recommended Posts

I'm trying to override CreatureEntity:canSpawn in my custom entity to prevent certain spawns, however even when I just return false the entities still spawn.


I could be wrong but to me this line in WorldEntitySpawner::performNaturalSpawning doesn't make much sense (line 126):


if (canSpawn == -1 || (canSpawn == 0 && d0 > 16384.0D && (mobentity.canDespawn(d0) || !mobentity.canSpawn(p_222263_1_, SpawnReason.NATURAL) || !mobentity.isNotColliding(p_222263_1_)))) {
   break label115;


About a 1/4 of the way in where it says d0 > 16384.0D. I believe d0 is the distance squared from the player to the attempted spawn location, so in this case it means if the distance isn't greater than 16384 CreatureEntity:canSpawn won't be called and it will just keep going about spawning the entity.


Please let me know if I've missed anything.

Edited by harison513
Link to comment
Share on other sites

  • 1 year later...
On 10/3/2020 at 10:58 AM, diesieben07 said:

It's 128². For distance calculations you use pythagoras: distance = sqrt((x1 - x2)² + (y1 - y2)² + (z1 - z2)²). However the square root operation at the end is somewhat expensive in terms of computing time. So if you only want to check "Is the distance lower than 128?" you can skip the square root part and instead check if the squared distance is lower than 128², which happens to be 16384.

That's very helpful to know, and makes sense in terms of saving computational costs. Appreciate your reply. Many thanks @diesieben07!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.