From c2ece0401de55fe00532719bc60913ac4aff8af6 Mon Sep 17 00:00:00 2001 From: deirn Date: Tue, 24 Aug 2021 23:44:25 +0700 Subject: [PATCH] Fix DynamicRegistryManager being initialized too early (#1660) --- .../impl/tag/extension/TagFactoryImpl.java | 30 +++++++++---------- .../tag/extension/MixinTagManagerLoader.java | 2 +- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/fabric-tag-extensions-v0/src/main/java/net/fabricmc/fabric/impl/tag/extension/TagFactoryImpl.java b/fabric-tag-extensions-v0/src/main/java/net/fabricmc/fabric/impl/tag/extension/TagFactoryImpl.java index 7e055fb5b..01c1c3d0c 100644 --- a/fabric-tag-extensions-v0/src/main/java/net/fabricmc/fabric/impl/tag/extension/TagFactoryImpl.java +++ b/fabric-tag-extensions-v0/src/main/java/net/fabricmc/fabric/impl/tag/extension/TagFactoryImpl.java @@ -17,9 +17,7 @@ package net.fabricmc.fabric.impl.tag.extension; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import java.util.function.Supplier; import com.google.common.base.Preconditions; @@ -50,7 +48,6 @@ public final class TagFactoryImpl implements TagFactory { private static final Logger LOGGER = LogManager.getLogger(); public static final Map>, RequiredTagList> TAG_LISTS = new HashMap<>(); - public static final Set> DYNAMICS = new HashSet<>(); public static TagFactory of(Supplier> tagGroupSupplier) { return new TagFactoryImpl<>(tagGroupSupplier); @@ -68,11 +65,6 @@ public final class TagFactoryImpl implements TagFactory { } else { tagList = RequiredTagListRegistry.register(registryKey, dataType); TAG_LISTS.put(registryKey, tagList); - - // Check whether the registry dynamic. - if (DynamicRegistryManagerAccessor.getInfos().containsKey(registryKey)) { - DYNAMICS.add(tagList); - } } return of(tagList::getGroup); @@ -91,14 +83,16 @@ public final class TagFactoryImpl implements TagFactory { Stopwatch stopwatch = Stopwatch.createStarted(); int loadedTags = 0; - for (RequiredTagList tagList : DYNAMICS) { - RegistryKey> registryKey = tagList.getRegistryKey(); - Registry registry = registryManager.get(registryKey); - TagGroupLoader tagGroupLoader = new TagGroupLoader<>(registry::getOrEmpty, tagList.getDataType()); - TagGroup tagGroup = tagGroupLoader.load(resourceManager); - ((FabricTagManagerHooks) ServerTagManagerHolder.getTagManager()).fabric_addTagGroup(registryKey, tagGroup); - tagList.updateTagManager(ServerTagManagerHolder.getTagManager()); - loadedTags += tagGroup.getTags().size(); + for (RequiredTagList tagList : TAG_LISTS.values()) { + if (isDynamic(tagList)) { + RegistryKey> registryKey = tagList.getRegistryKey(); + Registry registry = registryManager.get(registryKey); + TagGroupLoader tagGroupLoader = new TagGroupLoader<>(registry::getOrEmpty, tagList.getDataType()); + TagGroup tagGroup = tagGroupLoader.load(resourceManager); + ((FabricTagManagerHooks) ServerTagManagerHolder.getTagManager()).fabric_addTagGroup(registryKey, tagGroup); + tagList.updateTagManager(ServerTagManagerHolder.getTagManager()); + loadedTags += tagGroup.getTags().size(); + } } if (loadedTags > 0) { @@ -106,6 +100,10 @@ public final class TagFactoryImpl implements TagFactory { } } + public static boolean isDynamic(RequiredTagList tagList) { + return DynamicRegistryManagerAccessor.getInfos().containsKey(tagList.getRegistryKey()); + } + private final Supplier> tagGroupSupplier; private TagFactoryImpl(Supplier> tagGroupSupplier) { diff --git a/fabric-tag-extensions-v0/src/main/java/net/fabricmc/fabric/mixin/tag/extension/MixinTagManagerLoader.java b/fabric-tag-extensions-v0/src/main/java/net/fabricmc/fabric/mixin/tag/extension/MixinTagManagerLoader.java index 5562365ba..98c806272 100644 --- a/fabric-tag-extensions-v0/src/main/java/net/fabricmc/fabric/mixin/tag/extension/MixinTagManagerLoader.java +++ b/fabric-tag-extensions-v0/src/main/java/net/fabricmc/fabric/mixin/tag/extension/MixinTagManagerLoader.java @@ -37,7 +37,7 @@ public abstract class MixinTagManagerLoader { @Inject(method = "method_33179", at = @At("HEAD"), cancellable = true) private void method_33179(ResourceManager resourceManager, Executor executor, List list, RequiredTagList requiredTagList, CallbackInfo ci) { // Don't load dynamic registry tags now, we need to load them after the dynamic registry. - if (TagFactoryImpl.DYNAMICS.contains(requiredTagList)) { + if (TagFactoryImpl.isDynamic(requiredTagList)) { ci.cancel(); } }