• Forums

Navigation

  • Home
  • Style Guide
  • Getting Started
    • Home
    • Structuring Your Mod
    • Forge Update Checker
    • Debug Profiler
  • Concepts
    • Sides
    • Resources
    • Data
    • Registries
    • Mod Lifecycle
    • Internationalization and localization
  • Blocks
    • Home
    • Blockstates
    • Interaction
  • Animation API
    • Intro to the Animation API
    • Armatures
    • Animation State Machines
    • Using the API
  • Tile Entities
    • Home
    • Renderer
  • Items
    • Home
    • Loot Modification
  • Models
    • Intro to Models
    • Model Files
    • Blockstates
      • Intro to Blockstate JSONs
    • Coloring Textures
    • Item Property Overrides
    • Advanced Models
      • IBakedModel
      • Perspective
        • TransformType
        • The Vanilla Way
        • The Forge Way
      • ItemOverrideList
  • Rendering
    • ItemStackTileEntityRenderer
  • Data Generation
    • Introduction
    • Model Providers
  • Events
    • Basic Usage
  • Networking
    • Home
    • Overview
    • SimpleImpl
    • Entities
  • Data Storage
    • Capabilities
    • World Saved Data
  • Utilities
    • Recipes
    • Tags
  • Effects
    • Particles
    • Sounds
  • Conventions
    • Versioning
    • Locations
  • Advanced Topics
    • Access Transformers
  • Contributing to Forge
    • Getting Started
    • PR Guidelines
  • Legacy Versions
    • Home
    • Porting from 1.13/1.14 to 1.15

Perspective

When an 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 IBakedModel::getItemCameraTransforms, ItemCameraTranforms, and ItemTransformVec3f, and the Forge system, embodied by the method IBakedModel::handlePerspective. The vanilla code is patched to favor using handlePerspective over the vanilla system whenever possible.

TransformType

NONE - Unused.

THIRD_PERSON_LEFT_HAND/THIRD_PERSON_RIGHT_HAND/FIRST_PERSON_LEFT_HAND/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 EntityItem.

FIXED - Used for item frames.

The Vanilla Way

The vanilla way of handling perspective is through IBakedModel::getItemCameraTransforms. This method returns an ItemCameraTransforms, which is a simple object that contains various ItemTransformVec3fs as 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 TransformTypes, sans NONE. In the vanilla implementation, calling getTransform for NONE results in the default transform, ItemTransformVec3f.DEFAULT.

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 handlePerspective.

The Forge Way

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.

IBakedModel::handlePerspective

Given a TransformType and 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).

PerspectiveMapWrapper

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.

getTransforms and getTransformsWithFallback

Given an ItemCameraTransforms or an IModelTransform, this method will extract an ImmutableMap<TransformType, TransformationMatrix> from it. To extract this information from an IModelTransform, each TransformType is passed to getPartTransformation.

This is how models should support custom perspective transforms through IModelTransform. IUnbakedModels should use getTransforms in 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.

handlePerspective

Given either a map of transforms or an IModelTransform, an IBakedModel, a 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 IModelTransform, the TransformType is passed to getPartTransformation. This method is meant to be a simple implementation of IBakedModel::handlePerspective.

Built with MkDocs using a custom theme. Hosted by Read the Docs.
Enable Dark Theme