IBakedModel is being rendered as an item, it can apply special handling depending on which perspective it is being rendered in. “Perspective” means in what context the model is being rendered. The possible perspectives are represented in code by the
ItemCameraTransforms.TransformType enum. There are two systems for handling perspective: the deprecated vanilla system, constituted by
ItemTransformVec3f, and the Forge system, embodied by the method
IForgeBakedModel::handlePerspective. The vanilla code is patched to favor using
handlePerspective over the vanilla system whenever possible.
NONE - Unused.
FIRST_PERSON_RIGHT_HAND - The first person values represent when the player is holding the item in their own hand. The third person values represent when another player is holding the item and the client is looking at them in the 3rd person. Hands are self-explanatory.
HEAD - Represents when any player is wearing the item in the helmet slot (e.g. pumpkins).
GUI - Represents when the item is being rendered in a GUI.
GROUND - Represents when the item is being rendered in the world as an
FIXED - Used for item frames.
The vanilla way of handling perspective is through
IBakedModel::getItemCameraTransforms. This method returns an
ItemCameraTransforms, which is a simple object that contains various
public final fields. An
ItemTransformVec3f represents a rotation, a translation, and a scale to be applied to the model. The
ItemCameraTransforms is a container for these, holding one for each of the
NONE. In the vanilla implementation, calling
NONE results in the default transform,
The entire vanilla system for handling transforms is deprecated by Forge, and most implementations of
IBakedModel should simply
return ItemCameraTransforms.DEFAULT (which is the default implementation) from
IBakedModel::getItemCameraTransforms. Instead, they should implement
The Forge way of handling transforms is
handlePerspective, a method patched into
IBakedModel. It supersedes the
getItemCameraTransforms method. Additionally, the class
PerspectiveMapWrapper is a simple implementation of an
IBakedModel with the method; it is a wrapper around other
IBakedModels, augmenting them with a
Map<TransformType, TransformationMatrix> to handle perspective.
MatrixStack, this method produces an
IBakedModel to be rendered. Because the returned
IBakedModel can be a totally new model, this method is more flexible than the vanilla method (e.g. a piece of paper that looks flat in hand but crumpled on the ground).
A wrapper around other
IBakedModels, this class delegates to the wrapped model for all
IBakedModel methods except
handlePerspective, and utilizes a simple
Map<TransformType, TransformationMatrix> for
handlePerspective. However, the more interesting parts of this class are the static helper methods.
ItemCameraTransforms or an
IModelTransform, this method will extract an
ImmutableMap<TransformType, TransformationMatrix> from it. To extract this information from an
TransformType is passed to
This is how models should support custom perspective transforms through
IUnbakedModels should use
bakeModel and store the passed in perspective transforms in the
IBakedModel. Then the
IBakedModel can use these custom transforms in
handlePerspective, composing them on top of its own.
Given either a map of transforms or an
TransformType, and a
MatrixStack, this finds the
IBakedModel for the transform from the map or the
IModelTransform, and then pairs it with the given model. To extract the transform from an
TransformType is passed to
getPartTransformation. This method is meant to be a simple implementation of