Skip to content

Commit

Permalink
attempt to fix forge (i hate mixins)
Browse files Browse the repository at this point in the history
  • Loading branch information
not-coded committed Nov 2, 2024
1 parent a3c8526 commit 9fd4c88
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
`kotlin-dsl`
kotlin("jvm") version "2.0.20"
kotlin("jvm") version "1.9.24"
}

repositories {
Expand Down
7 changes: 6 additions & 1 deletion forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ loom {
}
}

forge.mixinConfigs(
"wayfix-forge.mixins.json",
"wayfix-common.mixins.json"
)

runConfigs.all {
isIdeConfigGenerated = true
runDir = "../../../run"
Expand All @@ -90,7 +95,7 @@ tasks.processResources {
tasks.shadowJar {
configurations = listOf(shadowBundle)
archiveClassifier = "dev-shadow"
exclude("fabric.mod.json")
exclude("fabric.mod.json", "assets/wayfix/icon.png")
}

tasks.remapJar {
Expand Down
2 changes: 1 addition & 1 deletion forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version = "${version}"
displayName = "WayFix"
authors = "NotCoded"
description = "Fixes multiple issues regarding Wayland compatibility for Minecraft."
logoFile = "assets/wayfix/icon.png"
logoFile = "icon.png"
logoBlur = false

[["dependencies.wayfix"]]
Expand Down
Binary file added forge/src/main/resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx2G
org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.caching.debug=false
Expand Down
Binary file added neoforge/src/main/resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

@Mixin(MinecraftClient.class)
public abstract class MinecraftClientMixin {
// broken in forge
@Shadow @Final private Window window;

@Shadow @Final public GameOptions options;

// broken in forge
@Shadow public abstract boolean forcesUnicodeFont();

@ModifyArg(method = "onResolutionChanged", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/Window;setScaleFactor(D)V"))
Expand All @@ -29,14 +31,19 @@ private double fixHiDPIScaling(double d) {
/*guiScale = this.options.guiScale;
*///?}


// "Auto" or Gui Scale 0 already auto-scales it
return guiScale != 0 && WayFix.config.autoScaleGUI ? window.calculateScaleFactor(Math.round(guiScale * getScaleFactor()), this.forcesUnicodeFont()) : d;

// this.forcesUnicodeFont() doesn't work on forge & neoforge
// TODO: this.options.getForceUnicodeFont().getValue();

return guiScale != 0 && WayFix.config.autoScaleGUI ? window.calculateScaleFactor(Math.round(guiScale * wayFix$getScaleFactor()), this.forcesUnicodeFont()) : d;
}

@Unique
private float getScaleFactor() {
private float wayFix$getScaleFactor() {
float[] pos = new float[1];
GLFW.glfwGetWindowContentScale(this.window.getHandle(), pos, pos);
GLFW.glfwGetWindowContentScale(this.window.getHandle(), pos, pos);

return pos[0]; // using x or y doesn't matter
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public class MonitorTrackerMixin {

@Inject(method = {"handleMonitorEvent", "<init>"}, at = @At("TAIL"))
private void handleConfigAdditions(CallbackInfo ci) {
this.refreshMonitors();
this.wayFix$refreshMonitors();
}

@Unique
private void refreshMonitors() {
private void wayFix$refreshMonitors() {
ArrayList<Monitor> monitors = new ArrayList<>();
this.pointerToMonitorMap.forEach((aLong, monitor1) -> monitors.add(monitor1));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
public class TextFieldWidgetMixin {
@Inject(method = "charTyped", at = @At("HEAD"), cancellable = true)
private void charTyped(char chr, int modifiers, CallbackInfoReturnable<Boolean> cir) {
if (WayFix.config.keyModifiersFix && WayFix.isWayland() && isSpecialChar(chr) && Screen.hasControlDown()) cir.setReturnValue(false);
if (WayFix.config.keyModifiersFix && WayFix.isWayland() && wayFix$isSpecialChar(chr) && Screen.hasControlDown()) cir.setReturnValue(false);
}

@Unique
private boolean isSpecialChar(char chr) {
private boolean wayFix$isSpecialChar(char chr) {
return chr == 'a' // CTRL + A (select all)
|| chr == 'v' // CTRL + V (paste)
|| chr == 'c' // CTRL + C (copy)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.notcoded.wayfix.common.mixin;

import net.minecraft.client.WindowEventHandler;
import net.minecraft.client.WindowSettings;
import net.minecraft.client.util.Monitor;
import net.minecraft.client.util.MonitorTracker;
import net.minecraft.client.util.Window;
Expand Down Expand Up @@ -41,7 +39,7 @@
@Mixin(Window.class)
public class WindowMixin {
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwDefaultWindowHints()V", shift = At.Shift.AFTER, remap = false))
private void onWindowHints(WindowEventHandler windowEventHandler, MonitorTracker monitorTracker, WindowSettings windowSettings, String string, String string2, CallbackInfo ci) {
private void onWindowHints(CallbackInfo ci) {
if (isWayland()) {
GLFW.glfwWindowHint(GLFW.GLFW_FOCUS_ON_SHOW, GLFW.GLFW_FALSE);

Expand Down

0 comments on commit 9fd4c88

Please sign in to comment.