Getting a block's bounding box (AxisAlignedBB)

Discussion in 'Spigot Plugin Development' started by Killstreak702, Jun 1, 2017.

  1. Heyo,

    So quick question, I've been searching for a little bit now and can't seem to find a method that returns a block's bounding box.

    Basically, I need a method, or anything at all, that will return an AxisAlignedBB of a Block.

    Ex:
    Code (Text):
    public AxisAlignedBB getBoundingBox(Block block) {
    // do whatever and return the bounding box of the block
    }
    I've searched on Spigot and some forums but can't seem to find a method that returns it. So far I've only found one that returns a bounding box for a player, but nothing for blocks.

    Some help would be great :)
     
  2. I thought that blocks dont have hitboxes (that is what a bounding box is as I know), but you can explore the world of NMS
     
  3. I'm pretty sure they do, was talking to another developer about it just now and they think they have bounding boxes too. I haven't really done anything with NMS before though
     
  4. NMS = net.minecraft.server (version dependent), just look for the block class in NMS and decompile it and get its methods and variables, or use the NMS block and try to find a method that returns what you want. I can help you convert it to reflection (that is used to support more versions)
     
  5. Code (Text):
    BlockPosition pos = new BlockPosition(block.getX(), block.getY(), block.getZ());
    WorldServer world = ((CraftWorld) block.getWorld()).getHandle();
    AxisAlignedBB box = world.getType(pos).d(world, pos);
    min = new Vector(pos.getX() + box.a, pos.getY() + box.b, pos.getZ() + box.c);
    max = new Vector(pos.getX() + box.d, pos.getY() + box.e, pos.getZ() + box.f);
     
    This works in 1.12, earlier/later versions may be different. You can set the min/max to a new aabb object if you want.

    I use this in my sign editing plugin (plus some ray tracing stuffs) to properly find block hitboxes. It allows me to edit see between two double slabs (half block of air between) and to find if a player is actually looking at a sign and not just passed it, etc.

    Its extremely accurate. The block you look at shows an outline on the client in survival/creative mode. This is that hitbox.

    Here's some videos showing the different of player#getTargetBlock and the above code



    Also, be careful when using NMS like this. I caught shit ton of heat for making "a signedit plugin that is nms dependent" and no one fully understood why I did it so the plugin never really gained any ground passed my own server.
     
    #5 BillyGalbreath, Jun 1, 2017
    Last edited: Jun 1, 2017
    • Informative Informative x 1
    • Useful Useful x 1
  6. Sorry for the late reply.

    @BillyGalbreath Thanks, I'm making this plugin for 1.7 but I'll see if it's the same or somewhat different than 1.12.
     
  7. lol no that music :p, and does it work for stairs?