Overview
TheModelRenderer is the entry point for spawning and managing model instances in BetterModel. It represents a loaded model definition (typically from a .bbmodel file) and provides methods to create trackers that render the model in the world.
Model Structure
AModelRenderer contains:
- Name - Unique identifier for the model
- Type - Either
GENERALorPLAYER - Renderer Groups - Hierarchical bone structure with display entities
- Animations - Named animation definitions
Renderer Types
- GENERAL
- PLAYER
General models can be attached to any entity or location. They support saving/serialization.
Loading Models
Models are automatically discovered from theBetterModel/models/ and BetterModel/players/ directories.
Model Discovery
Model names are derived from the
.bbmodel filename without the extension.Creating Trackers
TheModelRenderer provides multiple create() methods for spawning model instances.
Entity Trackers
Attach a model to an entity:src/main/java/com/example/EntityModelExample.java
Dummy Trackers
Spawn a standalone model at a location:src/main/java/com/example/DummyModelExample.java
Dummy trackers are stationary and don’t follow entities. Use them for environmental decorations, holograms, or stationary NPCs.
Get or Create Pattern
For entity trackers, you can retrieve existing trackers or create new ones:src/main/java/com/example/GetOrCreateExample.java
Working with Animations
Renderers provide access to their animation definitions:Renderer Groups
Renderer groups represent the bone hierarchy of the model:Tracker Modifiers
Customize tracker behavior withTrackerModifier:
src/main/java/com/example/ModifierExample.java
Modifier Options
int
default:"64"
Maximum distance in blocks from which players can see the model.
boolean
default:"false"
Whether to hide the model when the player’s line of sight is blocked.
boolean
default:"true"
Whether to smoothly interpolate entity movement.
Profile Support
For player models or custom textures, useModelProfile:
src/main/java/com/example/ProfileExample.java
Profiles handle player skins and custom textures asynchronously. The model will update automatically when the texture loads.
Best Practices
Cache ModelRenderer instances
Cache ModelRenderer instances
Retrieve renderers once and cache them. Don’t look up models on every tracker creation.
Always check for empty optionals
Always check for empty optionals
Model loading can fail. Always handle
Optional.empty() cases.Use getOrCreate for persistent entities
Use getOrCreate for persistent entities
For entities that may already have trackers, use
getOrCreate() to avoid duplicates.Clean up trackers properly
Clean up trackers properly
Always close trackers when they’re no longer needed.
Example: Complete Model Spawning
src/main/java/com/example/CompleteExample.java
See Also
Trackers
Learn about managing tracker lifecycle
Animations
Playing and controlling animations
Bones & Hitboxes
Working with individual bones
API Reference
Complete ModelRenderer API
