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..7229adb --- /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 MouseTweaksNeo + * 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/MouseTweaksNeo.java b/src/main/java/yalter/mousetweaks/neoforge/MouseTweaksNeo.java new file mode 100644 index 0000000..0c04180 --- /dev/null +++ b/src/main/java/yalter/mousetweaks/neoforge/MouseTweaksNeo.java @@ -0,0 +1,79 @@ +package yalter.mousetweaks.neoforge; + +import net.neoforged.neoforge.client.ConfigScreenHandler; +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 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."); + 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"