Skip to content

Commit

Permalink
fix: Fix off-thread bootstrapping causing registry issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveplays28 committed Aug 9, 2024
1 parent 7211243 commit f5810f7
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package io.github.steveplays28.blinkload.mixin;

import io.github.steveplays28.blinkload.client.event.ClientLifecycleEvent;
import io.github.steveplays28.blinkload.util.ThreadUtil;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -12,7 +11,20 @@
@Mixin(Registry.class)
public interface RegistryMixin {
@Inject(method = "getOrThrow", at = @At(value = "HEAD"))
private void blinkload$waitForBootstrapInitializationToFinish(RegistryKey<?> key, @NotNull CallbackInfoReturnable<?> cir) {
private void blinkload$waitForBootstrapInitializationToFinishBeforeGetting(CallbackInfoReturnable<?> cir) {
if (Thread.currentThread().getName().contains(ThreadUtil.BOOTSTRAPPER_THREAD_POOL_NAME)) {
return;
}

ClientLifecycleEvent.BEFORE_BOOTSTRAP_FINISH_INITIALIZATION.invoker().onBeforeBootstrapFinishInitialization();
}

@Inject(method = {"register(Lnet/minecraft/registry/Registry;Lnet/minecraft/registry/RegistryKey;Ljava/lang/Object;)Ljava/lang/Object;", "register(Lnet/minecraft/registry/Registry;ILjava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;", "registerReference(Lnet/minecraft/registry/Registry;Lnet/minecraft/registry/RegistryKey;Ljava/lang/Object;)Lnet/minecraft/registry/entry/RegistryEntry$Reference;"}, at = @At(value = "HEAD"))
private static void blinkload$waitForBootstrapInitializationToFinishBeforeRegistering(CallbackInfoReturnable<?> cir) {
if (Thread.currentThread().getName().contains(ThreadUtil.BOOTSTRAPPER_THREAD_POOL_NAME)) {
return;
}

ClientLifecycleEvent.BEFORE_BOOTSTRAP_FINISH_INITIALIZATION.invoker().onBeforeBootstrapFinishInitialization();
}
}

0 comments on commit f5810f7

Please sign in to comment.