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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Slot depo 5k merupakan situs slot depo 5k yang menyediakan slot minimal deposit 5rb atau 5k via dana yang super gacor, dimana para pemain hanya butuh modal depo sebesar 5k untuk bisa bermain di link slot gacor thailand terbaru tahun 2024 yang gampang menang ini.   DAFTAR & LOGIN AKUN PRO SLOT DEPO 5K ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit 3000 adalah situs slot deposit 3000 via dana yang super gacor dimana para pemain dijamin garansi wd hari ini juga hanya dengan modal receh berupa deposit sebesar 3000 baik via dana, ovo, gopay maupun linkaja untuk para pemain pengguna e-wallet di seluruh Indonesia.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT 3000 ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • OLXTOTO: Menikmati Sensasi Bermain Togel dan Slot dengan Aman dan Mengasyikkan Dunia perjudian daring terus berkembang dengan cepat, dan salah satu situs yang telah menonjol dalam pasar adalah OLXTOTO. Sebagai platform resmi untuk permainan togel dan slot, OLXTOTO telah memenangkan kepercayaan banyak pemain dengan menyediakan pengalaman bermain yang aman, adil, dan mengasyikkan. DAFTAR OLXTOTO DISINI <a href="https://imgbb.com/"><img src="https://i.ibb.co/GnjSVpx/daftar1-480x480.webp" alt="daftar1-480x480" border="0" /></a> Keamanan Sebagai Prioritas Utama Salah satu aspek utama yang membuat OLXTOTO begitu menonjol adalah komitmennya terhadap keamanan pemain. Dengan menggunakan teknologi enkripsi terkini, situs ini memastikan bahwa semua informasi pribadi dan keuangan para pemain tetap aman dan terlindungi dari akses yang tidak sah. Beragam Permainan yang Menarik Di OLXTOTO, pemain dapat menemukan beragam permainan yang menarik untuk dinikmati. Mulai dari permainan klasik seperti togel hingga slot modern dengan fitur-fitur inovatif, ada sesuatu untuk setiap selera dan preferensi. Grafik yang memukau dan efek suara yang mengagumkan menambah keseruan setiap putaran. Peluang Menang yang Tinggi Salah satu hal yang paling menarik bagi para pemain adalah peluang menang yang tinggi yang ditawarkan oleh OLXTOTO. Dengan pembayaran yang adil dan peluang yang setara bagi semua pemain, setiap taruhan memberikan kesempatan nyata untuk memenangkan hadiah besar. Layanan Pelanggan yang Responsif Tim layanan pelanggan OLXTOTO siap membantu para pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Dengan layanan yang ramah dan responsif, pemain dapat yakin bahwa mereka akan mendapatkan bantuan yang mereka butuhkan dengan cepat dan efisien. Kesimpulan OLXTOTO telah membuktikan dirinya sebagai salah satu situs terbaik untuk penggemar togel dan slot online. Dengan fokus pada keamanan, beragam permainan yang menarik, peluang menang yang tinggi, dan layanan pelanggan yang luar biasa, tidak mengherankan bahwa situs ini telah menjadi pilihan utama bagi banyak pemain. Jadi, jika Anda mencari pengalaman bermain yang aman, adil, dan mengasyikkan, jangan ragu untuk bergabung dengan OLXTOTO hari ini dan rasakan sensasi kemenangan!
    • Slot deposit dana adalah situs slot deposit dana yang juga menerima dari e-wallet lain seperti deposit via dana, ovo, gopay & linkaja terlengkap saat ini, sehingga para pemain yang tidak memiliki rekening bank lokal bisa tetap bermain slot dan terbantu dengan adanya fitur tersebut.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit dana adalah situs slot deposit dana minimal 5000 yang dijamin garansi super gacor dan gampang menang, dimana para pemain yang tidak memiliki rekening bank lokal tetap dalam bermain slot dengan melakukan deposit dana serta e-wallet lainnya seperti ovo, gopay maupun linkaja lengkap. Agar para pecinta slot di seluruh Indonesia tetap dapat menikmati permainan tanpa halangan apapun khususnya metode deposit, dimana ketersediaan cara deposit saat ini yang lebih beragam tentunya sangat membantu para pecinta slot.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
  • Topics

×
×
  • Create New...

Important Information

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