-
Notifications
You must be signed in to change notification settings - Fork 0
What is ModContext
ModContext is the central runtime context responsible for managing mod metadata and dependency injection pools within the Temporal API.
The main responsibility of ModContext is to:
- track the currently active mod
- maintain a per-mod
InjectionPool - provide a global access point for injected objects during engine execution
ModContext is a singleton that maps each loaded mod (NeoMod) to its corresponding InjectionPool.
Key responsibilities:
- creating injection pools
- resolving pools by
modId - removing pools during cleanup
- exposing the current mod context via static access
The active mod is stored in:
public static volatile NeoMod NEO_MOD;NeoMod is an immutable runtime representation of a NeoForge mod.
It encapsulates:
- mod name
- mod main class
- mod ID
- all discovered mod classes
A NeoMod instance is created using:
NeoMod.create(Class<?> clazz, List<ModClassScanner> scanners)During creation:
- the
@Modannotation is validated - the mod ID is extracted
- all registered
ModClassScanners are executed - discovered classes are collected and stored
This class acts as the authoritative metadata source for a mod.
InjectionPool is a per-mod object container for dependency injection, implementing ObjectPool.
It is responsible for:
- storing instantiated objects
- resolving objects by name, class, or
InjectionKey - caching lookups for performance
- supporting multiple objects of the same type
Each mod has exactly one InjectionPool, managed by ModContext.
Objects are stored internally as:
Map<InjectionKey, Object>Each object is indexed by:
- class
- optional string name
- cached lookup keys
You can retrieve objects using:
InjectionPool.getFromInstance(Class<T> clazz)
InjectionPool.getFromInstance(String name)Resolution rules:
- exact key match is preferred
- if missing, the first matching instance of the requested type is returned
-
nullis returned if no suitable object exists
Objects can be registered using:
pool.put(MyClass.class);
pool.put("customName", instance);
pool.put(instance);Object instantiation uses reflection:
ReflectionUtils.createObject(clazz);Objects can be removed by:
- class
- instance
- clearing the entire pool
All caches are kept in sync automatically.
InjectionKey uniquely identifies an object inside an InjectionPool.
It consists of:
- a string name
- a concrete class
Keys can be created using:
new InjectionKey(Class<?> clazz)
new InjectionKey(String name, Class<?> clazz)InjectionKeys are used internally and cached for fast resolution.
ModContext.createPool(modId)Rules:
- only one pool per mod is allowed
- creating a duplicate pool throws
PoolCreationException
ModContext.getPool(modId)If no pool exists, a PoolGettingException is thrown.
ModContext.removePool(modId)If the pool does not exist, a PoolDeletionException is thrown.
The active mod’s injection pool is accessed via:
InjectionPool.getInstance()This resolves:
- the current
ModContext - the active
NeoMod - the corresponding
InjectionPool
This pattern is used throughout Temporal API (e.g. factories, annotations).
-
ModContextandLayerContaineruse double-checked locking -
InjectionPooluses concurrent caches for key resolution - object storage itself is not synchronized and assumes controlled engine execution
Most users do not interact with ModContext directly.
Direct usage is only recommended when:
- writing custom engine layers
- implementing advanced injection logic
- debugging engine internals
🚀 Getting Started
🧩 Core Concepts
⚙️ Data Generation
- ⚙️ Advancement
- ⚙️ Damage Type
- ⚙️ Chest Loot Modifier
- ⚙️ Recipe
- ⚙️ Sound
- ⚙️ Jukebox Song
- ⚙️ Enchantment
- ⚙️ Trim Material
- ⚙️ Trim Pattern
- ⚙️ Banner Pattern
- ⚙️ Painting Variant
- ⚙️ Particle Sprite Set
- ⚙️ Wolf Variant
- ⚙️ Item Model
- ⚙️ Block Model
- ⚙️ Block Loot Table
- ⚙️ Tag
- ⚙️ Language Translation
- ⚙️ World Feature
- ⚙️ Custom Properties
🚨 Events
🛠 Engine Layers
🧪 Resources
- 🧪 Examples