Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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];
}

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.

  • Author

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 1296 combinations already, I can't use metadata.

You have access to the ItemBlock/ItemStack just make a new ItemBlock and register your block with it like so:

GameRegistry.registerBlock(myBlockInstance, MyItemBlock.class, "myBlockName");

 

EDIT: nvm

If I helped please press the Thank You button.

  • Author

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.

 

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

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.

  • Author

Thanks! I have fixed it using ItemRenderer.

 

 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.