Jump to content

[1.12]Changing Color of Model Dynamically


proudmoorn

Recommended Posts

Hello,

I'm attempting to change the color of a block (of leaves) dynamically based on how close they are to the end of a progress.

I get the model of the leaf to render, but it always renders in greyscale, no matter how I try to modify the color. I've attached my TileEntityRenderer's render function, along with a lot of the debug code I've attempted.

 

Color output looks like this: Color:-4665437 R:0.72156864 G:0.8117647 B:0.6392157


Any help is appreciated.

 

	@Override
    public void render(TileExplosiveLeaves te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
        GlStateManager.pushMatrix();
        GlStateManager.enableRescaleNormal();

        RenderHelper.disableStandardItemLighting();
        GlStateManager.enableColorMaterial();

        int color = te.getColor().toInt();

        float colorRed = (float) (color >> 16 & 255) / 255.0F;
        float colorGreen = (float) (color >> 8 & 255) / 255.0F;
        float colorBlue = (float) (color & 255) / 255.0F;
        float colorAlpha = (float) (color >> 24 & 255) / 255.0F;

        System.out.println("Color:" + color + " R:" + colorRed + " G:" + colorGreen + " B:" + colorBlue);

//        GlStateManager.resetColor();
//        GL11.glColor3f(color.r, color.g, color.b);
//        GL11.

        GlStateManager.enableBlend();
//        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);



        World world = te.getWorld();

        bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);

        Tessellator tessellator = Tessellator.getInstance();
        tessellator.getBuffer().begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);

        tessellator.getBuffer().color(colorRed, colorGreen, colorBlue, colorAlpha);

        Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(
                world,
                Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(te.getLeafBlock()),
                world.getBlockState(te.getPos()),
                te.getPos(),
                Tessellator.getInstance().getBuffer(), false);
        tessellator.draw();
  //        RenderHelper.enableStandardItemLighting();

//        GlStateManager.enableLighting();

        GlStateManager.popMatrix();

        GlStateManager.disableBlend();

 

Link to comment
Share on other sites

17 hours ago, diesieben07 said:

Ok, so. If you want a continuous color transition (which you still have not answered!) then you need to indeed stick with the TESR. Otherwise use IBlockColors. In your current TESR method the issue is that the model rendering method you are using already applies the block's "native" color modifier, overwriting yours.

Sorry! I thought I did! I do want it to be a continuous. Can you recommend an alternative method to look at for rendering? (I don't need examples, just a general gist will be enough)

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.