Baked Models
BakedModel
s are the in-code representation of a shape with textures. They can originate from multiple sources, for example from a call to UnbakedModel#bake
(default model loader) or IUnbakedGeometry#bake
(custom model loaders). Some block entity renderers also make use of baked models. There is no limit to how complex a model may be.
Models are stored in the ModelManager
, which can be accessed through Minecraft.getInstance().modelManager
. Then, you can call ModelManager#getModel
to get a certain model by its ResourceLocation
or ModelResourceLocation
. Mods will basically always reuse a model that was previously automatically loaded and baked.
Methods of BakedModel
getQuads
The most important method of a baked model is getQuads
. This method is responsible for returning a list of BakedQuad
s, which can then be sent to the GPU. A quad compares to a triangle in a modeling program (and in most other games), however due to Minecraft's general focus on squares, the developers elected to use quads (4 vertices) instead of triangles (3 vertices) for rendering in Minecraft. getQuads
has five parameters that can be used:
- A
BlockState
: The blockstate being rendered. May be null, indicating that an item is being rendered. - A
Direction
: The direction of the face being culled against. May be null, which means quads that cannot be occluded should be returned. - A
RandomSource
: A client-bound random source you can use for randomization. - A
ModelData
: The extra model data to use. This may contain additional data from the block entity needed for rendering. Supplied byBakedModel#getModelData
. - A
RenderType
: The render type to use for rendering the block. May be null, indicating that the quads for all render types used by this model should be returned. Otherwise, it is one of the render types returned byBakedModel#getRenderTypes
(see below).
Models should heavily cache. This is because even though chunks are only rebuilt when a block in them changes, the computations done in this method still need to be as fast as possible and should ideally be cached heavily due to the amount of times this method will be called per chunk section (up to seven times per RenderType used by a given model * amount of RenderTypes used by the respective model * 4096 blocks per chunk section). In addition, BERs or entity renderers may actually call this method several times per frame.