Avoid calling createCapabilities many times, mark mixin as client-only
This commit is contained in:
parent
fe8d0434c5
commit
8d766a8cc8
|
|
@ -8,12 +8,14 @@ import net.minecraftforge.fml.StartupMessageManager;
|
|||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.registries.GameData;
|
||||
import net.minecraftforge.registries.RegisterEvent;
|
||||
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
|
||||
import org.embeddedt.modernfix.forge.util.AsyncLoadingScreen;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(value = GameData.class, remap = false)
|
||||
@ClientOnlyMixin
|
||||
public class GameDataMixin {
|
||||
@Redirect(method = "postRegisterEvents", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/ModLoader;postEventWrapContainerInModOrder(Lnet/minecraftforge/eventbus/api/Event;)V"))
|
||||
private static <T extends Event & IModBusEvent> void swapThreadAndPost(ModLoader loader, T event) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package org.embeddedt.modernfix.forge.util;
|
|||
import net.minecraftforge.fml.loading.ImmediateWindowHandler;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.opengl.GLCapabilities;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
|
@ -14,9 +15,13 @@ public class AsyncLoadingScreen extends Thread implements AutoCloseable {
|
|||
|
||||
private static int splashThreadNum = 1;
|
||||
|
||||
private static GLCapabilities caps;
|
||||
|
||||
public AsyncLoadingScreen() {
|
||||
this.setName("ModernFix splash thread " + splashThreadNum++);
|
||||
this.theWindow = GLFW.glfwGetCurrentContext();
|
||||
if(caps == null)
|
||||
caps = GL.createCapabilities();
|
||||
if(this.theWindow == 0)
|
||||
throw new IllegalStateException("No context found but async loading screen was requested");
|
||||
this.keepRunning = new AtomicBoolean(true);
|
||||
|
|
@ -32,7 +37,7 @@ public class AsyncLoadingScreen extends Thread implements AutoCloseable {
|
|||
@Override
|
||||
public void run() {
|
||||
GLFW.glfwMakeContextCurrent(theWindow);
|
||||
GL.createCapabilities(); // seems to be needed, otherwise we get a "function not valid for context" error
|
||||
GL.setCapabilities(caps);
|
||||
while(keepRunning.get()) {
|
||||
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(50));
|
||||
ImmediateWindowHandler.renderTick();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user