-
Notifications
You must be signed in to change notification settings - Fork 0
Finalization Layer
Maksym Uimanov edited this page Jan 30, 2026
·
2 revisions
The Finalization Layer is the cleanup and teardown phase of the TemporalEngine.
Its main goal is to:
- Release resources allocated during previous layers
- Clear object pools
- Ensure no leftover state persists between mod reloads or engine runs
It operates after all initialization, registration, metadata, configuration, and event handling are complete.
The Finalization Layer:
- Invokes all registered
ObjectPoolCleanerinstances - Cleans both default and dynamic object pools
- Guarantees that the system is left in a stable and clean state
This prevents memory leaks, dangling references, and inconsistent object states.
public class FinalizationLayer implements EngineLayer@Override
public void processAllTasks()Step-by-step:
- Run default ObjectPoolCleaners:
objectPoolCleaners.forEach(ObjectPoolCleaner::clear);- Access the dynamic object pool:
ObjectPool objectPool = InjectionPool.getInstance();- Run all dynamic cleaners registered in the pool:
objectPool.getAll(ObjectPoolCleaner.class)
.forEach(ObjectPoolCleaner::clear);All cleanup logic is centralized here, ensuring predictable finalization.
public class FinalizationLayerBuilderThe builder:
- Attaches the
FinalizationLayerto the engine - Sets up default or custom cleaners
- Processes the layer immediately via
.and()
this.engineBuilder.processLayer(this.finalizationLayer);This guarantees that all resources are cleared once the engine is done.
private static final List<ObjectPoolCleaner> DEFAULT_CLEANERS = List.of();- Empty by default
- Can be extended by mods to clear specific pools or objects
Custom cleanup tasks are implemented via the ObjectPoolCleaner functional interface:
@FunctionalInterface
public interface ObjectPoolCleaner {
void clear();
}Example:
ObjectPoolCleaner cacheCleaner = () -> someCache.clear();
ObjectPoolCleaner dbCleaner = () -> databaseConnectionPool.closeAll();These can be passed to the builder:
new FinalizationLayerBuilder(engineBuilder)
.cleaners(List.of(cacheCleaner, dbCleaner))
.and();The Finalization Layer:
- Runs after Initialization, Registry, Metadata, Config, and Event layers
- Clears default and dynamic object pools
- Uses
ObjectPoolCleanerinterface to define cleanup logic - Ensures consistent and leak-free runtime behavior
🚀 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