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 know there is a way, but I cannot find it. How can I identify the number of entities around me in a given block radius?

Create an AABB and use the method for finding all entities within the AABB?

If you guys dont get it.. then well ya.. try harder...

  • Author

Thanks for the push in the right direction.ย  ;) It took me a few minutes, but I figured it out. Now it will identify any EntityMob within 5 blocks (if my understanding of the +5 is correct)

ย 

For those who actually would like to see some code:

ย 


List e = player.worldObj.getEntitiesWithinAABB(EntityMob.class, AxisAlignedBB.getBoundingBox(player.posX, player.posY, player.posZ, (player.posX + 5),(player.posY + 5),(player.posZ + 5)));

if (e.size() > 0) {

ย  ย  ย  ย  	for (int i = 0; i <= e.size() - 1; i++) {
ย  ย  ย  ย  		EntityMob em = (EntityMob) e.get(i);
ย  ย  ย  ย  		LogHelper.info(em.getEntityName());
ย  ย  ย  ย  	}ย  ย  	
ย  ย  ย  ย  	
ย  ย  ย  ย  }ย   

  • Author

Ok. I have this working for client side detection, but how do I make it identify the entities on the serverside? the method returns 0 everytime.

You've almost got it right. Now you're setting up a AABB for only a part of the radius. This can be solved by doing this:

List<EntityMob> e = player.worldObj.getEntitiesWithinAABB(EntityMob.class, AxisAlignedBB.getBoundingBox(player.posX - 5, player.posY - 5, player.posZ - 5, player.posX + 5, player.posY + 5, player.posZ + 5));

Checking for e.size() > 0 is unnecessary, as the test of the for loop will be false at the start (0 <= 0 - 1) = false. But this is a small side note.

ย 

This code should work at the server side as well....

ย 

By the way, if you want to have a real max of 5 blocks, you can use Pythagoras' theorem to filter out entities that are outside your radius (you're now checking in a box around the player).

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

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.