-
Notifications
You must be signed in to change notification settings - Fork 36
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
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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)); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/yalter/mousetweaks/neoforge/MouseTweaksForge.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,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); | ||
} | ||
} | ||
} |
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" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it makes sense to rename this to something like
MouseTweaksNeo
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be resolved now 👍