Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I want to render shapes through blocks. I found this code in minecraft source 

public static void renderShape(PoseStack poseStack, VertexConsumer vertexConsumer, VoxelShape shape, double minX, double minY, double minZ, float red, float green, float blue, float alpha) {
        PoseStack.Pose pose = poseStack.last();
        shape.forAllEdges((x1, y1, z1, x2, y2, z2) -> {
            float dx = (float)(x2 - x1);
            float dy = (float)(y2 - y1);
            float dz = (float)(z2 - z1);
            float length = Mth.sqrt(dx * dx + dy * dy + dz * dz);
            dx /= length;
            dy /= length;
            dz /= length;
            vertexConsumer.vertex(pose.pose(), (float)(x1 + minX), (float)(y1 + minY), (float)(z1 + minZ)).color(red, green, blue, alpha).normal(pose.normal(), dx, dy, dz).endVertex();
            vertexConsumer.vertex(pose.pose(), (float)(x2 + minX), (float)(y2 + minY), (float)(z2 + minZ)).color(red, green, blue, alpha).normal(pose.normal(), dx, dy, dz).endVertex();
        });
    }

that draws a rectangle around the block, but it is not visible through other blocks. Could someone point me in the right direction on how one renders things through blocks?
Thanks in advance 🙏

Edited by CodecDev

  • Author

Solved! Here is my solution: Create my own RenderType.CompositeRenderType that does what i need it to. First you will need to add an access transfomer in your build.gradle (https://docs.minecraftforge.net/en/latest/advanced/accesstransformers/) and paste this there 

public net.minecraft.client.renderer.RenderType$CompositeRenderType
public net.minecraft.client.renderer.RenderType m_173209_(Ljava/lang/String;Lcom/mojang/blaze3d/vertex/VertexFormat;Lcom/mojang/blaze3d/vertex/VertexFormat$Mode;ILnet/minecraft/client/renderer/RenderType$CompositeState;)Lnet/minecraft/client/renderer/RenderType$CompositeRenderType; # create
public net.minecraft.client.renderer.RenderStateShard$LineStateShard

after that you just create your own CompositeRenderType, here is the code for mine 

public static RenderType.CompositeRenderType myOutline = RenderType.CompositeRenderType.create("myLines", DefaultVertexFormat.POSITION_COLOR_NORMAL, VertexFormat.Mode.LINES, 256, RenderType.CompositeState.builder().setShaderState(new RenderStateShard.ShaderStateShard(GameRenderer::getRendertypeLinesShader)).setLineState(new RenderStateShard.LineStateShard(OptionalDouble.empty())).setLayeringState(new RenderStateShard.LayeringStateShard("view_offset_z_layering", () -> {
        PoseStack $$0 = RenderSystem.getModelViewStack();
        $$0.pushPose();
        $$0.scale(0.99975586F, 0.99975586F, 0.99975586F);
        RenderSystem.applyModelViewMatrix();
    }, () -> {
        PoseStack $$0 = RenderSystem.getModelViewStack();
        $$0.popPose();
        RenderSystem.applyModelViewMatrix();
    })).setTransparencyState(new RenderStateShard.TransparencyStateShard("translucent_transparency", () -> {
        RenderSystem.enableBlend();
        RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
        RenderSystem.disableDepthTest();
        }, () -> {
        RenderSystem.disableBlend();
        RenderSystem.defaultBlendFunc();
        RenderSystem.enableDepthTest();
    })).setOutputState(new RenderStateShard.OutputStateShard("item_entity_target", () -> {
        if (Minecraft.useShaderTransparency()) {
            Minecraft.getInstance().levelRenderer.getItemEntityTarget().bindWrite(false);
        }

    }, () -> {
        if (Minecraft.useShaderTransparency()) {
            Minecraft.getInstance().getMainRenderTarget().bindWrite(false);
        }

    })).setDepthTestState(new RenderStateShard.DepthTestStateShard("always", 519)).setWriteMaskState(new RenderStateShard.WriteMaskStateShard(true, false)).setCullState(new RenderStateShard.CullStateShard(false)).createCompositeState(false));

I hope this helped 🙏 if you have any questions dm me on discord .ducklett

  • CodecDev changed the title to [SOLVED] Render rectangle through blocks

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.