Jump to content

[1.7] Render custom block as item in inventory


Jhary

Recommended Posts

*sigh* Hi again !

 

As solved in this topic : http://www.minecraftforge.net/forum/index.php/topic,20137.0.html

my custom rendered block now does everything I want, but .. it does not render as an item in my hand or in my inventory.

I just get a flat not found texture (the black/purple thingy)

 

My ISimpleBlockRenderingHelper implementation hast got this method here that seems what I have to use:

 

@Override
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) {

}

 

But how do I use it correctly? There is a method from the RenderBlocks class called .renderBlockAsItem(Block block, int noclue, float noclue).

But just using this method and testing with the values did not change a single thing.

I even tried defining each IIcon to render on every side using the methods from the RenderBlocks class (.renderFace*) and then calling the .renderBlockAsItem

method but that didn't work either..

 

On http://greyminecraftcoder.blogspot.com.au/ there is an article about rendering custom blocks in inventories but I don't really get it this time.

For reference, here is my custom renderer implementation :

 

public class MyTileRenderer implements ISimpleBlockRenderingHandler{

  @Override
  public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) { 
  
  }

  @Override
   public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {

    	IIcon top = block.getIcon(world, x, y, z, 1);
    	IIcon bottom = block.getIcon(world, x, y, z, 0);
    	IIcon north = block.getIcon(world, x, y, z, 2);
    	IIcon south = block.getIcon(world, x, y, z, 3);
    	IIcon west = block.getIcon(world, x, y, z, 4);
    	IIcon east = block.getIcon(world, x, y, z, 5);
    	
    	renderer.renderFaceXNeg(block, x, y, z, west);
    	renderer.renderFaceXPos(block, x, y, z, east);
    	renderer.renderFaceYNeg(block, x, y, z, bottom);
    	renderer.renderFaceYPos(block, x, y, z, top);
    	renderer.renderFaceZNeg(block, x, y, z, north);
    	renderer.renderFaceZPos(block, x, y, z, south);
    	
    	TileEntity tile = world.getTileEntity(x, y, z);
    	if(tile instanceof TileEntityMyTile){
    		//wonky rendering incoming
    		switch(((TileEntityMyTile)tile).orientation.ordinal()){
    			case 0: //Bottom
    				renderer.uvRotateNorth=2; //west
    				renderer.uvRotateSouth=1; //east
    				renderer.uvRotateWest=2; //south
    				renderer.uvRotateEast=1; //north
    				break;
    			case 1: //Top
    				renderer.uvRotateNorth=1;
    				renderer.uvRotateSouth=2;
    				renderer.uvRotateWest=1;
    				renderer.uvRotateEast=2;
    				break;				
    			case 2: //North
    				renderer.uvRotateTop = 1;
    				renderer.uvRotateBottom = 2;
    				
    				break;
    			case 3: //South
    				renderer.uvRotateTop=2;
    				renderer.uvRotateBottom=1;
    				renderer.uvRotateNorth=3; 
    				renderer.flipTexture=true; //east
    				break;
    			case 4: //West
    				renderer.uvRotateTop=4;
    				renderer.uvRotateBottom=4;
    				break;
    			case 5: //East
    				renderer.uvRotateTop=3;
    				renderer.uvRotateBottom=3;
    				renderer.flipTexture=true;
    				break;
    		}
    	}
    	
    	boolean flag = renderer.renderStandardBlock(block, x, y, z);
    	//important reset afterwards!
    	renderer.flipTexture=false; 
    	renderer.uvRotateNorth=0; //west
renderer.uvRotateSouth=0; //east
renderer.uvRotateWest=0; //south
renderer.uvRotateEast=0; //north
renderer.uvRotateTop=0;
renderer.uvRotateBottom=0;
return flag;
  }

  @Override
   public int getRenderId() {
    	return ClientProxy.myTileRenderID;
   }

  @Override
  public boolean shouldRender3DInInventory(int modelId) {
return false;
  }

}

