Package net.neoforged.neoforge.resource
Class ReloadListenerSort
java.lang.Object
net.neoforged.neoforge.resource.ReloadListenerSort
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static booleanisVanilla(SortedReloadListenerEvent.NameLookup lookup, PreparableReloadListener listener) private static booleanneedsToBeLinkedToVanilla(SortedReloadListenerEvent.NameLookup lookup, Graph<PreparableReloadListener> graph, PreparableReloadListener listener) A node needs to be linked to vanilla if it is otherwise "dangling" from the vanilla graph.static List<PreparableReloadListener> sort(SortedReloadListenerEvent event) Sorts the listeners and emits the returned list.static List<PreparableReloadListener> sortListeners(SortedReloadListenerEvent.NameLookup lookup, MutableGraph<PreparableReloadListener> graph, Map<ResourceLocation, PreparableReloadListener> registry, PreparableReloadListener lastVanilla) Implementation forsort(SortedReloadListenerEvent).
-
Constructor Details
-
ReloadListenerSort
public ReloadListenerSort()
-
-
Method Details
-
sort
Sorts the listeners and emits the returned list.This method modifies the current state of the graph to ensure that all dangling listeners run after vanilla.
- Returns:
- An immutable, sorted list of listeners based on the current dependency graph.
- Throws:
IllegalArgumentException- if cycles were detected in the dependency graph.
-
sortListeners
public static List<PreparableReloadListener> sortListeners(SortedReloadListenerEvent.NameLookup lookup, MutableGraph<PreparableReloadListener> graph, Map<ResourceLocation, PreparableReloadListener> registry, PreparableReloadListener lastVanilla) Implementation forsort(SortedReloadListenerEvent).- Parameters:
lookup- Thename lookupfrom the event.graph- The mutable graph. The event only exposes a non-mutable graph, but we can just downcast it since we know it's a MutableGraph.registry- The reload listener registry.lastVanilla- A reference to the last vanilla listener in vanilla order.- Returns:
- An immutable, sorted list of listeners based on the current dependency graph.
- Throws:
IllegalArgumentException- if cycles were detected in the dependency graph.
-
needsToBeLinkedToVanilla
private static boolean needsToBeLinkedToVanilla(SortedReloadListenerEvent.NameLookup lookup, Graph<PreparableReloadListener> graph, PreparableReloadListener listener) A node needs to be linked to vanilla if it is otherwise "dangling" from the vanilla graph.To determine if a node needs to be linked, we perform a forward and backward DFS to detect if there are any links to vanilla nodes. If there are no links, we add an edge against the last vanilla listener based on the default order.
- Returns:
- true if the listener needs to be linked to vanilla.
-
isVanilla
private static boolean isVanilla(SortedReloadListenerEvent.NameLookup lookup, PreparableReloadListener listener)
-