Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added NeoForge Support #125

Merged
merged 4 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ build
# other
eclipse
run
# Neoforge
runs

# Files from Forge MDK
forge*changelog.txt
.DS_Store
1 change: 1 addition & 0 deletions build-fabric.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ sourceSets {
main {
java {
exclude 'yalter/mousetweaks/forge'
exclude 'yalter/mousetweaks/neoforge'
}

resources {
Expand Down
90 changes: 90 additions & 0 deletions build-neoforge.gradle
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ pluginManagement {
mavenCentral()
gradlePluginPortal()
maven { url = 'https://maven.minecraftforge.net/' }
maven { url = 'https://maven.neoforged.net/releases' }
}
}
}
14 changes: 14 additions & 0 deletions src/main/java/yalter/mousetweaks/neoforge/ClientHelper.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
79 changes: 79 additions & 0 deletions src/main/java/yalter/mousetweaks/neoforge/MouseTweaksNeo.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
19 changes: 19 additions & 0 deletions src/main/resources/META-INF/mods-neo.toml
Original file line number Diff line number Diff line change
@@ -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"
Loading