Link to comment
Share on other sites

Yeah its turned off, right. But if I turn it on, the only difference is that it is just invisible in my inventory/hand.

You are right, it should be set to true, but that does not solve the rendering because I still don't really know what to do in the

renderInventoryBlock(...) method of my ISimpleBlockRenderingHandler..

 

Here is what I tried:

 

   @Override
    public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) {
        IIcon top = renderer.getBlockIconFromSide(block, 1);
    	IIcon bottom = renderer.getBlockIconFromSide(block, 0);
    	IIcon north = renderer.getBlockIconFromSide(block, 2);
    	IIcon south = renderer.getBlockIconFromSide(block, 3);
    	IIcon west = renderer.getBlockIconFromSide(block, 4);
    	IIcon east = renderer.getBlockIconFromSide(block, 5);
    	
    	renderer.renderFaceXNeg(block, 0, 0, 0, west);
    	renderer.renderFaceXPos(block, 0, 0, 0, east);
    	renderer.renderFaceYNeg(block, 0, 0, 0, bottom);
    	renderer.renderFaceYPos(block, 0, 0, 0, top);
    	renderer.renderFaceZNeg(block, 0, 0, 0, north);
    	renderer.renderFaceZPos(block, 0, 0, 0, south);
    	
    }

 

renderer.renderFace* needs coordinates that I don't got here. And if I use

 

renderer.renderBlockAsItem(block, 3, 1.0F);

 

instead I just get a Stack Overflow Exception..

 

I am a bit clueless at the moment..

Link to comment
Share on other sites

Tessallator mate :) go to the forge wiki, and search it up. Specifically the one by hydroflame (there is only one part that is outdated. Instead of the texture binding he uses, use:

 minecraftInstance.getTextureManager().bindTexture(resourcelocation);

)

 

See if that works.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

Yeah its turned off, right. But if I turn it on, the only difference is that it is just invisible in my inventory/hand.

You are right, it should be set to true, but that does not solve the rendering because I still don't really know what to do in the

renderInventoryBlock(...) method of my ISimpleBlockRenderingHandler..

 

renderer.renderFace* needs coordinates that I don't got here. And if I use

 

renderer.renderBlockAsItem(block, 3, 1.0F);

 

instead I just get a Stack Overflow Exception..

 

I am a bit clueless at the moment..

 

Hi

 

For renderFace use the coordinates from [0,0,0] to [1,1,1] because the caller has already set those coordinates for you.  In 1.6.4 you needed to do an extra translate, that may have changed, but it will be obvious if so.

 

The vanilla code is in RenderBlocks.renderBlockAsItem(), so for example this code from 1.6.4

                    GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
                    tessellator.startDrawingQuads();
                    tessellator.setNormal(0.0F, -1.0F, 0.0F);
                    this.renderFaceYNeg(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 0));
                    tessellator.draw();
                    tessellator.startDrawingQuads();
                    tessellator.setNormal(0.0F, 1.0F, 0.0F);
                    this.renderFaceYPos(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 1));
                    tessellator.draw();
                    tessellator.startDrawingQuads();
                    tessellator.setNormal(0.0F, 0.0F, -1.0F);
                    this.renderFaceZNeg(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 2));
                    tessellator.draw();
                    tessellator.startDrawingQuads();
                    tessellator.setNormal(0.0F, 0.0F, 1.0F);
                    this.renderFaceZPos(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 3));
                    tessellator.draw();
                    tessellator.startDrawingQuads();
                    tessellator.setNormal(-1.0F, 0.0F, 0.0F);
                    this.renderFaceXNeg(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 4));
                    tessellator.draw();
                    tessellator.startDrawingQuads();
                    tessellator.setNormal(1.0F, 0.0F, 0.0F);
                    this.renderFaceXPos(par1Block, 0.0D, 0.0D, 0.0D, this.getBlockIconFromSide(par1Block, 5));
                    tessellator.draw();
                    GL11.glTranslatef(0.5F, 0.5F, 0.5F);

 

