Posted November 2, 20159 yr I was wondering if there was a function similar to world.getClosestPlayer. I need it something I can iterate through with a for loop. I'm basically trying to heal any player close but hurt any hostile mob close. Bumper Cars!
November 2, 20159 yr There isn't an analogous function, no, but you can use World#getEntitiesWithinAABB to get nearby entities, then iterate through that list to see which is closes (see World#getClosestPlayer if you need an example of that). http://i.imgur.com/NdrFdld.png[/img]
November 2, 20159 yr Author getEntitiesWithinAABB has a Class parameter and AxisAlignedBB parameter. I have no idea how to use that Bumper Cars!
November 2, 20159 yr The Class is the is class of entity you want to retrieve and the AxisAlignedBB (axis aligned bounding box) is the region from which you want to retrieve entities. Don't make mods if you don't know Java. Check out my website: http://shadowfacts.net Developer of many mods
November 2, 20159 yr Author So i've tried this: for(CoordEntry entry: connectedNodes) { double bnX = baseNodePos.getX(); double bnY = baseNodePos.getY(); double bnZ = baseNodePos.getZ(); double eX = entry.getPos().getX(); double eY = entry.getPos().getY(); double eZ = entry.getPos().getZ(); List entities = this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(eX, eY, eZ, bnX, bnY, bnZ)); if(player != null) player.addChatMessage(new ChatComponentText("Entities: " + entities.size())); } but my chat message always says "Entities: 0" even when I'm in range. Fyi the baseNode position and entry position are on the same X axis but have different Z coordinates is there a better way to debug the bounding box that this.worldObj.getEntitiesWithinAABB creates? I think that would help solve my problem Bumper Cars!
November 3, 20159 yr is there a better way to debug the bounding box that this.worldObj.getEntitiesWithinAABB creates? I think that would help solve my problem I usually put in console or logger statements such as System.out.println() and print out useful info. In this case you could print out the bounds of the bounding box and see it if makes sense considering where it is supposed to be in the world you're playing in. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
November 3, 20159 yr The arguments for AxisAlignedBB are MINIMUM x/y/z followed by MAXIMUM x/y/z; are you absolutely certain that the baseNodePos x/y/z will always be less than the connected node entry's x/y/z? That doesn't seem very likely to me... http://i.imgur.com/NdrFdld.png[/img]
November 3, 20159 yr for (EntityLivingBase e:world.getEntities(EntityLivingBase.class, new Predicate<EntityLivingBase>() { @Override public boolean apply(EntityLivingBase input) { return (input.getDistanceToEntity(player) <= DISTANCE); } })) { // Do stuff } It's not super clean or elegant, but it does work. Just make sure you get the right imports.
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.