Jump to content

Up to date Block overlay tutorial?


CJCutrone9

Recommended Posts

Hey everyone, I've been looking around, and I couldn't find a tutorial for rendering the overlay on a block that worked for 1.7.2. I thought that maybe I could look in Mojang's code for this, but I couldn't find the specialRenderer for the grass block (which is what I assume they are using for rendering the side of the grass block). If anyone could point me to either of the two (I'd prefer the grass block so I could figure it out myself) that would be great. Thanks!

Link to comment
Share on other sites

Cool! Thanks! :)

 

EDIT:

 

Okay, so I did some looking around, and figured I could just render the two textures, with one on top of the other. Only problem is, sometimes texture A like to get rendered before texture B. Is there a way to make sure that texture A get rendered before texture B and not the other way around? Here is the code I am using to render the block right now.

 

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
	renderer.renderFaceYPos(block, x,y,z, block.getIcon(1, world.getBlockMetadata(x, y, z)));

	renderer.renderFaceYPos(block, x,y,z, block.getIcon(world, x,y,z, 1));

	return true;
}

 

I am using an ISimpleBlockRenderingHandler, so this method is getting called. I just need it (as mentioned before) to render some textures before others. Sometimes it does, other times it doesn't.

 

Thanks!

Link to comment
Share on other sites

Okay, so I found a slightly cheaty solution:

 

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
                        Tessellator.instance.setColorOpaque_F(1F,1F,1F);
		Tessellator.instance.addTranslation(0F, .01F, 0F);
		renderer.renderFaceYPos(block, x,y,z, block.getIcon(world, x,y,z, 1));

		Tessellator.instance.addTranslation(0F, -.01F, 0F);
		renderer.renderFaceYPos(block, x, y, z, DummyBlockScrolls.getUnderlayer());

	return true;
}

 

Essentially, you put one texture slightly over another. Works decent. But now I have another question (still related to this). I want to make the underlayer glow, but not the over layer. How would I stop the over layer from glowing? I know I can make them both glow by using:

 

Tessellator.instance.setBrightness(brightness);

 

If I set it at zero both texture become black, if I set it to say 200, both have the appearance of glowing. How would I get the top layer to be normal and the bottom  layer to have that code added to it? I thought maybe a switch statement might work, but I couldn't figure out what to switch between...

Link to comment
Share on other sites

Okay, so I found a slightly cheaty solution:

 

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
                        Tessellator.instance.setColorOpaque_F(1F,1F,1F);
		Tessellator.instance.addTranslation(0F, .01F, 0F);
		renderer.renderFaceYPos(block, x,y,z, block.getIcon(world, x,y,z, 1));

		Tessellator.instance.addTranslation(0F, -.01F, 0F);
		renderer.renderFaceYPos(block, x, y, z, DummyBlockScrolls.getUnderlayer());

	return true;
}

 

Essentially, you put one texture slightly over another. Works decent. But now I have another question (still related to this). I want to make the underlayer glow, but not the over layer. How would I stop the over layer from glowing? I know I can make them both glow by using:

 

Tessellator.instance.setBrightness(brightness);

 

If I set it at zero both texture become black, if I set it to say 200, both have the appearance of glowing. How would I get the top layer to be normal and the bottom  layer to have that code added to it? I thought maybe a switch statement might work, but I couldn't figure out what to switch between...

 

Like this:

https://github.com/SanAndreasP/SAPManagerPack/blob/master/java/sanandreasp/core/manpack/helpers/client/RenderBlockGlowOverlay.java#L106-L126

 

Basically I render the block (which is not glowing), set the brightness to 240 (max brightness), then rendered the glowing texture and last but not least reset the brightness.

In your case it's vice versa (set brightness, render glowy texture, reset brightness, render standard block)

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

It... Works... Kind of.... It is rendering the layers funny. The two textures are also fighting for control over who gets top layer. Did I do something wrong?

 

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {	
        DummyBlockScrolls dummy = (DummyBlockScrolls)block;
        renderer.renderStandardBlockWithColorMultiplier(block, x, y, z, 1F, 1F, 1F);
        
        if( block instanceof DummyBlockScrolls ) {
        	
	    Tessellator.instance.setBrightness(240);
	    Tessellator.instance.setColorOpaque(255, 255, 255);

	    renderer.renderFaceYNeg(block, x, y, z, dummy.getUnderlayer());
	    renderer.renderFaceYPos(block, x, y, z, dummy.getUnderlayer());
	    renderer.renderFaceZNeg(block, x, y, z, dummy.getUnderlayer());
	    renderer.renderFaceZPos(block, x, y, z, dummy.getUnderlayer());
	    renderer.renderFaceXNeg(block, x, y, z, dummy.getUnderlayer());
	    renderer.renderFaceXPos(block, x, y, z, dummy.getUnderlayer());


	    Tessellator.instance.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
        }
        return true;


}

Link to comment
Share on other sites

That's a typical example of z-fighting. If you have two textures that render in the same exact plane, the graphics engine renders them as fighting for dominance and can cause weird effects. If I were doing this, I'd render them in parallel planes but with a small distance between them.

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.