Don't call renderBlockAsItem, because that's what called your renderer in the first place.  i.e. you wind up in an infinite loop ("recursion") until the stack overflows.

 

-TGG

 

Link to comment
Share on other sites

This implementation seems to work. I got a 3D block now in my inventory :)

But.. no valid textures. Maybe the renderer.getBlockIconFromSide(..) seems to find no IIcon..strange.

 

renderer.getBlockIconFromSideAndMetadata(..) has no effect, too.

Link to comment
Share on other sites

No you get me wrong. The textures are fine. The block renders if placed correctly with all the textures. Just like I want it.

I just don't get it to work in my inventory / hand.

 

I just get a 3D block with the purple/black texture...

 

@Override
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) {

Tessellator tessellator = Tessellator.instance;

block.setBlockBoundsForItemRender();
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
        tessellator.startDrawingQuads();
        tessellator.setNormal(0.0F, -1.0F, 0.0F);
        renderer.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSide(block, 0));
        tessellator.draw();
        tessellator.startDrawingQuads();
        tessellator.setNormal(0.0F, 1.0F, 0.0F);
        renderer.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSide(block, 1));
        tessellator.draw();
        tessellator.startDrawingQuads();
        tessellator.setNormal(0.0F, 0.0F, -1.0F);
        renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSide(block, 2));
        tessellator.draw();
        tessellator.startDrawingQuads();
        tessellator.setNormal(0.0F, 0.0F, 1.0F);
        renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSide(block, 3));
        tessellator.draw();
        tessellator.startDrawingQuads();
        tessellator.setNormal(-1.0F, 0.0F, 0.0F);
        renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSide(block, 4));
        tessellator.draw();
        tessellator.startDrawingQuads();
        tessellator.setNormal(1.0F, 0.0F, 0.0F);
        renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSide(block, 5));
        tessellator.draw();
        GL11.glTranslatef(0.5F, 0.5F, 0.5F);
}

 

The error log shows not a single error..

Link to comment
Share on other sites

Yeah I already tried that, if I bin my textures beforehand like this :

 

Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("mymod:block_front"));

Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("mymod:block_top"));

Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("mymod:block_side"));

Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("mymod:block_back"));

 

But then the 3D block renders very dark and I cannot see if it is just black or my textures..

 

I tried to setup the lighting of my tessellator with tessellator.setBrightness(int) but I can't figure out how to get the brightness value.

 

block.getMixedBrightnessForBlock(...) needs a world and coordinates that I don't have in this method.

Link to comment
Share on other sites

Bind one texture at a time as you need it... Not all at once. (that is what I got from that)

 

Also, it's:

new ResourceLocation("modid", "textures/blocks/block_front.png")

 

That could well solve your problem.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

I did now bind one texture at a time as I needed it But.. nothing gets better. Probably it is more of a lighting problem and if I get that sorted out I see the textures.(Now its just dark .. perhaps the textures are therer but without lighting?)

 

But as I said above:

 

I tried to setup the lighting of my tessellator with tessellator.setBrightness(int) but I can't figure out how to get the brightness value.

 

block.getMixedBrightnessForBlock(...) needs a world and coordinates that I don't have in this method.

Link to comment
Share on other sites

You could always use GL11.glDisable(GL11.GL_LIGHTING); before your drawing and GL11.glEnable(GL11.GL_LIGHTING); after. This would help you figure out if your textures are there or not.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

hmm ok it was not the lighting. I get just a 3D block completely covered in dark grey. Not as in too dark, as in here:

 

http://www.directupload.net/file/d/3658/ondfi9un_png.htm

 

The texture binding seems to work correctly because if I remove the .png file extension for testing I get an exception on startup.

 

I disable the GL11 lighting at the beginning of my method and enable it again at the end. That is right? Or do I have to do that before and after every single

 

Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("modid","textures/blocks/filename.png"));
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, 1.0F);
renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSide(block, 3));
tessellator.draw();

 

code block?

