Compare commits

...
Author SHA1 Message Date
Jake Potrebic 1a995d67e6 Set correct tag registrar cause on reload (#14459) 2026-11-11 10:01:29 -08:00
11 changed files with 116 additions and 45 deletions

No files matched your search

@@ -26819,7 +26819,7 @@ index df28b83ab34b2e44a6ce2dbb903ef94db5496aaa..f961326218d56f1455df8d3b7b6079e2
assert isValidNamespace(namespace);
assert isValidPath(path);
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 7bc5221da2707b53f0d710f80ea4bfa838195ad4..07ba0aeefec186d7befe60c86dc5180e3131de51 100644
index a68f89d10332d559fa487d7f95ffc664410b07bd..fe3cb9c49d12e22f00e12f227357f4d49dbf312e 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -187,7 +187,7 @@ import net.minecraft.world.scores.ScoreboardSaveData;
@@ -27060,7 +27060,7 @@ index 7bc5221da2707b53f0d710f80ea4bfa838195ad4..07ba0aeefec186d7befe60c86dc5180e
this.tickFrame.end();
this.recordEndOfTick(); // Paper - improve tick loop
profiler.pop();
@@ -2561,6 +2680,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2562,6 +2681,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
}
@@ -1,5 +1,19 @@
--- a/net/minecraft/resources/RegistryDataLoader.java
+++ b/net/minecraft/resources/RegistryDataLoader.java
@@ -201,11 +_,12 @@
final List<HolderLookup.RegistryLookup<?>> contextRegistries,
final List<RegistryDataLoader.RegistryData<?>> registriesToLoad,
final Executor executor
+ , final io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause // Paper - add load cause
) {
RegistryDataLoader.LoaderFactory loaderFactory = new RegistryDataLoader.LoaderFactory() {
@Override
public <T> RegistryLoadTask<T> create(final RegistryDataLoader.RegistryData<T> data, final Map<ResourceKey<?>, Exception> loadingErrors) {
- return new ResourceManagerRegistryLoadTask<>(data, Lifecycle.stable(), loadingErrors, resourceManager);
+ return new ResourceManagerRegistryLoadTask<>(data, Lifecycle.stable(), loadingErrors, resourceManager, cause); // Paper - add load cause
}
};
return load(loaderFactory, contextRegistries, registriesToLoad, executor);
@@ -278,11 +_,21 @@
final Map<ResourceKey<? extends Registry<?>>, HolderGetter<?>> result = new HashMap<>();
contextRegistries.forEach(e -> result.put(e.key(), e));
@@ -1,6 +1,23 @@
--- a/net/minecraft/resources/ResourceManagerRegistryLoadTask.java
+++ b/net/minecraft/resources/ResourceManagerRegistryLoadTask.java
@@ -40,6 +_,7 @@
@@ -26,20 +_,24 @@
return new RegistrationInfo(knownPack, lifecycle);
});
private final ResourceManager resourceManager;
+ private final io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause; // Paper - add load cause
public ResourceManagerRegistryLoadTask(
final RegistryDataLoader.RegistryData<T> data,
final Lifecycle lifecycle,
final Map<ResourceKey<?>, Exception> loadingErrors,
final ResourceManager resourceManager
+ , final io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause // Paper - add load cause
) {
super(data, lifecycle, loadingErrors);
this.resourceManager = resourceManager;
+ this.cause = cause; // Paper - add load cause
}
@Override
public CompletableFuture<?> load(final RegistryOps.RegistryInfoLookup context, final Executor executor) {
FileToIdConverter lister = FileToIdConverter.registry(this.registryKey());
@@ -20,7 +37,7 @@
this.registryKey(), this.concurrentRegistrationGetter, this.readOnlyRegistry()
);
- Map<TagKey<T>, List<Holder<T>>> pendingTags = TagLoader.loadTagsForRegistry(this.resourceManager, this.registryKey(), tagElementLookup);
+ Map<TagKey<T>, List<Holder<T>>> pendingTags = TagLoader.loadTagsForRegistry(this.resourceManager, this.registryKey(), tagElementLookup, this.registry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL); // Paper - tag lifecycle - add registry, cause
+ Map<TagKey<T>, List<Holder<T>>> pendingTags = TagLoader.loadTagsForRegistry(this.resourceManager, this.registryKey(), tagElementLookup, this.registry, this.cause); // Paper - tag lifecycle - add registry, cause
this.registerTags(pendingTags);
},
executor
@@ -1341,6 +1341,14 @@
return ReloadableServerResources.loadResources(
resources,
this.registries,
@@ -1526,6 +_,7 @@
this.getFunctionCompilationPermissions(),
this.executor,
this
+ , io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.RELOAD // Paper - add registrar event cause
)
.whenComplete((unit, throwable) -> {
if (throwable != null) {
@@ -1536,17 +_,35 @@
}
)
@@ -0,0 +1,17 @@
--- a/net/minecraft/server/ReloadableServerRegistries.java
+++ b/net/minecraft/server/ReloadableServerRegistries.java
@@ -32,12 +_,13 @@
final List<Registry.PendingTags<?>> updatedContextTags,
final ResourceManager manager,
final Executor executor
+ , final io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause // Paper - tag lifecycle - add registrar event cause
) {
List<HolderLookup.RegistryLookup<?>> contextRegistriesWithTags = TagLoader.buildUpdatedLookups(
context.getAccessForLoading(RegistryLayer.RELOADABLE), updatedContextTags
);
HolderLookup.Provider loadingContextWithTags = HolderLookup.Provider.create(contextRegistriesWithTags.stream());
- return RegistryDataLoader.load(manager, contextRegistriesWithTags, RegistryDataLoader.RELOADABLE_REGISTRIES, executor)
+ return RegistryDataLoader.load(manager, contextRegistriesWithTags, RegistryDataLoader.RELOADABLE_REGISTRIES, executor, cause) // Paper - tag lifecycle - add registrar event cause
.thenApplyAsync(newlyLoadedRegistries -> createAndValidateFullContext(context, loadingContextWithTags, newlyLoadedRegistries), executor);
}
@@ -11,17 +11,27 @@
this.advancements = new ServerAdvancementManager(loadingContext.lookupWithUpdatedTags());
this.functionLibrary = new ServerFunctionLibrary(functionCompilationPermissions, this.commands.getDispatcher());
}
@@ -96,6 +_,14 @@
@@ -80,8 +_,9 @@
final PermissionSet functionCompilationPermissions,
final Executor backgroundExecutor,
final Executor mainThreadExecutor
+ , final io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause // Paper - add registrar event cause
) {
- return ReloadableServerRegistries.reload(contextLayers, updatedContextTags, resourceManager, backgroundExecutor)
+ return ReloadableServerRegistries.reload(contextLayers, updatedContextTags, resourceManager, backgroundExecutor, cause) // Paper - tag lifecycle - add registrar event cause
.thenCompose(
fullRegistries -> CompletableFuture.<List<DataComponentInitializers.PendingComponents<?>>>supplyAsync(
() -> BuiltInRegistries.DATA_COMPONENT_INITIALIZERS.build(fullRegistries.lookupWithUpdatedTags()), backgroundExecutor
@@ -96,6 +_,13 @@
functionCompilationPermissions,
(List<DataComponentInitializers.PendingComponents<?>>)pendingComponents
);
+ // Paper start - call commands event for bootstraps
+ //noinspection ConstantValue
+ io.papermc.paper.plugin.lifecycle.event.LifecycleEventRunner.INSTANCE.callReloadableRegistrarEvent(
+ io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents.COMMANDS,
+ io.papermc.paper.command.brigadier.PaperCommands.INSTANCE,
+ io.papermc.paper.plugin.bootstrap.BootstrapContext.class,
+ MinecraftServer.getServer() == null ? io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL : io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.RELOAD);
+ cause);
+ // Paper end - call commands event
return SimpleReloadInstance.create(
resourceManager,
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/WorldLoader.java
+++ b/net/minecraft/server/WorldLoader.java
@@ -35,7 +_,7 @@
@@ -35,11 +_,11 @@
CloseableResourceManager resources = packsAndResourceManager.getSecond();
LayeredRegistryAccess<RegistryLayer> initialLayers = RegistryLayer.createRegistryAccess();
List<Registry.PendingTags<?>> staticLayerTags = TagLoader.loadTagsForExistingRegistries(
@@ -9,3 +9,25 @@
);
RegistryAccess.Frozen worldLoadContext = initialLayers.getAccessForLoading(RegistryLayer.WORLD);
List<HolderLookup.RegistryLookup<?>> worldContextRegistries = TagLoader.buildUpdatedLookups(worldLoadContext, staticLayerTags);
- return RegistryDataLoader.load(resources, worldContextRegistries, RegistryDataLoader.WORLD_REGISTRIES, backgroundExecutor)
+ return RegistryDataLoader.load(resources, worldContextRegistries, RegistryDataLoader.WORLD_REGISTRIES, backgroundExecutor, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL) // Paper - tag lifecycle - add cause
.thenComposeAsync(
loadedWorldRegistries -> {
List<HolderLookup.RegistryLookup<?>> dimensionContextRegistries = Stream.concat(
@@ -47,7 +_,7 @@
)
.toList();
return RegistryDataLoader.load(
- resources, dimensionContextRegistries, RegistryDataLoader.DIMENSION_REGISTRIES, backgroundExecutor
+ resources, dimensionContextRegistries, RegistryDataLoader.DIMENSION_REGISTRIES, backgroundExecutor, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL // Paper - tag lifecycle - add cause
)
.thenComposeAsync(
initialWorldgenDimensions -> {
@@ -70,6 +_,7 @@
config.functionCompilationPermissions(),
backgroundExecutor,
mainThreadExecutor
+ , io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL // Paper - add registrar event cause
)
.whenComplete((managers, throwable) -> {
if (throwable != null) {
@@ -21,15 +21,17 @@
}
public static <T> Map<TagKey<T>, List<Holder<T>>> loadTagsFromNetwork(final TagNetworkSerialization.NetworkPayload tags, final Registry<T> registry) {
@@ -120,18 +_,39 @@
@@ -120,18 +_,22 @@
}
public static List<Registry.PendingTags<?>> loadTagsForExistingRegistries(final ResourceManager manager, final RegistryAccess layer) {
- return layer.registries().map(entry -> loadPendingTags(manager, entry.value())).flatMap(Optional::stream).collect(Collectors.toUnmodifiableList());
+ // Paper start - tag lifecycle - add cause
+ return loadTagsForExistingRegistries(manager, layer, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL);
+ }
+
}
- public static <T> void loadTagsForRegistry(final ResourceManager manager, final WritableRegistry<T> registry) {
- loadTagsForRegistry(manager, registry.key(), TagLoader.ElementLookup.fromWritableRegistry(registry));
+ public static List<Registry.PendingTags<?>> loadTagsForExistingRegistries(
+ final ResourceManager manager, final RegistryAccess layer, final io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause
+ ) {
@@ -37,27 +39,10 @@
+ // Paper end - tag lifecycle - add cause
}
public static <T> void loadTagsForRegistry(final ResourceManager manager, final WritableRegistry<T> registry) {
- loadTagsForRegistry(manager, registry.key(), TagLoader.ElementLookup.fromWritableRegistry(registry));
+ // Paper start - tag lifecycle - add registrar event cause
+ loadTagsForRegistry(manager, registry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL);
+ }
+ public static <T> void loadTagsForRegistry(final ResourceManager manager, final WritableRegistry<T> registry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause) {
+ loadTagsForRegistry(manager, registry.key(), TagLoader.ElementLookup.fromWritableRegistry(registry), registry, cause);
+ // Paper end - tag lifecycle - add registrar event cause
}
public static <T> Map<TagKey<T>, List<Holder<T>>> loadTagsForRegistry(
final ResourceManager manager, final ResourceKey<? extends Registry<T>> registryKey, final TagLoader.ElementLookup<Holder<T>> lookup
- final ResourceManager manager, final ResourceKey<? extends Registry<T>> registryKey, final TagLoader.ElementLookup<Holder<T>> lookup
+ final ResourceManager manager, final ResourceKey<? extends Registry<T>> registryKey, final TagLoader.ElementLookup<Holder<T>> lookup, final WritableRegistry<T> registry, final io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause // Paper - tag lifecycle - add registrar event cause
) {
+ // Paper start - tag lifecycle - add registrar event cause
+ return loadTagsForRegistry(manager, registryKey, lookup, null, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL);
+ }
+
+ public static <T> Map<TagKey<T>, List<Holder<T>>> loadTagsForRegistry(
+ final ResourceManager manager, final ResourceKey<? extends Registry<T>> registryKey, final TagLoader.ElementLookup<Holder<T>> lookup, final WritableRegistry<T> registry, final io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause
+ ) {
+ // Paper end - tag lifecycle - add registrar event cause
TagLoader<Holder<T>> loader = new TagLoader<>(lookup, Registries.tagsDirPath(registryKey));
- return wrapTags(registryKey, loader.build(loader.load(manager)));
+ return wrapTags(registryKey, loader.build(loader.load(manager), io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.createEventConfig(registry, cause))); // Paper - tag lifecycle
@@ -10,6 +10,7 @@ import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import net.minecraft.resources.RegistryDataLoader;
import net.minecraft.resources.ResourceKey;
import org.bukkit.Keyed;
import org.bukkit.Registry;
@@ -97,14 +98,6 @@ public class PaperRegistryAccess implements RegistryAccess {
return registry;
}
public <M> void registerReloadableRegistry(final net.minecraft.core.Registry<M> registry) {
this.registerRegistry(registry, true);
}
public <M> void registerRegistry(final net.minecraft.core.Registry<M> registry) {
this.registerRegistry(registry, false);
}
public <M> void lockReferenceHolders(final ResourceKey<? extends net.minecraft.core.Registry<M>> resourceKey) {
final RegistryEntry<M, Keyed> entry = PaperRegistries.getEntry(resourceKey);
if (entry == null || !(entry.meta() instanceof final RegistryEntryMeta.ServerSide<M, Keyed> serverSide) || !serverSide.registryTypeMapper().constructorUsesHolder()) {
@@ -115,14 +108,14 @@ public class PaperRegistryAccess implements RegistryAccess {
}
@SuppressWarnings("unchecked") // this method should be called right after any new MappedRegistry instances are created to later be used by the server.
private <M, B extends Keyed, R extends Registry<B>> void registerRegistry(final net.minecraft.core.Registry<M> registry, final boolean replace) {
public <M, B extends Keyed, R extends Registry<B>> void registerRegistry(final net.minecraft.core.Registry<M> registry) {
final RegistryEntry<M, B> entry = PaperRegistries.getEntry(registry.key());
if (entry == null) { // skip registries that don't have API entries
return;
}
final RegistryHolder<B> registryHolder = (RegistryHolder<B>) this.registries.get(entry.apiKey());
if (registryHolder == null || replace) {
// if the holder doesn't exist yet, or is marked as "replaceable", put it in the map.
if (registryHolder == null || isReloadable(registry.key())) {
// if the holder doesn't exist yet, or the registry is recreated on each reload, put it in the map.
this.registries.put(entry.apiKey(), entry.createRegistryHolder(registry));
} else {
if (registryHolder instanceof RegistryHolder.Delayed<?, ?> && entry instanceof final DelayedRegistryEntry<M, B> delayedEntry) {
@@ -134,6 +127,11 @@ public class PaperRegistryAccess implements RegistryAccess {
}
}
// only called once a holder already exists, so RegistryDataLoader isn't class-loaded during BuiltInRegistries bootstrap
private static boolean isReloadable(final ResourceKey<? extends net.minecraft.core.Registry<?>> registryKey) {
return RegistryDataLoader.RELOADABLE_REGISTRIES.stream().anyMatch(data -> data.key() == registryKey);
}
@SuppressWarnings("unchecked")
@Deprecated
@VisibleForTesting
@@ -1,5 +1,6 @@
package org.bukkit.support;
import io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
@@ -75,11 +76,11 @@ public final class RegistryHelper {
List<Registry.PendingTags<?>> pendingTags = TagLoader.loadTagsForExistingRegistries(resourceManager, layers.getLayer(RegistryLayer.STATIC));
List<HolderLookup.RegistryLookup<?>> lookupsWithPendingTags = TagLoader.buildUpdatedLookups(layers.getAccessForLoading(RegistryLayer.WORLD), pendingTags);
RegistryAccess.Frozen worldGenRegistries = RegistryDataLoader.load(resourceManager, lookupsWithPendingTags, RegistryDataLoader.WORLD_REGISTRIES, Util.backgroundExecutor()).join();
RegistryAccess.Frozen worldGenRegistries = RegistryDataLoader.load(resourceManager, lookupsWithPendingTags, RegistryDataLoader.WORLD_REGISTRIES, Util.backgroundExecutor(), ReloadableRegistrarEvent.Cause.INITIAL).join();
layers = layers.replaceFrom(RegistryLayer.WORLD, worldGenRegistries);
List<HolderLookup.RegistryLookup<?>> staticAndWorldgenLookups = Stream.concat(lookupsWithPendingTags.stream(), worldGenRegistries.listRegistries()).toList();
RegistryAccess.Frozen dimensionRegistries = RegistryDataLoader.load(resourceManager, staticAndWorldgenLookups, RegistryDataLoader.DIMENSION_REGISTRIES, Util.backgroundExecutor()).join();
RegistryAccess.Frozen dimensionRegistries = RegistryDataLoader.load(resourceManager, staticAndWorldgenLookups, RegistryDataLoader.DIMENSION_REGISTRIES, Util.backgroundExecutor(), ReloadableRegistrarEvent.Cause.INITIAL).join();
layers = layers.replaceFrom(RegistryLayer.DIMENSIONS, dimensionRegistries);
// load registry here to ensure bukkit object registry are correctly delayed if needed
try {
@@ -99,7 +100,7 @@ public final class RegistryHelper {
PackedRegistries registries = createRegistries(resourceManager);
// Register vanilla packs
ReloadableServerResources datapack = ReloadableServerResources.loadResources(resourceManager, registries.layers(), registries.pendingTags(), enabledFeatures, Commands.CommandSelection.DEDICATED, LevelBasedPermissionSet.ALL_PERMISSIONS, Util.backgroundExecutor(), Runnable::run).join();
ReloadableServerResources datapack = ReloadableServerResources.loadResources(resourceManager, registries.layers(), registries.pendingTags(), enabledFeatures, Commands.CommandSelection.DEDICATED, LevelBasedPermissionSet.ALL_PERMISSIONS, Util.backgroundExecutor(), Runnable::run, ReloadableRegistrarEvent.Cause.INITIAL).join();
// Bind tags
datapack.updateComponentsAndStaticRegistryTags();
-1
View File
@@ -1,5 +1,4 @@
- Check all conversions related to API/Event for the inclusion of ConversionTracker
- ServerboundCommandSuggestionPacket - now sender split, keep old paper reduced limit for this or adopt mojangs?
- ReloadableServerRegistries - this logic all appears to have moved downstream and handled by somebody else, somebody with more familiarity with the code should check this
- BrewingRecipe for now takes any RecipeChoice, which does not represent the PotionIngredient fully.
- Run test for brigadier command suggestions for checking the last changes related to the context used