Add updated tag context to AddReloadListenerEvent (#10412)

Fixes using custom tags in GlobalLootModifiers.
This commit is contained in:
Jonathing authored and GitHub committed 2025-02-12 11:02:22 -08:00
1 parent 02e82c672d
commit 674f2efd54
6 files changed
+56 -11

No files matched your search

@@ -94,7 +94,7 @@ public class ForgeInternalHandler {
@SubscribeEvent
public void onResourceReload(AddReloadListenerEvent event) {
INSTANCE = new LootModifierManager(event.getRegistryAccess());
INSTANCE = new LootModifierManager(event.getRegistries());
event.addListener(INSTANCE);
}
@@ -6,7 +6,10 @@
package net.minecraftforge.event;
import com.google.common.collect.ImmutableList;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.LayeredRegistryAccess;
import net.minecraft.core.RegistryAccess;
import net.minecraft.server.RegistryLayer;
import net.minecraft.server.ReloadableServerResources;
import net.minecraft.server.packs.resources.PreparableReloadListener;
import net.minecraft.server.packs.resources.ResourceManager;
@@ -29,10 +32,31 @@ import java.util.concurrent.Executor;
public class AddReloadListenerEvent extends Event {
private final List<PreparableReloadListener> listeners = new ArrayList<>();
private final ReloadableServerResources serverResources;
private final HolderLookup.Provider registries;
@Deprecated(forRemoval = true, since = "1.21.4")
private final RegistryAccess registryAccess;
public AddReloadListenerEvent(ReloadableServerResources serverResources, RegistryAccess registryAccess) {
/** @deprecated Does not provide additional context. Use {@link #AddReloadListenerEvent(ReloadableServerResources, HolderLookup.Provider, RegistryAccess)} instead. */
@Deprecated(forRemoval = true, since = "1.21.4")
public AddReloadListenerEvent(
ReloadableServerResources serverResources,
RegistryAccess registryAccess
) {
this(
serverResources,
registryAccess,
registryAccess
);
}
public AddReloadListenerEvent(
ReloadableServerResources serverResources,
HolderLookup.Provider registries,
@Deprecated(forRemoval = true, since = "1.21.4") RegistryAccess registryAccess
) {
this.serverResources = serverResources;
this.registries = registries;
this.registryAccess = registryAccess;
}
@@ -62,21 +86,27 @@ public class AddReloadListenerEvent extends Event {
return serverResources.getConditionContext();
}
/**
* @return A holder lookup provider containing the registries with updated tags.
*
* @see net.minecraft.server.ReloadableServerRegistries.LoadResult#lookupWithUpdatedTags()
*/
public HolderLookup.Provider getRegistries() {
return registries;
}
/**
* Provides access to the loaded registries associated with these server resources.
* All built-in and dynamic registries are loaded and frozen by this point.
* @return The RegistryAccess context for the currently active reload.
* @deprecated Does not contain updated tags. Use {@link #getRegistries()} instead.
*/
@Deprecated(forRemoval = true, since = "1.21.4")
public RegistryAccess getRegistryAccess() {
return registryAccess;
}
private static class WrappedStateAwareListener implements PreparableReloadListener {
private final PreparableReloadListener wrapped;
private WrappedStateAwareListener(final PreparableReloadListener wrapped) {
this.wrapped = wrapped;
}
private record WrappedStateAwareListener(PreparableReloadListener wrapped) implements PreparableReloadListener {
@Override
public CompletableFuture<Void> reload(final PreparationBarrier stage, final ResourceManager resourceManager, final Executor backgroundExecutor, final Executor gameExecutor) {
@@ -85,5 +115,10 @@ public class AddReloadListenerEvent extends Event {
else
return CompletableFuture.completedFuture(null);
}
@Override
public String getName() {
return wrapped.getName();
}
}
}
@@ -14,7 +14,10 @@ import java.util.Optional;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.LayeredRegistryAccess;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.server.RegistryLayer;
import net.minecraft.world.entity.*;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.chunk.storage.SerializableChunkData;
@@ -712,10 +715,15 @@ public final class ForgeEventFactory {
return fire(new SleepFinishedTimeEvent(level, newTime, minTime)).getNewTime();
}
@Deprecated(forRemoval = true, since = "1.21.4")
public static List<PreparableReloadListener> onResourceReload(ReloadableServerResources serverResources, RegistryAccess registryAccess) {
return fire(new AddReloadListenerEvent(serverResources, registryAccess)).getListeners();
}
public static List<PreparableReloadListener> onResourceReload(ReloadableServerResources serverResources, HolderLookup.Provider lookupProvider, @Deprecated(forRemoval = true, since = "1.21.4") RegistryAccess registryAccess) {
return fire(new AddReloadListenerEvent(serverResources, lookupProvider, registryAccess)).getListeners();
}
public static void onCommandRegister(CommandDispatcher<CommandSourceStack> dispatcher, Commands.CommandSelection environment, CommandBuildContext context) {
post(new RegisterCommandsEvent(dispatcher, environment, context));
}