Jump to content

anyone know how the vanilla grass block works?


robustus

Recommended Posts

Hi, I've had no problem creating a "grass" block, the only thing I haven't been able to find is how the vanilla grass block works in respect to the coloring of the grass.  Grass is unique that only the side texture top portion is colored, and the grass color is not applied to the dirt texture underneath.  I've copied the vanilla grass block code but when the grass is colored, it tints the side dirt texture as well, which is the kink im trying to iron out here.  Right now I've just set the side texture to the top grass block, but I'd love to be able to have the side of my grass blocks have the dirt underneath like the Vanilla one.  Anyone have a clue about this? 

 

Just to clarify I am not asking how to get a different texture to appear on the side of the block, merely just how the grass manages to only color the top portion of the block and not the dirt section of that texture

Link to comment
Share on other sites

It'll be in RenderBlocks somewhere. Stock up on aspirin before looking in there though, as it's a tremendously tedious and obscure piece of code...

 

There are two different branches to the rendering code, depending on whether ambient occlusion is enabled (I think this is the "Fancy Lighting" option in the video settings). In renderStandardBlockWithAmbientOcclusion() there are passages of code like this:

 

            this.colorRedTopLeft = this.colorRedBottomLeft = this.colorRedBottomRight = this.colorRedTopRight = (var17 ? par5 : 1.0F) * 0.6F;

            // a bunch more colour-setting code here

            this.renderNorthFace(par1Block, (double)par2, (double)par3, (double)par4, var27);

 

            if (Tessellator.instance.defaultTexture && fancyGrass && var27 == 3 && this.overrideBlockTexture < 0)

            {

                this.colorRedTopLeft *= par5;

                // a bunch more colour-setting code here

                this.renderNorthFace(par1Block, (double)par2, (double)par3, (double)par4, 38);

            }

 

which is what appears to be rendering the face a second time with different lighting when a grass block is being rendered (id == 3).

 

The other branch is in renderStandardBlockWithColorMultiplier():

 

            var8.setBrightness(this.customMinZ > 0.0D ? var26 : par1Block.getMixedBrightnessForBlock(this.blockAccess, par2, par3, par4 - 1));

            var8.setColorOpaque_F(var18, var21, var24);

            var28 = par1Block.getBlockTexture(this.blockAccess, par2, par3, par4, 2);

            this.renderEastFace(par1Block, (double)par2, (double)par3, (double)par4, var28);

 

            if (Tessellator.instance.defaultTexture && fancyGrass && var28 == 3 && this.overrideBlockTexture < 0)

            {

                var8.setColorOpaque_F(var18 * par5, var21 * par6, var24 * par7);

                this.renderEastFace(par1Block, (double)par2, (double)par3, (double)par4, 38);

            }

 

Since all this is hard-coded to recognise the block id of vanilla grass, even if you copy all of the code in BlockGrass into your block class, it won't render the same way.

 

Where to go from here depends on how much you want to customise the appearance of your block. If you want it to look exactly like a vanilla grass block, I think you should be able to get that by installing a custom block renderer that calls renderBlockByRenderType() and passes it the vanilla grass block object instead of your own block.

 

If you want to customise your block more than that, you may need to figure out what that code is doing with the lighting and do something similar in your own block renderer.

 

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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.