Expose loaded RegistryAccess through AddReloadListenerEvent (#9613)

This commit is contained in:
Gegy authored and GitHub committed 2023-07-05 15:00:12 -07:00
1 parent 93e4a7c649
commit 7b833faa46
3 files changed
+18 -4

No files matched your search

@@ -6,6 +6,7 @@
package net.minecraftforge.event;
import com.google.common.collect.ImmutableList;
import net.minecraft.core.RegistryAccess;
import net.minecraft.server.ReloadableServerResources;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.server.packs.resources.PreparableReloadListener;
@@ -30,10 +31,12 @@ public class AddReloadListenerEvent extends Event
{
private final List<PreparableReloadListener> listeners = new ArrayList<>();
private final ReloadableServerResources serverResources;
private final RegistryAccess registryAccess;
public AddReloadListenerEvent(ReloadableServerResources serverResources)
public AddReloadListenerEvent(ReloadableServerResources serverResources, RegistryAccess registryAccess)
{
this.serverResources = serverResources;
this.registryAccess = registryAccess;
}
/**
@@ -66,6 +69,16 @@ public class AddReloadListenerEvent extends Event
return serverResources.getConditionContext();
}
/**
* 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.
*/
public RegistryAccess getRegistryAccess()
{
return registryAccess;
}
private static class WrappedStateAwareListener implements PreparableReloadListener {
private final PreparableReloadListener wrapped;
@@ -18,6 +18,7 @@ import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementProgress;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.core.Holder;
import net.minecraft.core.RegistryAccess;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ReloadableServerResources;
import net.minecraft.server.level.ChunkHolder;
@@ -758,9 +759,9 @@ public class ForgeEventFactory
return event.getNewTime();
}
public static List<PreparableReloadListener> onResourceReload(ReloadableServerResources serverResources)
public static List<PreparableReloadListener> onResourceReload(ReloadableServerResources serverResources, RegistryAccess registryAccess)
{
AddReloadListenerEvent event = new AddReloadListenerEvent(serverResources);
AddReloadListenerEvent event = new AddReloadListenerEvent(serverResources, registryAccess);
MinecraftForge.EVENT_BUS.post(event);
return event.getListeners();
}