Jump to content

1.19.3 how to render lines through blocks using LevelRenderer.renderLineBox


sFXprt

Recommended Posts

I can easily draw the bounding box of an entity on the client side, but now the problem is that I can only see the lines when I am not behind any blocks. 

Here is the draw method 

public static void drawLineBox(Client client, PoseStack matrixStack, AABB aabb) {
        Vec3 camVec = client.getInstance().getEntityRenderDispatcher().camera.getPosition();

        VertexConsumer vertexConsumer = Minecraft.getInstance().renderBuffers().bufferSource().getBuffer(RenderType.lines());

        RenderSystem.disableDepthTest();
        matrixStack.pushPose();

        matrixStack.translate(-camVec.x(), -camVec.y(), -camVec.z());
        LevelRenderer.renderLineBox(matrixStack, vertexConsumer, aabb, 15f, 15f, 15f, 1F);
        matrixStack.popPose();
        RenderSystem.enableDepthTest();
    }

Here is how I call it 

@SubscribeEvent
    public static void onRender(RenderLevelStageEvent e){
        Client client = new Client();
        if(e.getStage().equals(RenderLevelStageEvent.Stage.AFTER_ENTITIES)){
            for(Entity entity : client.getInstance().level.entitiesForRendering()){
                if(entity instanceof LivingEntity target){
                    if(!Utils.isPlayer(target)){
                        drawLineBox(client, e.getPoseStack(), target.getBoundingBox());
                    }
                }
            }
        }
    }

 

Like I said it renders the boxes perfectly but I can only see them when my vision isn't blocked. I tried following an x-ray mod which drew using Tesselator and VertexBuffer instead of just purely LevelRenderer.

https://github.com/AdvancedXRay/XRay-Mod/blob/main/src/main/java/pro/mikey/xray/xray/Render.java#:~:text=static void renderBlocks(RenderLevelStageEvent event) {

 

After closely following the code and editing it to match my goals it wouldn't render any entities except just randomly rendering blocks that had nothing to do with entities(I used Entity#position() instead of Entity#getBoundingBox()) 

However the code in the github above does in fact allow me to see the box through blocks which is exactly what I want but draws the wrong things and in the wrong area. 

Before anyone says, I've already tried disabling and re-enabling depth test using various classes/methods. 

I've used the following below

RenderSystem.disableDepthTest();
GlStateManager._disableDepthTest();
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_DEPTH);
RenderSystem.depthMask(false);

which none of them work at all when drawing with LevelRenderer which makes me things its a LevelRenderer issue? Ill look into code using LevelRenderer if I find any... 

Link to comment
Share on other sites

You shouldn't be playing with opengl calls directly, you will likely just break things when you change things in ways minecraft doesn't understand.

Use minecraft's RenderSystem.

 

But in this case, directly modifying the opengl state using any of those calls is not going to work.

You are using a buffer to do the rendering. That means it is not doing the rendering immediately.

Instead once everybody has had a chance to fill the buffer (long after your code has run);

* The rendering state is initialised from the RenderType of the buffer

* The buffer is flushed to the graphics card

* The relevant shader(s) are called to process the buffer.

 

If you want to do something different you will likely have to make your own RenderType (if one does not already exist that does what you want) or draw directly so you have control of the rendering state.

I am not an expert on rendering, so I can't really help you with how to do that.

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.

Link to comment
Share on other sites

Just now, warjort said:

You shouldn't be playing with opengl calls directly, you will likely just break things when you change things in ways minecraft doesn't understand.

Use minecraft's RenderSystem.

 

But in this case, directly modifying the opengl state using any of those calls is not going to work.

You are using a buffer to do the rendering. That means it is not doing the rendering immediately.

Instead once everybody has had a chance to fill the buffer (long after your code has run);

* The rendering state is initialised from the RenderType of the buffer

* The buffer is flushed to the graphics card

* The relevant shader(s) are called to process the buffer.

 

If you want to do something different you will likely have to make your own RenderType (if one does not already exist that does what you want) or draw directly so you have control of the rendering state.

I am not an expert on rendering, so I can't really help you with how to do that.

Thank you @warjort you have been very very helpful and informative to me on the forum. I think I understand what I need to do now. Thanks again.

Link to comment
Share on other sites

On 4/16/2023 at 1:56 AM, warjort said:

You shouldn't be playing with opengl calls directly, you will likely just break things when you change things in ways minecraft doesn't understand.

Use minecraft's RenderSystem.

 

But in this case, directly modifying the opengl state using any of those calls is not going to work.

You are using a buffer to do the rendering. That means it is not doing the rendering immediately.

Instead once everybody has had a chance to fill the buffer (long after your code has run);

* The rendering state is initialised from the RenderType of the buffer

* The buffer is flushed to the graphics card

* The relevant shader(s) are called to process the buffer.

 

If you want to do something different you will likely have to make your own RenderType (if one does not already exist that does what you want) or draw directly so you have control of the rendering state.

I am not an expert on rendering, so I can't really help you with how to do that.

Hey you were right, after the buffer was flushed and the shaders were processed it only did so one at a time. For anyone whos stuck on this issue just make sure you arent filling the buffer on an if(vertexBuffer == null) check and call vertexBuffer.close() before unbind.

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.
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.



×
×
  • Create New...

Important Information

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