Jump to content

[1.19.2] Duplicate block outline rendering with main block outline


HixlePod

Recommended Posts

Hello, I have a problem that's stumped me for a couple of days. I have successfully displayed a block outline at a specified position, the current problem is a secondary box appears that moves around based on the camera rotation and position. I have no idea what is causing this issue so any help would be appreciated.

Also, a block is required at the position in order to display the outline if you are trying to reproduce the problem.

Image of the issue
https://drive.google.com/file/d/1SBh_XaHYCgcnJSRs1mh1fdi9Yg0bCf41/view?pli=1

Code:

        public static void drawBoxAtBlockPos(PoseStack matrixStack, AABB aabbIn, float red, float green, float blue, float alpha, BlockPos pos) {
            Vec3 cam = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition();

            double camX = cam.x, camY = cam.y, camZ = cam.z;

            PoseStack.Pose pose = matrixStack.last();
            MultiBufferSource.BufferSource renderTypeBuffer = Minecraft.getInstance().renderBuffers().bufferSource();
            VertexConsumer bufferIn = renderTypeBuffer.getBuffer(RenderType.lines());

            VoxelShape voxelShape = Shapes.create(aabbIn);
            double originX = pos.getX() - camX, originY = pos.getY() - camY, originZ = pos.getZ() - camZ;

            matrixStack.pushPose();
            GL11.glDisable(GL11.GL_DEPTH_TEST);

            voxelShape.forAllEdges((x0, y0, z0, x1, y1, z1) -> {
                bufferIn.vertex(pose.pose(), (float) (x0 + originX), (float) (y0 + originY), (float) (z0 + originZ))
                        .color(red, green, blue, alpha)
                        .normal(pose.normal(), (float) (x1-x0), (float) (y1-y0), (float) (z1-z0))
                        .endVertex();

                bufferIn.vertex(pose.pose(), (float) (x1 + originX), (float) (y1 + originY), (float) (z1 + originZ))
                        .color(red, green, blue, alpha)
                        .normal(pose.normal(), (float) (x1-x0), (float) (y1-y0), (float) (z1-z0))
                        .endVertex();

            });

            renderTypeBuffer.endBatch(RenderType.lines());

            GL11.glEnable(GL11.GL_DEPTH_TEST);

            matrixStack.popPose();
        }


        @SubscribeEvent
        public static void onRenderWorldEvent(RenderLevelStageEvent event) {
            final GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer;
            Player player = Minecraft.getInstance().player;

            gameRenderer.resetProjectionMatrix(event.getProjectionMatrix());
            
            BlockPos thePos = new BlockPos(0, 67, 1);

            if (player.level.isClientSide) {
                if (player.level.getBlockState(thePos) != Blocks.AIR.defaultBlockState() && player.level.getBlockState(thePos) != Blocks.CAVE_AIR.defaultBlockState()) {
                    AABB aabb = player.level.getBlockState(thePos).getShape(player.getLevel(), new BlockPos(0, 0, 0), CollisionContext.of(player)).optimize().bounds();
                    drawBoxAtBlockPos(event.getPoseStack(), aabb, 1.0F, 1.0F, 1.0F, 1.0F, thePos);
                }
            }
        }
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.