Jump to content

Custom Fluid Rendering Incorrectly


iward1

Recommended Posts

I have created a custom fluid using forge (several actually) and I have been unable to figure out how to get the back sides of the fluid blocks to render. It looks fine from the outside but when I am standing in the fluid I can't see the sides. I have tried using the shouldSideBeRendered method and this changed all but the sides I am having trouble with.

Does anyone have any idea what could be causing this/how to fix it?

Link to comment
Share on other sites

I've been having the same issue. Just for fun, I switched my fluid block to extend from Vanilla's BlockLiquid rather than BlockFluidClassic, and to my great surprise, it fixed this rendering issue.

 

There's a method in net.minecraft.Block, getRenderType that returns an integer value based on the rendering type that Minecraft should use to render the block. In BlockFluidClassic's superclass, BlockFluidBase, this method is overridden to return a value from the Fluid Registry, renderIDFluid. The value defaults to -1. I don't see anywhere this value can otherwise be set (since there's no registerFluid method that sets this value for the fluid anywhere I can find), but this makes Minecraft not render the interior faces of the fluid block.

 

By overriding this method in my fluid block implementation to return 4 (which is what Vanilla's BlockLiquid class does), I managed to fix the rendering issue, and now the interior faces of the fluid block display properly and with the correct texture.

 

If a veteran knows the "correct" way of setting the Fluid's renderIDFluid value for mod fluids, please step in!

 

IMPORTANT: This will cause a crash if your fluid's Material is anything other than Material.water.

 

EDIT: I just looked again and noticed that renderIdFluid is a static value, so obviously cannot itself be changed per fluid block. Looks like overriding getRenderType is the way to go, but doesn't seem to work for custom fluid materials.

Link to comment
Share on other sites

It actually worked even with a material other than water.

 

Ah... really? Hmm! There must be a bug in my code, then. Now's your chance to help me out! How are you setting up your custom Materials? Whenever I pass a Material that isn't Material.water or Material.lava to my fluid block constructor, it causes an NPE when my fluid is rendered, in getFlowDirection. I think this is because getRenderType (4) calls BlockLiquid's getFlowDirection method in order to render, which is expecting those:

 

public static double getFlowDirection(IBlockAccess p_149802_0_, int p_149802_1_, int p_149802_2_, int p_149802_3_, Material p_149802_4_)
    {
        Vec3 vec3 = null;

        if (p_149802_4_ == Material.water)
        {
            vec3 = Blocks.flowing_water.getFlowVector(p_149802_0_, p_149802_1_, p_149802_2_, p_149802_3_);
        }

        if (p_149802_4_ == Material.lava)
        {
            vec3 = Blocks.flowing_lava.getFlowVector(p_149802_0_, p_149802_1_, p_149802_2_, p_149802_3_);
        }

        return vec3.xCoord == 0.0D && vec3.zCoord == 0.0D ? -1000.0D : Math.atan2(vec3.zCoord, vec3.xCoord) - (Math.PI / 2D);
    }

 

So if the material isn't water or lava, Vec3 is null and so the block can't render, then crash and sadness.

 

My material is set up like so:

 

public static MaterialLiquid chemical = new MaterialLiquid(MapColor.grayColor);

 

And simply inserted into my liquid block implementation's constructor. But I don't the material declaration is the issue, considering the above getFlowDirection code...

Link to comment
Share on other sites

Ahh, gotcha. No worries.

 

I'm going to continue to look into this, since the more I think about it, the more I believe that setting the render type is the "improper" way to go about this. I'm thinking there must be some difference between Forge's RenderBlockFluid and Vanilla's RenderBlocks.renderBlockLiquid that is causing our mutual difficulty.

 

Examining RenderBlocks.renderBlockLiquid will probably yield the answer, as that is what's called by getRenderType returning 4. The method is not pretty, though...

 

EDIT: Eureka! I have discovered the difference. I have learned that Forge's RenderBlockFluid class is just a copy pasta of Vanilla's renderBlockLiquid with cleaned up method and variable names, save for the following:

 

  • Forge's RenderBlockFluid checks a boolean value called "rises" which itself is based on whether the relevant fluid's density is greater than zero before rendering certain block faces.
  • Vanilla's renderer simply calls the tessellator indiscriminately.

 

I suppose the reason why it's set up this way is because KingLemming wanted to set up some kind of convention for liquids versus gases and so the rendering code is checking what the fluid's density is. I kind of see what KingLemming was going for here: if the fluid has zero or lesser density, it therefore "floats like a gas" and should be rendered such a way, and if the fluid does not float, don't bother rendering interior faces. Perhaps there is some wisdom here I am not seeing because I don't know that this implementation makes the most sense. A fluid set up to be within what the implementation considers "liquid density" will not render interior the interior faces when the player is submerged unless the fluid is considered to be "rising".

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.