Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • 1 year later...

Random question, what does the "16384.0d" value represent? Why must the spawn distance threshold so specific to that value? Thanks.

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.