-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
[1.21.x] Topologically sort reload listeners based on dependency ordering #1915
base: 1.21.x
Are you sure you want to change the base?
Conversation
This class injects a ModLoader.hasErrors() check into code that would not be reached if the mod loader errors.
Also adds static keys for the neo-added listeners.
Last commit published: 2601dc47a353d69a67627b17b8cba5638f481e6d. PR PublishingThe artifacts published by this PR:
Repository DeclarationIn order to use the artifacts published by the PR, add the following repository to your buildscript: repositories {
maven {
name 'Maven for PR #1915' // https://github.com/neoforged/NeoForge/pull/1915
url 'https://prmaven.neoforged.net/NeoForge/pr1915'
content {
includeModule('net.neoforged', 'neoforge')
includeModule('net.neoforged', 'testframework')
}
}
} MDK installationIn order to setup a MDK using the latest PR version, run the following commands in a terminal. mkdir NeoForge-pr1915
cd NeoForge-pr1915
curl -L https://prmaven.neoforged.net/NeoForge/pr1915/net/neoforged/neoforge/21.4.89-beta-pr-1915-listener-sort/mdk-pr1915.zip -o mdk.zip
jar xf mdk.zip
rm mdk.zip || del mdk.zip To test a production environment, you can download the installer from here. |
@Shadows-of-Fire, this PR introduces breaking changes.
|
Overview
This PR introduces dependency sorting for both client and server reload listeners. The sort is topological, using FML's
TopologicalSort
class as the backbone. Reload listeners are added to a DAG where an edge froma->b
means thata
must run beforeb
.The sorting logic, and the modder-facing API, is in
SortedReloadListenerEvent
, the parent class of bothAddReloadListenerEvent
andAddClientReloadListenerEvent
(formerlyRegisterClientReloadListenersEvent
).Requirements
As a prerequisite, this change enforces that all reload listeners are named. The name must be provided via
SortedReloadListenerEvent#addListener
at the time of registration. Vanilla listeners are preemptively named, viaVanillaClientListeners
andVanillaServerListeners
, which hold the class->RL maps for all known vanilla listener types.Note: Mods that are currently using mixins or other non-event means to inject reload listeners will crash after this change.
Sorting
Each
SortedReloadListenerEvent
maintains aGraph<PreparableReloadListener>
which holds the directed edges that dictate the dependency information. An edge froma->b
means thata
must run beforeb
. New edges are added to the graph via#addDependency(first, second)
, which creates a new edge fromfirst->second
.When the vanilla listeners are added in the event's constructor, edges are added such that each vanilla listener depends on the previous one in-order. This guarantees that the vanilla order is maintained without relying on implicit behavior from the toposort.
Finally, after the event has concluded, but before the sort, a search is performed to find dangling nodes and attach them to the last vanilla node, such that all mod-added listeners run after vanilla if they do not otherwise specify dependency ordering.
Error Handling
A dependency cycle in the toposort is an unrecoverable error and will cause the game to crash. If any cycles are detected, an
IllegalArgumentException
will be thrown containing a string representation of the cycle(s).For example:
Notes
This PR supersedes #1289.