Monsters in an area?

Discussion in 'Plugin Development' started by Saturisk, Mar 6, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Saturisk

    Is there a way to get, say all monsters/ creatures in an area of 10 blocks or something like that? I'm working on spells for a plugin on my server and just wanted to know if it's possible
     
  2. Offline

    Edward Hand

    I know I already told you this in the PM you sent me, but I thought I'd post it here in case anyone else comes looking for the solution:

    Code:
    Location loc = thePlayer.getLocation();
    CraftWorld craftWorld = (CraftWorld)event.getPlayer().getWorld();
    CraftPlayer craftPlayer = (CraftPlayer)thePlayer;
    
    double x = loc.getX()+0.5;
    double y = loc.getY()+0.5;
    double z = loc.getZ()+0.5;
    double radius = 10;
    
    List entities = new ArrayList();
    AxisAlignedBB bb = AxisAlignedBB.a(x-radius,y-radius,z-radius,x+radius,y+radius,z+radius);
    entities = craftWorld.getHandle().b(craftPlayer.getHandle(), bb);
    Get's all entities (players, mobs, boats, paintings and everything, excluding thePlayer) within a cube of size 2*radius around the player and puts them in the ArrayList.
    Note: the entities in the list are of class net.minecraft.server.Entity not org.bukkit.entity.Entity
    To convert:
    Entity bukkitEntity = entities.get(n).bukkitEntity;
     
  3. Offline

    Saturisk

    Where do you get this information!?!?! haha it's so nice to have someone who knows exactly what to do and how to do it!
     
  4. Offline

    Plague

    Wow, man, just wow :)
     
  5. Offline

    narrowtux

    One question that's offtopic: What's the AxisAlignedBB class used for in the minecraft server?
     
  6. Offline

    Edward Hand

    It's used all over the place for holding information about bounding boxes - both for blocks and entities. On the client, when in game, if you look at a close-by block, minecraft draws a little grey wireframe cube around it. That is a visual representation of the block's AxisAlignedBB. Entities too have bounding boxes (though you never get to see them). The bounding boxes are mainly used for collision detection between entities and blocks or between entities and entities, but also for just defining generic regions, like a search region in my example above.
     
  7. Offline

    narrowtux

    Good to know, with this algorithm, I could make my Passenger-Detection in MagnetBlock much more efficient!
     
  8. Offline

    4am

    Are their any bounding-box type structures that aren't axis-aligned? I imagine that entities must use one as they aren't required to remain aligned while moving?
     
  9. Offline

    Edward Hand

    Nope. Notch just loves cubes.
     
Thread Status:
Not open for further replies.

Share This Page