Jump to content

[SOLVED] Rendering BlockItem in inventory


wnx

Recommended Posts

Hi, I have a problem, I have a block and I am storing data about side texture at TileEntity, when Block is in inventory texture data are stored in NBT data of ItemBlock. When block is placed in the world, everything works fine, but I can't figure out how to get rendering at inventory/hand working, I know that i can use public IIcon getIcon(int side, int meta) in block, but I don't have acess to ItemStack/ItemBlock, so I can't get data from NBT. I tryed a couple of methods in ItemBlock like public IIcon getIcon(ItemStack stack, int pass) but it also did not work ...

 

Thanks for any help!

 

getIcon of my Block (this works)

public IIcon getIcon(IBlockAccess blockAcess, int x, int y, int z, int side) {
	TileEntityMW te = (TileEntityMW) blockAcess.getTileEntity(x, y, z);
	if(te != null){
		return sideTextures[te.getSideTexture(side)];
	} else {
		return null;
	}
}

 

I can use this or blockIcon to set Icon of block, this works in inventory/hand but I can't get data from TileEntity/ItemStack

@Override
public IIcon getIcon(int side, int meta) {
	return sideTexture[0];
}

Link to comment
Share on other sites

An item in hand or inventory is actually an ItemStack. You can code the block's drop method to give the dropped stack a "damage" value, and from damage you can choose a texture.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

I allready have custom ItemBlock for my Block, I am using it to display tooltip that shows IDs of texture on sides (from NBT) of my Block.

I have tryed to @Override getIcon, but doesn't work for me.

 

Link to comment
Share on other sites

Hi

 

I suggest you look at using IItemRenderer.  The renderer is given the ItemStack when rendering, and has access to the NBT information

 

See here for some background info

http://greyminecraftcoder.blogspot.com.au/2013/08/rendering-items.html

http://greyminecraftcoder.blogspot.com.au/2013/09/custom-item-rendering-using.html

http://greyminecraftcoder.blogspot.com.au/2013/09/sample-code-for-rendering-items.html  (1.6.4 but the code is very similar)

 

-TGG

Link to comment
Share on other sites

But that limits my options to 16 states.

I have 4 types of texture, that can be on any side in any combination. That is about 96 combinations already, I can't use metadata.

Pretty sure the max damage for an item is closer to 32,767 and not 16.

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.