Skip to content

Commit

Permalink
attempt to bring over multiloader-2 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
not-coded committed Nov 27, 2024
1 parent 1c1b560 commit e91a923
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 35 deletions.
8 changes: 6 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ loom {
}
}

if(isForge) {
forge.mixinConfig("wayfix.mixins.json")
}

/*
runConfigs.all {
ideConfigGenerated(stonecutter.current.isActive)
Expand All @@ -74,12 +78,12 @@ tasks.processResources {

if (isFabric) {
filesMatching("fabric.mod.json") { expand(expandProps) }
exclude("META-INF/mods.toml", "META-INF/neoforge.mods.toml", "pack.mcmeta")
exclude("META-INF/mods.toml", "META-INF/neoforge.mods.toml", "pack.mcmeta", "icon.png")
}

if(isForge) {
filesMatching("META-INF/*mods.toml") { expand(expandProps) }
exclude("fabric.mod.json")
exclude("fabric.mod.json", "assets/wayfix/icon.png")
}

inputs.properties(expandProps)
Expand Down
2 changes: 0 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Done to increase the memory available to gradle.
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

# Mod Information
mod.version=1.0.2
Expand Down
32 changes: 14 additions & 18 deletions src/main/java/net/notcoded/wayfix/WayFix.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
*///?} elif forge {
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
//? if >=1.19 {
import net.minecraftforge.client.ConfigScreenHandler;
Expand Down Expand Up @@ -40,24 +39,21 @@ public void onInitializeClient() {

//? if forge {
public WayFix() {
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
modEventBus.addListener(WayFix::onClientSetup);
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> WayFix::setupConfigScreen);
}

private static void onClientSetup(final FMLClientSetupEvent event) {
event.enqueueWork(() -> {
//? if >=1.19 {
ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () ->
new ConfigScreenHandler.ConfigScreenFactory(
(client, parent) -> AutoConfig.getConfigScreen(ModConfig.class, parent).get()
)
);
//?} elif <1.19 {
/*ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY, () ->
(client, parent) -> AutoConfig.getConfigScreen(ModConfig.class, parent).get()
);*///?}
});
}
private static void setupConfigScreen() {
//? if >=1.19 {
ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () ->
new ConfigScreenHandler.ConfigScreenFactory(
(client, parent) -> AutoConfig.getConfigScreen(ModConfig.class, parent).get()
)
);
//?} elif <1.19 {
/*ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY, () ->
(client, parent) -> AutoConfig.getConfigScreen(ModConfig.class, parent).get()
);*///?}
}
//?}

public static boolean isWayland() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ private double fixHiDPIScaling(double d) {
*///?}

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

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
8 changes: 3 additions & 5 deletions src/main/java/net/notcoded/wayfix/mixin/WindowMixin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.notcoded.wayfix.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 All @@ -53,11 +51,11 @@ private void onWindowHints(WindowEventHandler windowEventHandler, MonitorTracker

@Redirect(method = "updateWindowRegion", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/MonitorTracker;getMonitor(Lnet/minecraft/client/util/Window;)Lnet/minecraft/client/util/Monitor;"))
private Monitor fixWrongMonitor(MonitorTracker instance, Window window) {
return WayFix.config.fullscreen.useMonitorName ? getMonitor(instance) : instance.getMonitor(window);
return WayFix.config.fullscreen.useMonitorName ? wayFix$getMonitor(instance) : instance.getMonitor(window);
}

@Unique
private Monitor getMonitor(MonitorTracker instance) {
private Monitor wayFix$getMonitor(MonitorTracker instance) {
String monitorName = WayFix.config.fullscreen.monitorName;
long monitorID = monitorName.trim().isEmpty() ? GLFW.glfwGetPrimaryMonitor() : ModConfig.Monitors.getMonitor(monitorName);

Expand Down
2 changes: 1 addition & 1 deletion 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
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/neoforge.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 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.

0 comments on commit e91a923

Please sign in to comment.