Jump to content

How do you render a block overlay?


timed

Recommended Posts

I need to find out how to render an overlay on a block, like the side of the grass block. I looked in the code (RenderBlocks) but there was just too many obfuscated variables, so that there was no easy way to read it.

Hoping that someone can help me.

Link to comment
Share on other sites

That is actually easy. I've been playing around with the renderers the other day and this is what I have come up with. First follow this short tutorial:

 

http://www.minecraftforge.net/wiki/Upgrading_To_Forge_for_1.3.1#Custom_Block_renders

 

In order to check if the block rendering handler has been setup correctly, put a System.out.println(); in renderWorldBlock(...) method. If the message pops out in your console after placing the block, you're on the good track.

 

Then you can actually try to render the block. Here's the sample:

http://paste.minecraftforge.net/view/5ed53601

 

The result:

 

4IvxL7p.png

 

All you have to do is to determine what side you want your overlay to be on. Correct the UV parameters so that you render one specific tile and coordinates if you want the overlay to be on the other side of the block, or simply to scale it. You name it.

 

@Reika, this green cage is even simpler to do. I haven't tried it, but I'm pretty sure you just have to call

 

GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glColor4f(0.0F, 1.0F, 0.0F, 0.4F);

 

... before using the Tessellator and

 

GL11.glEnable(GL11.GL_TEXTURE_2D);

 

after it. If that doesn't work, flush the Tessellator by calling t.draw(); t.startDrawingQuads(); after addVertex calls. Oh, and since you're not using textures, just use addVertex(x,y,z) method instead. Just play around with it.

 

Cheers

Link to comment
Share on other sites

Thank you! That really helped a lot :D! But I still have a couple of questions:

1. What is the last arg in block.shouldSideBeRendered(...) for each side?

2. What does the return value do?

3. If I want another texture, what do I do to bind it?

4. If I want just one tile of the texture, how do I do that?

5. Is it better to use TileEntitySpecialRenderer or ISimpleBlockRenderingHandler if I want the texture to change based on TileEntity, and how do I get the RenderBlocks then?

 

Again thank you very much for your answer!

Link to comment
Share on other sites

1. The side of the block you want to test against. This value ranges from 0 to 5, each meaning one of the six sides of the cube.

2. Nothin', pretty much.

3. Again, I didn't try it really, but that's what I'd do:

 

int nTex= Minecraft.getMinecraft().renderEngine.getTexture("/my_custom_texture.png");
GL11.glBindTexture(GL11.GL_TEXTURE_2D, nTex);

 

Use it with caution though. Hopefully it won't mess up the rendering process of any more blocks following it. Maybe there's a Minecraft method for binding a texture automatically?

 

4. Do you know what UV coordinates are? These coordinates determine what piece of a texture to use. (0,0) means down-left corner of a texture, while (1,1) means the opposite corner ( or top-left corner and down-right corner accordingly, I can't remember. Not that it's hard to sort out anyways ). Do the math :)

5. I didn't have opportunity to use TileEntities just yet. Remember though that you still have coordinates of your block so I don't see why not just call world.getBlockTileEntity(x, y, z) to get your tile entity and have it at hand.

Link to comment
Share on other sites

@diesieben07 - thanks for correcting me. Didn't know that actually and I guess I would never know :)

 

I've just run some tests with using a custom texture for our overlay, and as I suspected in my earlier post, binding another texture messed up the entire chunk. Here's the example using gui/items.png spritesheet:

 

HbvXjsM.png

 

Here's the corrected code snippet with additional measures when binding a new texture to prevent this from happening:

 

http://paste.minecraftforge.net/view/8d6e647f

 

The result:

 

cDtOW9W.png

 

Cheers!  ;)

Link to comment
Share on other sites

@Reika, this green cage is even simpler to do. I haven't tried it, but I'm pretty sure you just have to call

 

GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glColor4f(0.0F, 1.0F, 0.0F, 0.4F);

 

... before using the Tessellator and

 

GL11.glEnable(GL11.GL_TEXTURE_2D);

 

after it. If that doesn't work, flush the Tessellator by calling t.draw(); t.startDrawingQuads(); after addVertex calls. Oh, and since you're not using textures, just use addVertex(x,y,z) method instead. Just play around with it.

 

Cheers

 

I tried that before posting here, and the result was no render where I told it to be, and "rays" of corrupted rendering projecting from where I told it to render, corrupting every render in their path:

V7PdZ71.png

QkgLzzz.png

 

Also, I was plagued with crashes - the tessellator appears to have the following logic within it:

*call tess.startDrawing(GL.LINE_LOOP)*

*crash from "already tesellating!"*

and

*do not call start*

*add Vertex*

*crash from "not tesselating!"*

Link to comment
Share on other sites

You must be doing something terribly wrong. Changing colors of the vertices is supposed to mess up the position of other vertices of the blocks in the chunk.

 

About this 'tessellating' & 'not tessellating' errors. When renderWorldBlock(...) method is called, the Tessellator is already up and running - by default you just call 'Tessellator.addVertex(...)' and leave it as it is - then after all of the vertices are added to the buffer, the Tessellator is being flushed - the textures and vertices colors are all set to the last GL11 call that was setting them up, because they were "floating" in mid-air and were not affected by these GL11 changes at all. Once they all are flushed, the current GL11 setting are used.

 

That is why we're flushing it in this process. We want GL11 to be set differently to render it with different options. The draw() method flushes the Tessellator, while startDrawing() initialized it. When you leave the method renderWorldBlock(...) you MUST make sure the Tessellator is up and running ( so you either have not called draw() or startDrawing() methods, or the last one you called is startDrawing()). Also, once you enter the method renderWorldBlock(...), the Tessellator is up and running so calling startDrawing() to initialize it again results in a crash.

 

Show me your code, because there must be something wrong with it.

Link to comment
Share on other sites

  • 3 weeks later...

My render code is in my TileEntity file.

    	Tessellator var5 = Tessellator.instance;
    	var5.setColorOpaque(255, 0, 0);
    	var5.startDrawing(GL11.GL_LINE_LOOP);
    	var5.addVertex(x, y+1, z);
    	var5.addVertex(x+1, y+1, z);
    	var5.addVertex(x+1, y+1, z+1);
    	var5.addVertex(x, y+1, z+1);
    	var5.draw();

 

It crashes no matter what combination of start() and Draw() I have - both and only one (and either one).

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.