Fixes double-invoking of the client start event. (#1839)

This is due to vanilla now calling thread.setPriority (thus accessing the field twice).
This commit is contained in:
shartte 2021-11-17 18:01:22 +01:00 committed by GitHub
parent 3ac43d9577
commit c15ca33535
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View file

@ -47,7 +47,7 @@ public abstract class MinecraftClientMixin {
} }
// We inject after the thread field is set so `ThreadExecutor#getThread` will work // We inject after the thread field is set so `ThreadExecutor#getThread` will work
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;thread:Ljava/lang/Thread;", shift = At.Shift.AFTER), method = "run") @Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;thread:Ljava/lang/Thread;", shift = At.Shift.AFTER, ordinal = 0), method = "run")
private void onStart(CallbackInfo ci) { private void onStart(CallbackInfo ci) {
ClientLifecycleEvents.CLIENT_STARTED.invoker().onClientStarted((MinecraftClient) (Object) this); ClientLifecycleEvents.CLIENT_STARTED.invoker().onClientStarted((MinecraftClient) (Object) this);
} }

View file

@ -23,15 +23,28 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public final class ClientLifecycleTests implements ClientModInitializer { public final class ClientLifecycleTests implements ClientModInitializer {
private boolean startCalled;
private boolean stopCalled;
@Override @Override
public void onInitializeClient() { public void onInitializeClient() {
ClientLifecycleEvents.CLIENT_STARTED.register(client -> { ClientLifecycleEvents.CLIENT_STARTED.register(client -> {
if (startCalled) {
throw new IllegalStateException("Start was already called!");
}
startCalled = true;
client.submitAndJoin(() -> { // This should fail if the client thread was not bound yet. client.submitAndJoin(() -> { // This should fail if the client thread was not bound yet.
System.out.println("Started the client"); System.out.println("Started the client");
}); });
}); });
ClientLifecycleEvents.CLIENT_STOPPING.register(client -> { ClientLifecycleEvents.CLIENT_STOPPING.register(client -> {
if (stopCalled) {
throw new IllegalStateException("Stop was already called!");
}
stopCalled = true;
System.out.println("Client has started stopping!"); System.out.println("Client has started stopping!");
}); });
} }