Monday, 9 September 2013

Sample code for rendering items

Although I said I wasn't going to provide any code snippets or sample code, the Item rendering turned out to be so full of "special cases" I've changed my mind.

I have posted the test code I used onto GitHub.  It is located here.

The picture below shows the module structure, based around
  1. ItemSmileyFace, which is a very simple Item that uses iconRegister.registerIcon() and nothing more.
  2. BlockNumberedFaces1, a simple cube.  When placed in the world as a block it uses vanilla code, when visible as an item it uses IItemRenderer to do custom rendering as a 3D cube.
  3. ItemNumberedFaces2, the same cube as BlockNumberedFaces1 except it is an Item only, and it is rendered in 2D, the same as most vanilla items.
  4. ItemNumberedFaces3, the same cube as BlockNumberedFaces1, except it is an Item only.  Rendered in 3D using IItemRenderer.
  5. BlockPyramid, (Block and Item) - showing how to render custom shapes using ISimpleBlockRenderingHandler.
  6. ItemLampshade, an Item showing some unusual custom rendering using IItemRenderer.
Which one should you use?
  1. If you want your item to look similar to the vanilla minecraft items, use ItemSmileyFace
  2. If your item can also be placed in the world as a block, and you want the item to look similar to the block, use BlockPyramid or BlockNumberedFaces1.
  3. If you want your item to render in 2D similar to the vanilla minecraft items, perhaps with a bit of extra fancy stuff, look at ItemNumberedFaces2
  4. If your item should render as a 3D object, look at ItemNumberedFaces3 or ItemLampshade.


"Inventory" render of the test Items: from left to right: Pyramid, Lampshade, SmileyFace, NumberedFaces1, NumberedFaces2, NumberedFaces3
"Dropped" render of the test items.  ("Fancy Graphics" option on).
"Dropped" render of the test items in picture frames.


"Dropped" render of the two test Items which are also Blocks.

"First Person Equipped" render of the test items.







"Third person equipped" render of the test items.