-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.21.x] Topologically sort reload listeners based on dependency orde…
…ring (#1915) Co-authored-by: Brennan Ward <[email protected]>
- Loading branch information
1 parent
2a445ac
commit 0aa1993
Showing
22 changed files
with
785 additions
and
192 deletions.
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
39 changes: 33 additions & 6 deletions
39
patches/net/minecraft/server/packs/resources/ReloadableResourceManager.java.patch
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 |
---|---|---|
@@ -1,13 +1,40 @@ | ||
--- a/net/minecraft/server/packs/resources/ReloadableResourceManager.java | ||
+++ b/net/minecraft/server/packs/resources/ReloadableResourceManager.java | ||
@@ -73,4 +_,10 @@ | ||
@@ -33,6 +_,12 @@ | ||
this.resources.close(); | ||
} | ||
|
||
+ /** | ||
+ * @deprecated Neo: Use {@link net.neoforged.neoforge.client.event.AddClientReloadListenerEvent}. | ||
+ * | ||
+ * @throws UnsupportedOperationException if called after the event has been fired. | ||
+ */ | ||
+ @Deprecated | ||
public void registerReloadListener(PreparableReloadListener p_10714_) { | ||
this.listeners.add(p_10714_); | ||
} | ||
@@ -72,5 +_,24 @@ | ||
@Override | ||
public Stream<PackResources> listPacks() { | ||
return this.resources.listPacks(); | ||
} | ||
+ } | ||
+ | ||
+ public void registerReloadListenerIfNotPresent(PreparableReloadListener listener) { | ||
+ if (!this.listeners.contains(listener)) { | ||
+ this.registerReloadListener(listener); | ||
+ } | ||
+ /** | ||
+ * Neo: Expose the reload listeners so they can be passed to the event. | ||
+ * | ||
+ * @return The (immutable) list of reload listeners. | ||
+ */ | ||
+ public List<PreparableReloadListener> getListeners() { | ||
+ return this.listeners; | ||
+ } | ||
+ | ||
+ /** | ||
+ * Neo: Updates the {@link #listeners} with the sorted list from the event. | ||
+ * | ||
+ * @implNote The returned list is immutable, so after this method is called, {@link #registerReloadListener(PreparableReloadListener)} will throw. | ||
+ */ | ||
+ @org.jetbrains.annotations.ApiStatus.Internal | ||
+ public void updateListenersFrom(net.neoforged.neoforge.event.SortedReloadListenerEvent event) { | ||
+ this.listeners = net.neoforged.neoforge.resource.ReloadListenerSort.sort(event); | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
src/main/java/net/neoforged/neoforge/client/event/AddClientReloadListenersEvent.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,43 @@ | ||
/* | ||
* Copyright (c) Forge Development LLC and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.client.event; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.packs.resources.PreparableReloadListener; | ||
import net.minecraft.server.packs.resources.ReloadableResourceManager; | ||
import net.neoforged.fml.LogicalSide; | ||
import net.neoforged.fml.event.IModBusEvent; | ||
import net.neoforged.neoforge.client.resources.VanillaClientListeners; | ||
import net.neoforged.neoforge.event.SortedReloadListenerEvent; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
/** | ||
* This event allows mods to register client-side reload listeners to the resource manager. | ||
* This event is fired once during the construction of the {@link Minecraft} instance. | ||
* <p> | ||
* This event is only fired on the {@linkplain LogicalSide#CLIENT logical client}. | ||
* | ||
* @see {@link AddServerReloadListenersEvent} for registering server-side reload listeners. | ||
*/ | ||
public class AddClientReloadListenersEvent extends SortedReloadListenerEvent implements IModBusEvent { | ||
@ApiStatus.Internal | ||
public AddClientReloadListenersEvent(ReloadableResourceManager resourceManager) { | ||
super(resourceManager.getListeners(), AddClientReloadListenersEvent::lookupName); | ||
} | ||
|
||
private static ResourceLocation lookupName(PreparableReloadListener listener) { | ||
ResourceLocation key = VanillaClientListeners.getNameForClass(listener.getClass()); | ||
if (key == null) { | ||
if (listener.getClass().getPackageName().startsWith("net.minecraft")) { | ||
throw new IllegalArgumentException("A key for the reload listener " + listener + " was not provided in VanillaClientListeners!"); | ||
} else { | ||
throw new IllegalArgumentException("A non-vanilla reload listener " + listener + " was added via mixin before the AddClientReloadListenerEvent! Mod-added listeners must go through the event."); | ||
} | ||
} | ||
return key; | ||
} | ||
} |
44 changes: 0 additions & 44 deletions
44
src/main/java/net/neoforged/neoforge/client/event/RegisterClientReloadListenersEvent.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.