Skip to content

Commit

Permalink
Fix mixin conflict with Sodium 0.5 (Fixes #31)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Apr 29, 2024
1 parent d062f9f commit 4dbbf87
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
23 changes: 23 additions & 0 deletions common/src/main/java/cn/zbx1425/mtrsteamloco/mixin/GLFWMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cn.zbx1425.mtrsteamloco.mixin;

import cn.zbx1425.sowcer.ContextCapability;
import com.mojang.blaze3d.platform.Window;
import org.lwjgl.glfw.GLFW;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(GLFW.class)
public class GLFWMixin {

// Promote to a higher OpenGL version, as glVertexAttribDivisor is only available in OpenGL 3.3+

@Inject(method = "glfwCreateWindow(IILjava/lang/CharSequence;JJ)J", at = @At("HEAD"), cancellable = true, remap = false)
private static void glfwCreateWindow(int width, int height, CharSequence title, long monitor, long share, CallbackInfoReturnable<Long> cir) {
cir.setReturnValue(ContextCapability.createWindow(width, height, title, monitor, share));
}

}

This file was deleted.

12 changes: 11 additions & 1 deletion common/src/main/java/cn/zbx1425/sowcer/ContextCapability.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.opengl.GL33;
import org.lwjgl.system.MemoryStack;

import java.util.Locale;

Expand All @@ -21,7 +22,16 @@ public static long createWindow(int width, int height, CharSequence title, long
for (int versionToTry : new int[] {46, 45, 44, 43, 42, 41, 40, 33, 32}) {
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, versionToTry / 10);
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, versionToTry % 10);
window = GLFW.glfwCreateWindow(width, height, title, monitor, share);

MemoryStack stack = MemoryStack.stackGet(); int stackPointer = stack.getPointer();
try {
stack.nUTF8(title, true);
long titleEncoded = stack.getPointerAddress();
window = GLFW.nglfwCreateWindow(width, height, titleEncoded, monitor, share);
} finally {
stack.setPointer(stackPointer);
}

if (window != 0) {
contextVersion = versionToTry;
break;
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/resources/mtrsteamloco.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"TrainClientAccessor",
"TrainClientMixin",
"TrainClientRegistryMixin",
"WindowMixin"
"GLFWMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 4dbbf87

Please sign in to comment.