diff options
Diffstat (limited to 'src/main/kotlin/events/FinalizeResourceManagerEvent.kt')
-rw-r--r-- | src/main/kotlin/events/FinalizeResourceManagerEvent.kt | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/main/kotlin/events/FinalizeResourceManagerEvent.kt b/src/main/kotlin/events/FinalizeResourceManagerEvent.kt index c43ad3b..0d411f1 100644 --- a/src/main/kotlin/events/FinalizeResourceManagerEvent.kt +++ b/src/main/kotlin/events/FinalizeResourceManagerEvent.kt @@ -1,10 +1,35 @@ - package moe.nea.firmament.events +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor import net.minecraft.resource.ReloadableResourceManagerImpl +import net.minecraft.resource.ResourceManager +import net.minecraft.resource.ResourceReloader +import net.minecraft.util.profiler.Profiler data class FinalizeResourceManagerEvent( val resourceManager: ReloadableResourceManagerImpl, ) : FirmamentEvent() { companion object : FirmamentEventBus<FinalizeResourceManagerEvent>() + + inline fun registerOnApply(name: String, crossinline function: () -> Unit) { + resourceManager.registerReloader(object : ResourceReloader { + override fun reload( + synchronizer: ResourceReloader.Synchronizer, + manager: ResourceManager?, + prepareProfiler: Profiler?, + applyProfiler: Profiler?, + prepareExecutor: Executor?, + applyExecutor: Executor + ): CompletableFuture<Void> { + return CompletableFuture.completedFuture(Unit) + .thenCompose(synchronizer::whenPrepared) + .thenAcceptAsync({ function() }, applyExecutor) + } + + override fun getName(): String { + return name + } + }) + } } |