Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

How do I render bounding box to entity?


Recommended Posts

I want the bounding box to be visible to the entity the player is looking at. But the bounding box is displayed to me.

How do I display this to entity?


This is my code:


    public void renderWorldLastEvent(RenderWorldLastEvent event) {

        if (Minecraft.getMinecraft().objectMouseOver.entityHit != null) {
            renderEntityBox(Minecraft.getMinecraft().objectMouseOver.entityHit, event.getPartialTicks());

    void renderEntityBox(Entity entity, float PartialTicks) {

        AxisAlignedBB boundingBox = entity.getEntityBoundingBox();

        double d0 = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double)PartialTicks;
        double d1 = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)PartialTicks;
        double d2 = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double)PartialTicks;
        Tessellator.getInstance().getBuffer().setTranslation(-d0, -d1, -d2);
        RenderGlobal.drawSelectionBoundingBox(boundingBox, 1.0F,1.0F,1.0F,1.0F);



Or can the entity's outline be displayed in red? Instead of doing it like a Glowing effect, it's red.




Edited by Guebeul
Link to comment
Share on other sites

This is because opengl coordinate space defines the coordinate (x0, y0, z0) as the camera position. In order to have the bounding box displayed around the entity, you would have to translate (and probably also rotate) the bounding box to the entity position.


You could check out the code used in minecraft debug mode (Pressing F3+B).

Edited by deerangle
Link to comment
Share on other sites

first translate to world origin 0,0,0

GlStateManager.translate(-player.posX, -player.posY, -player.posZ);


then translate to the entity position

GlStateManager.translate(entity.posX, entity.posY, entity.posZ);




but you should combine them to one translate call, like

GlStateManager.translate(entity.posX - player.posX, entity.posY - player.posY, entity.posZ - player.posZ);


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.