(the parameters of the Resource Location constructor are different in my case)

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

    • Hello! My friends and I were attempting to add a few extra mods to the Create Chronicles modpack, and all was well until people started crashing when they opened their inventories. Any help finding the culprit would be MUCH appreciated, I've been scratching my head for the past few days on what went wrong. https://paste.ee/p/8pajP
    • >>>KLIK LOGIN DISINI SAYANG<<< >>>KLIK DAFTAR DISINI SAYANG<<< Pendahuluan Dalam dunia perjudian online, slot menjadi salah satu permainan yang paling diminati. Dengan munculnya berbagai platform, Togel2Win hadir sebagai salah satu pilihan menarik, terutama dengan fitur anti rungkad yang dijanjikan. Artikel ini akan membahas tentang Togel2Win, keunggulan slot terbaru, dan bagaimana server Thailand berperan dalam meningkatkan pengalaman bermain. Apa Itu Togel2Win? Togel2Win adalah platform permainan yang menawarkan berbagai jenis permainan, termasuk slot dan togel. Dengan antarmuka yang ramah pengguna dan beragam pilihan permainan, situs ini bertujuan untuk memberikan pengalaman bermain yang menyenangkan dan menguntungkan bagi para pemain. Keunggulan Slot Togel2Win Fitur Anti Rungkad: Salah satu keunggulan utama dari Togel2Win adalah fitur anti rungkad yang dirancang untuk mengurangi kemungkinan gangguan saat bermain. Ini memastikan bahwa pemain dapat menikmati permainan tanpa gangguan teknis, meningkatkan kenyamanan dan fokus. Beragam Pilihan Slot: Togel2Win menawarkan berbagai jenis slot, dari yang klasik hingga yang modern dengan grafis menawan dan tema yang menarik. Ini memberikan variasi yang cukup bagi pemain untuk menemukan permainan yang sesuai dengan preferensi mereka. Server Thailand yang Stabil: Server yang berlokasi di Thailand memberikan koneksi yang cepat dan stabil. Ini sangat penting untuk pengalaman bermain yang lancar, terutama saat bermain slot yang memerlukan respons cepat. Bonus dan Promosi Menarik: Togel2Win sering menawarkan bonus dan promosi yang menarik untuk menarik pemain baru dan mempertahankan loyalitas pemain yang sudah ada. Ini bisa berupa bonus deposit, putaran gratis, atau program loyalitas. Tips untuk Pemain Slot di Togel2Win Pilih Slot dengan RTP Tinggi: Sebelum memulai permainan, pastikan untuk memilih slot dengan tingkat pengembalian pemain (RTP) yang tinggi untuk meningkatkan peluang menang. Kelola Anggaran: Tentukan batasan anggaran sebelum bermain dan patuhi itu. Ini membantu mencegah kerugian besar dan menjaga pengalaman bermain tetap menyenangkan. Manfaatkan Bonus: Jangan ragu untuk memanfaatkan bonus dan promosi yang ditawarkan. Ini bisa memberikan tambahan modal untuk bermain lebih lama. Kesimpulan Togel2Win merupakan pilihan menarik bagi para penggemar slot, terutama dengan fitur anti rungkad dan server yang stabil. Dengan berbagai pilihan permainan dan bonus yang menggiurkan, Togel2Win siap memberikan pengalaman bermain yang tak terlupakan. Jika Anda mencari platform slot yang andal dan menyenangkan, Togel2Win bisa menjadi solusi yang tepat.
    • I'm trying to make my own modpack, but sometimes, in certain areas of the world, the game just says "server closed". Minecraft doesn't close, it just returns to the menu. When I tried to figure it out on my own and understand the logs, I didn't understand anything (English is not my native language, so it's difficult for me). I've been trying to solve the problem for the third month. So I ask if anyone is good at this and it's not difficult for you, to help me with this. If you need details, ask. I'll describe everything. What it looks like Logs
  • Topics

×
×
  • Create New...

Important Information

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