-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: neoforge support * fix: broken mods.toml for forge * fix: whoops * fix: rename forge class to neo
- Loading branch information
1 parent
cc1365b
commit 9d563e8
Showing
9 changed files
with
212 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,9 @@ build | |
# other | ||
eclipse | ||
run | ||
# Neoforge | ||
runs | ||
|
||
# Files from Forge MDK | ||
forge*changelog.txt | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/yalter/mousetweaks/neoforge/ClientHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
79
src/main/java/yalter/mousetweaks/neoforge/MouseTweaksNeo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |