Overview
BetterModel follows a clean, layered architecture that separates concerns and enables multi-platform support. The codebase is organized into four main layers: API, Core, Platform, and NMS.Module Structure
API Layer
API Layer
Location:
api/ and api/bukkit-api/The API layer defines contracts and interfaces without implementation details:- Pure interfaces and data classes
- No platform-specific dependencies
- Stable public API surface
- Published to Maven Central
kr.toxicity.model.api- Core API classeskr.toxicity.model.api.tracker- Tracker interfaceskr.toxicity.model.api.animation- Animation systemkr.toxicity.model.api.bone- Bone manipulationkr.toxicity.model.api.bukkit- Bukkit-specific adapters
Core Layer
Core Layer
Location:
core/ and core/bukkit-core/The core layer implements the API contracts:- Business logic and orchestration
- Model loading and parsing
- Animation processing
- Resource pack generation
- Platform-agnostic implementation
- BlockBench
.bbmodelfile parsing - Animation keyframe interpolation
- Packet bundling and optimization
- Resource management
Platform Layer
Platform Layer
Location:
platform/paper/, platform/spigot/, platform/fabric/Platform-specific implementations and integrations:- Server lifecycle management
- Plugin/mod loading
- Platform-specific optimizations
- Event system integration
- Paper - Modern async scheduler, optimized packet handling
- Spigot - Legacy scheduler compatibility
- Fabric - Mod loader integration, Polymer resource packs
NMS Layer
NMS Layer
Location:
nms/v1_21_R1/, nms/v1_21_R3/, etc.Version-specific Minecraft internals access:- Packet manipulation
- Entity spawning
- Display entity control
- Network protocol handling
Data Flow
Model Loading
Core layer reads
.bbmodel files from disk and parses the JSON structure into internal data models.Resource Generation
Core layer generates optimized resource pack with custom model data and textures.
Tracker Creation
API user creates a tracker through
ModelRenderer. Core layer instantiates the appropriate tracker type (Entity/Dummy).Rendering
NMS layer spawns item display entities and sends packets to connected players. Platform layer handles scheduling.
Design Principles
Separation of Concerns
Each layer has a single responsibility and doesn’t leak implementation details.
Dependency Direction
Dependencies flow one way: API ← Core ← Platform ← NMS
Platform Abstraction
Platform-specific code is isolated, allowing easy addition of new platforms.
Version Isolation
NMS version differences are contained in separate modules.
Key Components
BetterModelPlatform
The platform singleton provides access to all managers:Model Manager
Loads and manages model renderers:- Discovers
.bbmodelfiles inBetterModel/models/andBetterModel/players/ - Caches parsed models
- Provides lookup by name
- Handles hot-reloading
Tracker System
Manages model instances (see Trackers):- EntityTracker - Attached to entities, follows movement
- DummyTracker - Standalone at fixed locations
- EntityTrackerRegistry - Per-entity tracker collection
Render Pipeline
Orchestrates rendering for a single model instance:- Manages bone hierarchy
- Coordinates packet sending
- Handles player visibility
- Processes animations
Thread Safety
Async Operations
- Model loading and parsing
- Resource pack generation
- Profile resolution (player skins)
Sync Operations
- Tracker creation and modification
- Entity manipulation
- Player-specific operations
Folia Considerations
On Folia, operations are region-specific:Extension Points
Custom Render Sources
Custom Render Sources
Implement
RenderSource to create custom model sources beyond entities and locations.Animation Scripts
Animation Scripts
Use Molang expressions in animations for dynamic, data-driven behavior.
Custom Update Actions
Custom Update Actions
Implement
TrackerUpdateAction for custom display modifications.Event Handling
Event Handling
Subscribe to BetterModel events through
BetterModelEventBus for lifecycle hooks.Best Practices
For detailed architectural guidelines, see the AGENTS.md file in the repository.
See Also
Models & Renderers
Learn about the model loading system
Trackers
Understand tracker lifecycle and types
API Reference
Explore the complete API
