Saturday 20 July 2013

Rendering Standard Blocks (cubes)

When minecraft needs to draw a standard cube block, it starts with a call to RenderBlocks.renderStandardBlock(myBlock), where myBlock is the Block that it wants to draw.

It then renders each of the six faces in turn, after asking myBlock to supply the Icon corresponding to each face. The faces are numbered from 0 to 5 – see net.minecraft.util.Facing.


The coordinate system used by Minecraft is shown below, where each block is a 1x1x1 cube.

If you program myBlock.getIcon to return the six Icon textures below corresponding to the six directions (Show me how?), it renders the cube shown below (red block points north and the blue block points east).


Points to note:
  • The side faces always render with the same orientation as the Icon Texture.
  • The top face (up, YPos) points north- if you are facing north and looking down, the face will have the same orientation as the Icon texture.
  • The bottom face points north (the same as the top face), but is flipped left-right. 
  • RenderBlocks actually calls Block.getBlockTexture(World, x, y, z, side) before it calls Block.getIcon.  If you want to change your block's textures depending on where it is or what other blocks are nearby (for example - make it turn green if a flower is planted on top of it), then override getBlockTexture instead of getIcon.