Jump to content

[1.10.2] Render fluid level in tank with TESR


XFactHD

Recommended Posts

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.

Link to comment
Share on other sites

Two things, did you bind the TESR, and the next being did you let the client know that there is a fluid inside of it.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

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/

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.