From 41dba34df5685a6947d0fc7d92f0962bc3c2a916 Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Sat, 2 Mar 2024 01:24:25 +0000 Subject: [PATCH 1/4] feat: neoforge support --- .github/workflows/gradle.yml | 2 + .gitignore | 3 + build-fabric.gradle | 1 + build-neoforge.gradle | 90 +++++++++++++++++++ build.gradle | 2 + settings.gradle | 3 +- .../mousetweaks/neoforge/ClientHelper.java | 14 +++ .../neoforge/MouseTweaksForge.java | 80 +++++++++++++++++ src/main/resources/META-INF/mods-neo.toml | 19 ++++ src/main/resources/META-INF/mods.toml | 7 +- 10 files changed, 218 insertions(+), 3 deletions(-) create mode 100644 build-neoforge.gradle create mode 100644 src/main/java/yalter/mousetweaks/neoforge/ClientHelper.java create mode 100644 src/main/java/yalter/mousetweaks/neoforge/MouseTweaksForge.java create mode 100644 src/main/resources/META-INF/mods-neo.toml diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index fe2cb4e..eb651f1 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -23,6 +23,8 @@ jobs: java-version: 17 - name: Build (Forge) run: ./gradlew build + - name: Build (NeoForge) + run: ./gradlew --build-file build-neoforge.gradle build - name: Build (Fabric) run: ./gradlew --build-file build-fabric.gradle build - uses: actions/upload-artifact@v2 diff --git a/.gitignore b/.gitignore index 12f8644..dbe1884 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,9 @@ build # other eclipse run +# Neoforge +runs # Files from Forge MDK forge*changelog.txt +.DS_Store diff --git a/build-fabric.gradle b/build-fabric.gradle index 6904e14..29e2db6 100644 --- a/build-fabric.gradle +++ b/build-fabric.gradle @@ -20,6 +20,7 @@ sourceSets { main { java { exclude 'yalter/mousetweaks/forge' + exclude 'yalter/mousetweaks/neoforge' } resources { diff --git a/build-neoforge.gradle b/build-neoforge.gradle new file mode 100644 index 0000000..c221400 --- /dev/null +++ b/build-neoforge.gradle @@ -0,0 +1,90 @@ +plugins { + id 'java-library' + id 'eclipse' + id 'idea' + id 'maven-publish' + id 'net.neoforged.gradle.userdev' version '7.0.80' +} + +def minecraftVersion = "1.20.4" // Used for output JAR filenames. + +version = project.mod_version +group = "yalter.mousetweaks" + +base { + archivesName = "MouseTweaks-neoforge-mc${minecraftVersion}" +} + +java.toolchain.languageVersion = JavaLanguageVersion.of(17) + +sourceSets { + main { + java { + exclude 'yalter/mousetweaks/fabric' + exclude 'yalter/mousetweaks/ModMenuApiImpl.java' + exclude 'yalter/mousetweaks/forge' + } + + resources { + exclude 'fabric.mod.json' + exclude 'META-INF/mods-neo.toml' + } + } +} + +tasks.register("fixModsToml", Copy) { + // Copy the mods-neo.toml file to mods.toml + from "src/main/resources/META-INF" + include "mods-neo.toml" + rename "mods-neo.toml", "mods.toml" + into "src/main/resources/META-INF" +} + +// Make the fixModsToml task run before the processResources task +processResources.dependsOn(fixModsToml) + +processResources { + inputs.property "version", project.mod_version + filesMatching("META-INF/mods.toml") { + expand "version": project.mod_version + } +} + +runs { + configureEach { + systemProperty 'forge.logging.markers', 'REGISTRIES' + systemProperty 'forge.logging.console.level', 'debug' + + modSource project.sourceSets.main + } + + client { + systemProperty 'forge.enabledGameTestNamespaces', "mousetweaks" + } + + server { + systemProperty 'forge.enabledGameTestNamespaces', "mousetweaks" + programArgument '--nogui' + } +} + +dependencies { + implementation "net.neoforged:neoforge:20.4.190" +} + +task srcJar(type: Jar) { + archiveClassifier.set("src") + from sourceSets.main.allJava +} + +task apiJar(type: Jar) { + archiveClassifier.set("api") + from(sourceSets.main.output) { + include 'yalter/mousetweaks/api/**' + } +} + +artifacts { + archives srcJar + archives apiJar +} diff --git a/build.gradle b/build.gradle index 5072d8b..3950f12 100644 --- a/build.gradle +++ b/build.gradle @@ -24,10 +24,12 @@ sourceSets { java { exclude 'yalter/mousetweaks/fabric' exclude 'yalter/mousetweaks/ModMenuApiImpl.java' + exclude 'yalter/mousetweaks/neoforge' } resources { exclude 'fabric.mod.json' + exclude 'META-INF/mods-neo.toml' } } } diff --git a/settings.gradle b/settings.gradle index a8ef30d..89921ff 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,5 +7,6 @@ pluginManagement { mavenCentral() gradlePluginPortal() maven { url = 'https://maven.minecraftforge.net/' } + maven { url = 'https://maven.neoforged.net/releases' } } -} \ No newline at end of file +} diff --git a/src/main/java/yalter/mousetweaks/neoforge/ClientHelper.java b/src/main/java/yalter/mousetweaks/neoforge/ClientHelper.java new file mode 100644 index 0000000..20456e5 --- /dev/null +++ b/src/main/java/yalter/mousetweaks/neoforge/ClientHelper.java @@ -0,0 +1,14 @@ +package yalter.mousetweaks.neoforge; + +import net.neoforged.neoforge.client.ConfigScreenHandler; +import yalter.mousetweaks.ConfigScreen; + +/** + * Functions accessing client-only classes, extracted so that they can be called from MouseTweaksForge + * without causing class-loading errors on the server. + */ +public class ClientHelper { + public static ConfigScreenHandler.ConfigScreenFactory createConfigScreenFactory() { + return new ConfigScreenHandler.ConfigScreenFactory((minecraft, screen) -> new ConfigScreen(screen)); + } +} diff --git a/src/main/java/yalter/mousetweaks/neoforge/MouseTweaksForge.java b/src/main/java/yalter/mousetweaks/neoforge/MouseTweaksForge.java new file mode 100644 index 0000000..0b92bdf --- /dev/null +++ b/src/main/java/yalter/mousetweaks/neoforge/MouseTweaksForge.java @@ -0,0 +1,80 @@ +package yalter.mousetweaks.neoforge; + +import net.neoforged.neoforge.client.ConfigScreenHandler; +import net.neoforged.neoforge.client.ConfigScreenHandler.ConfigScreenFactory; +import net.neoforged.neoforge.client.event.ScreenEvent.MouseButtonPressed; +import net.neoforged.neoforge.client.event.ScreenEvent.MouseButtonReleased; +import net.neoforged.neoforge.client.event.ScreenEvent.MouseDragged; +import net.neoforged.neoforge.client.event.ScreenEvent.MouseScrolled; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.IExtensionPoint; +import net.neoforged.fml.ModLoadingContext; +import net.neoforged.fml.loading.FMLEnvironment; +import net.neoforged.fml.common.Mod; +import yalter.mousetweaks.Constants; +import yalter.mousetweaks.Logger; +import yalter.mousetweaks.Main; +import yalter.mousetweaks.MouseButton; + +@Mod(Constants.MOD_ID) +public class MouseTweaksForge { + public MouseTweaksForge() { + ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> "ANY", (remote, isServer) -> true)); + if (FMLEnvironment.dist != net.neoforged.api.distmarker.Dist.CLIENT) { + Logger.Log("Disabled because not running on the client."); + return; + } + + Main.initialize(); + NeoForge.EVENT_BUS.register(this); + + ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, ClientHelper::createConfigScreenFactory); + } + + @SubscribeEvent + public void onGuiMouseClickedPre(MouseButtonPressed.Pre event) { + Logger.DebugLog("onGuiMouseClickedPre button = " + event.getButton()); + + MouseButton button = MouseButton.fromEventButton(event.getButton()); + if (button != null) { + if (Main.onMouseClicked(event.getScreen(), event.getMouseX(), event.getMouseY(), button)) + event.setCanceled(true); + } + } + + @SubscribeEvent + public void onGuiMouseReleasedPre(MouseButtonReleased.Pre event) { + Logger.DebugLog("onGuiMouseReleasedPre button = " + event.getButton()); + + MouseButton button = MouseButton.fromEventButton(event.getButton()); + if (button != null) { + if (Main.onMouseReleased(event.getScreen(), event.getMouseX(), event.getMouseY(), button)) + event.setCanceled(true); + } + } + + @SubscribeEvent + public void onGuiMouseScrollPost(MouseScrolled.Post event) { + // Sent when nothing handled the scroll itself. For example, the creative inventory handles scroll anywhere on + // screen, so this event is suppressed. Quick scrolls at limited FPS result in multiple scroll events rather + // than one with a bigger delta. + Logger.DebugLog("onGuiMouseScrollPost delta = " + event.getScrollDeltaY()); + + // Post events aren't cancellable, but that's okay. + Main.onMouseScrolled(event.getScreen(), event.getMouseX(), event.getMouseY(), event.getScrollDeltaY()); + } + + @SubscribeEvent + public void onGuiMouseDragPre(MouseDragged.Pre event) { + // Sent when a mouse is dragged while a mouse button is down (so between Clicked and Released events). The + // rate of reporting is high even when the FPS is limited through the options. + Logger.DebugLog("onGuiMouseDragPre button = " + event.getMouseButton() + ", dx = " + event.getDragX() + ", dy = " + event.getDragY()); + + MouseButton button = MouseButton.fromEventButton(event.getMouseButton()); + if (button != null) { + if (Main.onMouseDrag(event.getScreen(), event.getMouseX(), event.getMouseY(), button)) + event.setCanceled(true); + } + } +} diff --git a/src/main/resources/META-INF/mods-neo.toml b/src/main/resources/META-INF/mods-neo.toml new file mode 100644 index 0000000..354d1b5 --- /dev/null +++ b/src/main/resources/META-INF/mods-neo.toml @@ -0,0 +1,19 @@ +modLoader="javafml" +loaderVersion="[2,)" +license="BSD-3-Clause" +issueTrackerURL="https://github.com/YaLTeR/MouseTweaks/issues" + +[[mods]] +modId="mousetweaks" +version="${version}" +displayName="Mouse Tweaks" +displayURL="https://minecraft.curseforge.com/projects/mouse-tweaks" +logoFile="mousetweaks_logo.png" +credits="Contributors: mezz, juliand665, panoskj, FabiClawZ." +authors="Ivan Molodetskikh (YaLTeR)" +description=''' +A mod that enhances the inventory management by adding various additional functions to the usual mouse buttons. +''' + +[[mixins]] +config="mousetweaks.mixins.json" diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 2d29612..354d1b5 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,11 +1,11 @@ modLoader="javafml" -loaderVersion="[48,)" +loaderVersion="[2,)" license="BSD-3-Clause" issueTrackerURL="https://github.com/YaLTeR/MouseTweaks/issues" [[mods]] modId="mousetweaks" -version="${file.jarVersion}" +version="${version}" displayName="Mouse Tweaks" displayURL="https://minecraft.curseforge.com/projects/mouse-tweaks" logoFile="mousetweaks_logo.png" @@ -14,3 +14,6 @@ authors="Ivan Molodetskikh (YaLTeR)" description=''' A mod that enhances the inventory management by adding various additional functions to the usual mouse buttons. ''' + +[[mixins]] +config="mousetweaks.mixins.json" From dff5043308fdf355c705f26e0174f174f611e2bc Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Sun, 3 Mar 2024 02:29:46 +0000 Subject: [PATCH 2/4] fix: broken mods.toml for forge --- src/main/resources/META-INF/mods.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 354d1b5..b3f7522 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,11 +1,11 @@ modLoader="javafml" -loaderVersion="[2,)" +loaderVersion="[48,)" license="BSD-3-Clause" issueTrackerURL="https://github.com/YaLTeR/MouseTweaks/issues" [[mods]] modId="mousetweaks" -version="${version}" +version="${file.jarVersion}" displayName="Mouse Tweaks" displayURL="https://minecraft.curseforge.com/projects/mouse-tweaks" logoFile="mousetweaks_logo.png" From a8aa199e328023c988417688face3a3e6b7b0d63 Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Sun, 3 Mar 2024 02:30:36 +0000 Subject: [PATCH 3/4] fix: whoops --- src/main/resources/META-INF/mods.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index b3f7522..2d29612 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -14,6 +14,3 @@ authors="Ivan Molodetskikh (YaLTeR)" description=''' A mod that enhances the inventory management by adding various additional functions to the usual mouse buttons. ''' - -[[mixins]] -config="mousetweaks.mixins.json" From 3a7bc0bdd8476db528990aedc172f3c486acb4a2 Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Sun, 3 Mar 2024 10:44:14 +0000 Subject: [PATCH 4/4] fix: rename forge class to neo --- src/main/java/yalter/mousetweaks/neoforge/ClientHelper.java | 2 +- .../neoforge/{MouseTweaksForge.java => MouseTweaksNeo.java} | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) rename src/main/java/yalter/mousetweaks/neoforge/{MouseTweaksForge.java => MouseTweaksNeo.java} (96%) diff --git a/src/main/java/yalter/mousetweaks/neoforge/ClientHelper.java b/src/main/java/yalter/mousetweaks/neoforge/ClientHelper.java index 20456e5..7229adb 100644 --- a/src/main/java/yalter/mousetweaks/neoforge/ClientHelper.java +++ b/src/main/java/yalter/mousetweaks/neoforge/ClientHelper.java @@ -4,7 +4,7 @@ import yalter.mousetweaks.ConfigScreen; /** - * Functions accessing client-only classes, extracted so that they can be called from MouseTweaksForge + * Functions accessing client-only classes, extracted so that they can be called from MouseTweaksNeo * without causing class-loading errors on the server. */ public class ClientHelper { diff --git a/src/main/java/yalter/mousetweaks/neoforge/MouseTweaksForge.java b/src/main/java/yalter/mousetweaks/neoforge/MouseTweaksNeo.java similarity index 96% rename from src/main/java/yalter/mousetweaks/neoforge/MouseTweaksForge.java rename to src/main/java/yalter/mousetweaks/neoforge/MouseTweaksNeo.java index 0b92bdf..0c04180 100644 --- a/src/main/java/yalter/mousetweaks/neoforge/MouseTweaksForge.java +++ b/src/main/java/yalter/mousetweaks/neoforge/MouseTweaksNeo.java @@ -1,7 +1,6 @@ package yalter.mousetweaks.neoforge; import net.neoforged.neoforge.client.ConfigScreenHandler; -import net.neoforged.neoforge.client.ConfigScreenHandler.ConfigScreenFactory; import net.neoforged.neoforge.client.event.ScreenEvent.MouseButtonPressed; import net.neoforged.neoforge.client.event.ScreenEvent.MouseButtonReleased; import net.neoforged.neoforge.client.event.ScreenEvent.MouseDragged; @@ -18,8 +17,8 @@ import yalter.mousetweaks.MouseButton; @Mod(Constants.MOD_ID) -public class MouseTweaksForge { - public MouseTweaksForge() { +public class MouseTweaksNeo { + public MouseTweaksNeo() { ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> "ANY", (remote, isServer) -> true)); if (FMLEnvironment.dist != net.neoforged.api.distmarker.Dist.CLIENT) { Logger.Log("Disabled because not running on the client.");