Jump to content

Recommended Posts

Posted (edited)

As the title states, I finally managed to figure out how to draw entities. Problem is, I can't figure out why its drawing the boxes twice. 

https://ibb.co/X3xhyY0

 

Here is the code that draws

public static void drawLineBox(PoseStack matrixStack, AABB aabb, Camera camEntity, float r, float g, float b, float a) {
        double d0 = camEntity.getPosition().x();
        double d1 = camEntity.getPosition().y();
        double d2 = camEntity.getPosition().z();

        RenderSystem.depthMask(false); // disable showing lines through blocks
        VertexConsumer vertexConsumer = Minecraft.getInstance().renderBuffers().bufferSource().getBuffer(RenderType.lines());

        matrixStack.pushPose();
        matrixStack.translate(-d0, -d1, -d2); // because we start at 0,0,0 relative to camera
        LevelRenderer.renderLineBox(matrixStack, vertexConsumer, aabb, r, g, b, a);
        matrixStack.popPose();
    }

Here is where its called from

@SubscribeEvent
    public static void onRender(RenderLevelStageEvent e){
        for(Entity entity : Minecraft.getInstance().level.entitiesForRendering()){
            drawLineBox(e.getPoseStack(), entity.getBoundingBoxForCulling(), e.getCamera(),15.9f, 15.9f, 15.9f, 15.5f);
        }
    }

 

Any ideas? I'm not familiar with drawing with forge/and or OpenGL. On C++ its extremely easy and I understand the concept of drawing but here I have no idea.

 

EDIT: Im assuming this has to do with FoV as moving the slider down makes the two boxes render in the same exact place thus making it look a lot better than what I see in the picture, however I just want to make sure if thats it or theres some error on my part thats making the boxes render twice

Edited by sFXprt
Posted (edited)

You are not checking the stage, so you are rendering at every stage.

https://github.com/MinecraftForge/MinecraftForge/blob/01846c729a21c13cb86447c4e233b83a314b6856/src/main/java/net/minecraftforge/client/event/RenderLevelStageEvent.java#L57

and

Quote

matrixStack.translate(-d0, -d1, -d2); // because we start at 0,0,0 relative to camera

That's not always true.

e.g. when minecraft draws the normal block/entity hitboxes the matrix has been transformed to the camera

or if you are using the normal renderers it will have already translated to the block/entity

otherwise it will likely be at world 0,0,0 ?

Edited by warjort
  • Like 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.