ThatBenderGuy Posted November 2, 2015 Posted November 2, 2015 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. Quote Bumper Cars!
coolAlias Posted November 2, 2015 Posted November 2, 2015 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). Quote http://i.imgur.com/NdrFdld.png[/img]
ThatBenderGuy Posted November 2, 2015 Author Posted November 2, 2015 getEntitiesWithinAABB has a Class parameter and AxisAlignedBB parameter. I have no idea how to use that Quote Bumper Cars!
shadowfacts Posted November 2, 2015 Posted November 2, 2015 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. Quote Don't make mods if you don't know Java. Check out my website: http://shadowfacts.net Developer of many mods
ThatBenderGuy Posted November 2, 2015 Author Posted November 2, 2015 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 Quote Bumper Cars!
jabelar Posted November 3, 2015 Posted November 3, 2015 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. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
coolAlias Posted November 3, 2015 Posted November 3, 2015 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... Quote http://i.imgur.com/NdrFdld.png[/img]
TrashCaster Posted November 3, 2015 Posted November 3, 2015 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. Quote
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.