Thursday, 12 March 2020

Minecraft Model Basics [1.14.4+]

The purpose of this post is to explain the basics of how Minecraft Models (eg PigModel) are constructed .

Models are built up of boxes.  Each box has a size and a texture.

The models used for Entities and some TileEntityRenderers can be a bit confusing, mostly because the model coordinate system is different to the world coordinate system.  The Z axis points from the "head" of the entity back towards its tail, and the X axis points from its right side towards its left side.

The mapping of the box’s texture follows the pattern below.  The Top and Side are all a simple “unwrapping” of the box sides; the Bottom has the same view as the Top, i.e. the pattern on the bottom that you would see if the top were transparent and you were looking down at the “inside” of the bottom.

 When rendering an Entity, Minecraft applies two transformations to convert the model from model coordinate space into world coordinate space:
1.       Flips the x axis and the y axis
2.       Translates the model up (by 24 model coordinates = 1.5 world blocks) to put its feet on the ground.
What does this mean for you?
If you are creating an Entity:
  •        The feet of the model will be at y = 24, not y = 0, unless you adjust it using setRotationPoint().

If you are rendering an Entity model from a TileEntityRenderer:
  •        You need to account for the transformations by performing

matrixStack.scale(-1, -1, 1);
model.preRenderCallback(entityIn, matrixStackIn, partialTicks);  // for LivingRender
matrixStack.translate(0.0, -1.501, 0.0);
before calling the model render.  See LivingRenderer::render
  •        Beware - any subsequent translations will be in model space not world space, i.e. if you translate with matrixStack.translate(0, 1, 0) then the model will be rendered closer to the ground (moved down, not up), because the y axis has been flipped.
A great tool for making minecraft models is BlockBench.  You can do it manually for simple models, but BlockBench makes it much easier and faster to get it right.

No comments:

Post a Comment