pjlasl Posted September 10, 2013 Posted September 10, 2013 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? Quote
Mazetar Posted September 10, 2013 Posted September 10, 2013 Create an AABB and use the method for finding all entities within the AABB? Quote If you guys dont get it.. then well ya.. try harder...
pjlasl Posted September 10, 2013 Author Posted September 10, 2013 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()); } } Quote
pjlasl Posted September 10, 2013 Author Posted September 10, 2013 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. Quote
MineMaarten Posted September 11, 2013 Posted September 11, 2013 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). Quote Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.
Recommended Posts
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.