Size of entities

Discussion in 'Plugin Development' started by eisental, Feb 19, 2011.

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


    Hi, I was wondering if anyone knows of a good way to get the width and height of an entity. I'm trying to find if a mob or player are inside a cuboid and I need it to work even if the bottom (origin) of the entity is outside the cuboid and only part of it is.
    I see there's a new getEyeHeight() method but it seems only players have an eyeHeight not set to 1.0, and that won't work for spiders or pigs anyway.
    The alternative is of course to make a big if... else if (x instanceof y) for each entity type but I'm really trying to avoid that.

    Any help would be appreciated...
  2. Offline

    Edward Hand

    The net.minecraft.server.Entity class has width, height and length properties. I've never used them but you might like to look into them.

    You'll need to use the CraftPlayer.getHandle() method to get a reference to the aforementioned class.
  3. Offline


    The eye-height method is part of the getTargetBlock method, while gives the block that the player is pointing at. I just set it to 1.0 so that the system could be used for all LivingEntities.

    I may have got a little ahead of myself by adding it for all LivingEntities rather than players.

    If there is a getHeight() method for entities, then the eye height could be made dependent on that (say 1.5 if the entity has a height > 1 and 0.5 if the height is <= 1.
    --- merged: Feb 19, 2011 1:44 PM ---
    You could also submit a pull request that exposes the height/width/length methods.
  4. Offline


    Thanks, now I feel stupid for not checking Entity myself :p
    It also has a boundingBox field, apparently... I wonder if there's any reason the bukkit Entity class doesn't expose it.
    --- merged: Feb 19, 2011 1:56 PM ---
    Didn't see your message, Raphfrk. You read my mind...
    I'll definitely make a pull request.
    --- merged: Feb 19, 2011 2:37 PM ---
    Apparently, entity.height is always 0 for LivingEntity s anybody knows what's that about?
    --- merged: Feb 19, 2011 3:33 PM ---
    Here are some examples of Entity.height, Entity.width, Entity.length for different Entity s
    CraftPig size: 0.0, 0.9, 0.9
    CraftSquid size: 0.0, 0.95, 0.95
    CraftPlayer{name=eisental} size: 0.0, 1.8, 0.6
    CraftItem size: 0.125, 0.25, 0.25
    CraftChicken size: 0.0, 0.4, 0.3
    CraftBoat size: 0.3, 0.6, 1.5
    CraftSheep size: 0.0, 1.3, 0.9

    Seems like LivingEntity is messing it up, but CraftBoat and CraftItem are ok.
    Entity.width for CraftPlayer is obviously the entity height but then either length or width are missing.

    EDIT: If anybody knows how Entity.boundingbox works please do tell.
  5. Offline


    I decided to try using Entity.boundingBox.
    I'm using this to get size dimensions:
    Entity e = some entity;
    width = e.boundingBox.d - e.boundingBox.a;
    height = e.boundingBox.e - e.boundingBox.b;
    length= e.boundingBox.f - e.boundingBox.c;
    This way the width and length of any entity (even sheep and cows...) is the same. Is there anybody that has a clue about what's going on?

    Oh, and another question. Does anybody know if Entity.getLocation() points to the center of the entity? or is it the entity's origin point?

Thread Status:
Not open for further replies.

Share This Page