Posted September 7, 20196 yr 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 September 7, 20196 yr by harison513
October 3, 20204 yr Random question, what does the "16384.0d" value represent? Why must the spawn distance threshold so specific to that value? Thanks.
October 8, 20204 yr 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!
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.