Jump to content

[1.10.2] Render fluid level in tank with TESR


Recommended Posts

Posted

I am trying to render fluid inside a tank block with a TESR. The fluid I am trying to render in my tests is either water or lava.

 

This is my TESR:

    public void renderTileEntityAt(TileEntityFluidTank te, double x, double y, double z, float partialTicks, int destroyStage)
    {
        GlStateManager.pushMatrix();
        int capacity = te.getFluidHandler().getCapacity();
        FluidStack fluid = te.getFluidHandler().getFluid();
        if (fluid != null)
        {
            Tessellator tess = Tessellator.getInstance();
            VertexBuffer buffer = tess.getBuffer();

            buffer.setTranslation(x, y, z);

            bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
            TextureAtlasSprite still = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(fluid.getFluid().getStill().toString());
            TextureAtlasSprite flow =  Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(fluid.getFluid().getFlowing().toString());

            double posY = .1 + (.8 * ((float) fluid.amount / (float) capacity));
            float[] color = ClientUtils.getRGBAFloatArrayFromHexColor(fluid.getFluid().getColor(fluid));

            buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
            buffer.pos( 4/16, posY,  4/16).tex(still.getInterpolatedU( 4), still.getInterpolatedV( 4)).color(color[0], color[1], color[2], color[3]).endVertex();
            buffer.pos(12/16, posY,  4/16).tex(still.getInterpolatedU(12), still.getInterpolatedV( 4)).color(color[0], color[1], color[2], color[3]).endVertex();
            buffer.pos(12/16, posY, 12/16).tex(still.getInterpolatedU(12), still.getInterpolatedV(12)).color(color[0], color[1], color[2], color[3]).endVertex();
            buffer.pos( 4/16, posY, 12/16).tex(still.getInterpolatedU( 4), still.getInterpolatedV(12)).color(color[0], color[1], color[2], color[3]).endVertex();
            tess.draw();

            buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
            buffer.pos(12/16, 1/16, 12/16).tex(flow.getInterpolatedU(12), flow.getInterpolatedV(15)).color(color[0], color[1], color[2], color[3]).endVertex();
            buffer.pos(12/16, posY, 12/16).tex(flow.getInterpolatedU(12), flow.getInterpolatedV( 1)).color(color[0], color[1], color[2], color[3]).endVertex();
            buffer.pos( 4/16, posY, 12/16).tex(flow.getInterpolatedU( 4), flow.getInterpolatedV( 1)).color(color[0], color[1], color[2], color[3]).endVertex();
            buffer.pos( 4/16, 1/16, 12/16).tex(flow.getInterpolatedU( 4), flow.getInterpolatedV(15)).color(color[0], color[1], color[2], color[3]).endVertex();
            tess.draw();

            buffer.setTranslation(0, 0, 0);
        }
        GlStateManager.popMatrix();
    }

 

This code currently only renders two sides of the five sides that need to be rendered (or at least it should). Instead of rendering the water or lava texture, it renders nothing.

Posted

The client is properly updated. I will recheck if I bound it correctly, I might have forgotten that this time  ::).

Posted

I checked again and the TESR is properly bound and the call even enters into the if statement. So there must be something off with my use of the tesselator.

Posted

You are using integer division everywhere (

12/16

), which will always be rounded down (12/16 = 0.75 = 0). To do proper division with decimals, use

floats

(12F/16F = 0.75F).

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

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.