Jump to content

[1.17] Render texture on a specified pattern


TheOrangeInd

Recommended Posts

I'm trying to create a custom renderer for my entity and in order to do so I need to draw a sprite that has a lava texture and also a mask indicating which pixels to apply texture colors to. I've made quite a few attempts to implement this sort of thing, but all my scripts have either rendered nothing or just rendered a texture. Below is the code for my latest attempt. This code renders just a texture (instead of lava, I temporarily use a custom image). I would be grateful for any hints on how to fix it.

So this is my test script:

@Override
    public void render(EntityEruptionSource entity, float entityYaw, float partialTicks, PoseStack pose, MultiBufferSource buffer, int packedLight)
    {
        pose.pushPose();
        Vector3f vertexRotAxis = new Vector3f(0, 1, 0);
        
        GL11.glEnable(GL11.GL_STENCIL_TEST);
        GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT);
        GL11.glStencilMask(0xFF);
        GL11.glStencilFunc(GL11.GL_ALWAYS, 1, 0xFF);
        GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_REPLACE);
        VertexConsumer builder = buffer.getBuffer(RenderType.entityCutout(MainClass.RLof("textures/entities/eruption_source_mask.png")));
        Vector3f vertexPos = new Vector3f(-0.5f, 0.2f, 0.5f);
        for(int i = 0; i < 4; i++)
        {
            builder.vertex(pose.last().pose(), -vertexPos.x(), vertexPos.y(), -vertexPos.z())
                    .color(255, 255, 255, 255)
                    .uv(0, 0)
                    .overlayCoords(OverlayTexture.NO_OVERLAY)
                    .uv2(packedLight)
                    .normal(0, 1, 0)
                    .endVertex();
            vertexPos.transform(new Quaternion(vertexRotAxis, 90, true));
        }

        GL11.glStencilMask(0x00);
        GL11.glStencilFunc(GL11.GL_NOTEQUAL, 0, 0xFF);
        vertexPos = new Vector3f(-0.5f, 0.2f, 0.5f);
        VertexConsumer builder1 = buffer.getBuffer(RenderType.entityCutout(MainClass.RLof("textures/entities/eruption_source_c.png")));
        for(int i = 0; i < 4; i++)
        {
            builder1.vertex(pose.last().pose(), -vertexPos.x(), vertexPos.y(), -vertexPos.z())
                    .color(255, 255, 255, 255)
                    .uv(0, 0)
                    .overlayCoords(OverlayTexture.NO_OVERLAY)
                    .uv2(packedLight)
                    .normal(0, 1, 0)
                    .endVertex();
            vertexPos.transform(new Quaternion(vertexRotAxis, 90, true));
        }

        GL11.glDisable(GL11.GL_STENCIL_TEST);
        
        pose.popPose();

        super.render(entity, entityYaw, partialTicks, pose, buffer, packedLight);
    }

 

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.

Announcements



×
×
  • Create New...

Important Information

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