Friday, 23 August 2013

Rendering Third-Person-View Items

Rendering items in third person view is very similar to first person view.  The entry point is RenderPlayer.renderPlayer(), which calls RenderPlayer.renderSpecials().  After performing a number of translations depending on the item type and what actions the player is performing, it calls ItemRenderer.renderItem() as described for First Person View rendering.

The item renders as a 3D block:
  • if it's a block and RenderBlocks.renderItemIn3d returns true
  • if it checks MinecraftForgeClient.getItemRenderer(EQUIPPED) to see if there is a custom renderer for this item, and if so, checks customRenderer.shouldUseRenderHelper(EQUIPPED, BLOCK_3D) 
One other point of interest:
  • If  the item is 2D and Item.isFull3D() returns true, the item rotates so it lies in the plane of the player's arm, and also makes it a bit bigger.  Otherwise it lies in a plane normal to the arm.  See picture below.  Vanilla items which return .isFull3D() are eg tools, swords, fishing rod.
Item.isFull3D() affects the orientation of 2D items:
pickaxe.isFull3D() == true: icon is drawn in a plane parallel to his arm
potion.isFull3D() == false: icon is drawn in a plane normal to his arm