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.

How to get a mob to spawn only when it's more than 500 blocks from x=0,z=0

Featured Replies

Posted

This will be my first mod, I have no experience at all with java or forge. I'm trying to teach myself some stuff trough tutorials on-line. But i can't seem to find the specific information i need. I feel it shouldn't be such a difficult thing to achieve, altough it probably is. Any help would be greatly appreciated :)

If you have no experience with Java, go on youtube, watch several tutorial and program in java for a weekend before starting at a minimum.  If you have no programming experience at all, take longer.

Long time Bukkit & Forge Programmer

Happy to try and help

  • Author

Thanks, both of you. I realize i should follow a few tutorials first before starting with this, because right now i don't even know how to start :P I'm not going to give up though i'll see this trough until i have something i'm happy with.

 

I'll explain a little better what my goal is.

I'd like to make a mod in which for example a custom mob starts spawning from x=500 to x=1000 and then have another custom mob spawn from x=1000 to x=1500 and so on.

 

The idea is that the further you are away from spawn the more difficult the mobs will be to kill.

yeah sorry, i meant spawnpoint. I thought they were the same, but that probabbly will make it more difficult.

 

To control where the mob spawns, override getCanSpawnHere and return wheter it should spawn (true) or not (false)

 

To check a radius, do this:

Math.abs(spawnX - entityX) >= 500 && Math.abs(spawnZ - entityZ) >= 500

will check if it's not in a 500x500 squared perimeter around the spawn

Math.sqrt(Math.pow(spawnX - entityX, 2) >= 500 && Math.pow(spawnZ - entityZ, 2)) >= 500

will check if it's not in a circle perimeter with radius 500 around the spawn (I think the math is right, don't count me on that, though)

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Rather than invoking library code to compute limits, just use:

boolean farEnough(int entityX, int entityY, int spawnX, int spawnY) {
    int dx = spawnX - entityX, dy = spawnY - entityY;
    return (dx*dx + dy*dy > 500*500);
}

Rather than invoking library code to compute limits, just use:

boolean farEnough(int entityX, int entityY, int spawnX, int spawnY) {
    int dx = spawnX - entityX, dy = spawnY - entityY;
    return (dx*dx + dy*dy > 500*500);
}

 

That works, too and is less resource-intensive.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

  • Author

Thanks guys this will definitely get the ball rolling. I'm going to need to learn some java for sure but this made things a million times easier already.

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.