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

Hello, 

I tried to port my TileEntityRenderer from 1.12.2 to 1.15.2, i've almost rewrited all.
Objectively, I want to render the fluid contained in the TileEntity

 

First, here is the RenderType 

public static RenderType getPedestalRenderType(ResourceLocation resourceLocation) {
        RenderType.State state = RenderType.State.getBuilder()
                .texture(new TextureState(resourceLocation, false, false))
                .cull(CULL_DISABLED)
                .lightmap(LIGHTMAP_DISABLED)
                .transparency(TRANSLUCENT_TRANSPARENCY)
                .build(true);

        return RenderType.makeType(SkillsStones.MOD_ID + ":pedestal_fluid", DefaultVertexFormats.POSITION_COLOR_TEX, GL11.GL_QUADS, 256, true, false, state);
}

 

And here is the TileEntityRenderer

    private static final float MIN_HEIGHT = 0.5625f;
    private static final float MAX_HEIGHT = 0.78125f;

    @Override
    public void render(TileEntityNaturalTotemPedestal tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {
        Minecraft.getInstance().getProfiler().startSection("pedestalFluidRenderer");

        float level = ((float) tileEntityIn.getFluidTank().getFluidAmount()) / (float) tileEntityIn.getFluidTank().getCapacity();
        if(!(level > 0)) return;

        Fluid fluid = tileEntityIn.getFluidTank().getFluid().getFluid();

        ResourceLocation resourceLocation;
        int color;
        if(fluid.getAttributes().getStillTexture() != null) {
            resourceLocation = fluid.getAttributes().getStillTexture();
            color = getFluidColor(tileEntityIn.getWorld(), tileEntityIn.getPos(), fluid);
        } else if(fluid.getAttributes().getFlowingTexture() != null) {  // In case that Still Texture don't exist
            resourceLocation = fluid.getAttributes().getFlowingTexture();
            color = getFluidColor(tileEntityIn.getWorld(), tileEntityIn.getPos(), fluid);
        } else { // In case that no texture exist
            resourceLocation = Fluids.WATER.getAttributes().getStillTexture();
            color = getFluidColor(tileEntityIn.getWorld(), tileEntityIn.getPos(), Fluids.WATER);
        }

        TextureAtlasSprite textureAtlasSprite = Minecraft.getInstance().getAtlasSpriteGetter(PlayerContainer.LOCATION_BLOCKS_TEXTURE).apply(resourceLocation);

        float uMin = textureAtlasSprite.getMinU();
        float uMax = textureAtlasSprite.getMaxU();
        float vMin = textureAtlasSprite.getMinV();
        float vMax = textureAtlasSprite.getMaxV();

        float a = 1.0F;
        float r = (color >> 16 & 0xFF) / 255.0F;
        float g = (color >> 8 & 0xFF) / 255.0F;
        float b = (color & 0xFF) / 255.0F;

        Matrix4f matrix4f = matrixStackIn.getLast().getMatrix();

        float y = MIN_HEIGHT + (level) * (MAX_HEIGHT - MIN_HEIGHT);

        matrixStackIn.translate(0, y, 0);

        IVertexBuilder buffer = bufferIn.getBuffer(SSRenderType.getPedestalRenderType(resourceLocation));

        buffer.pos(matrix4f, 0, 0, 0).color(r, g, b, a).tex(uMin, vMin).endVertex();
        buffer.pos(matrix4f, 0, 0, 1).color(r, g, b, a).tex(uMin, vMax).endVertex();
        buffer.pos(matrix4f, 1, 0, 1).color(r, g, b, a).tex(uMax, vMax).endVertex();
        buffer.pos(matrix4f, 1, 0, 0).color(r, g, b, a).tex(uMax, vMin).endVertex();

        Minecraft.getInstance().getProfiler().endSection();
    }

    private static int getFluidColor(World world, BlockPos pos, Fluid fluid) {
        if(fluid.isEquivalentTo(Fluids.WATER)) {
            return BiomeColors.getWaterColor(world, pos);
        }

        return fluid.getAttributes().getColor();
    }

 

In this case, i've an error that tell me that texture doesn't exists (with an Java IO FileNotFound Exception)

 

When i hardcode the ResourceLocation value to "minecraft:textures/block/water_still.png"

It's working but the texture look weird (also, i've a weird smooth effect)

spacer.png

 

I don't know how I can properly render my fluid.

 

(Sorry for approximative English)
Thanks a lot.

Edited by Zeide
Solved

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.