diff --git a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/RegistryKeysMixin.java b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/RegistryKeysMixin.java index 50e5b9f2aa..e0ab71e070 100644 --- a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/RegistryKeysMixin.java +++ b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/RegistryKeysMixin.java @@ -26,15 +26,25 @@ import net.minecraft.registry.RegistryKeys; import net.minecraft.util.Identifier; +// Vanilla doesn't mark namespaces in the directories of tags and dynamic registry elements at all, +// so we prepend the directories with the namespace if it's a modded registry id. @Mixin(RegistryKeys.class) public class RegistryKeysMixin { - @ModifyReturnValue(method = "getTagPath", at = @At("RETURN")) + @ModifyReturnValue(method = "getPath", at = @At("RETURN")) private static String prependDirectoryWithNamespace(String original, @Local(argsOnly = true) RegistryKey> registryRef) { Identifier id = registryRef.getValue(); - // Vanilla doesn't mark namespaces in the directories of tags at all, - // so we prepend the directories with the namespace if it's a modded registry id. - // No need to check DIRECTORIES, since this is only used by vanilla registries. + if (!id.getNamespace().equals(Identifier.DEFAULT_NAMESPACE)) { + return id.getNamespace() + "/" + id.getPath(); + } + + return original; + } + + @ModifyReturnValue(method = "getTagPath", at = @At("RETURN")) + private static String prependTagDirectoryWithNamespace(String original, @Local(argsOnly = true) RegistryKey> registryRef) { + Identifier id = registryRef.getValue(); + if (!id.getNamespace().equals(Identifier.DEFAULT_NAMESPACE)) { return "tags/" + id.getNamespace() + "/" + id.getPath(); } diff --git a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/RegistryLoaderMixin.java b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/RegistryLoaderMixin.java index 9a897cc8c2..4801314cc1 100644 --- a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/RegistryLoaderMixin.java +++ b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/RegistryLoaderMixin.java @@ -35,10 +35,8 @@ import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryLoader; import net.minecraft.registry.RegistryWrapper; -import net.minecraft.util.Identifier; import net.fabricmc.fabric.api.event.registry.DynamicRegistrySetupCallback; -import net.fabricmc.fabric.impl.registry.sync.DynamicRegistriesImpl; import net.fabricmc.fabric.impl.registry.sync.DynamicRegistryViewImpl; @Mixin(RegistryLoader.class) @@ -79,27 +77,4 @@ private static void beforeLoad(@Coerce Object registryLoadable, List> registryKey, Operation original) { - String originalDirectory = original.call(registryKey); - Identifier id = registryKey.getValue(); - if (!id.getNamespace().equals(Identifier.DEFAULT_NAMESPACE) - && DynamicRegistriesImpl.FABRIC_DYNAMIC_REGISTRY_KEYS.contains(registryKey)) { - return id.getNamespace() + "/" + originalDirectory; - } - - return originalDirectory; - } } diff --git a/fabric-registry-sync-v0/src/test/java/net/fabricmc/fabric/test/registry/sync/RegistryKeysTest.java b/fabric-registry-sync-v0/src/test/java/net/fabricmc/fabric/test/registry/sync/RegistryKeysTest.java new file mode 100644 index 0000000000..a7eb2110ef --- /dev/null +++ b/fabric-registry-sync-v0/src/test/java/net/fabricmc/fabric/test/registry/sync/RegistryKeysTest.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.test.registry.sync; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import net.minecraft.Bootstrap; +import net.minecraft.SharedConstants; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.Identifier; + +public class RegistryKeysTest { + private static final RegistryKey> TEST_KEY = RegistryKey.ofRegistry(Identifier.of("registry-keys", "test")); + + @BeforeAll + static void beforeAll() { + SharedConstants.createGameVersion(); + Bootstrap.initialize(); + } + + @Test + void getPath() { + assertEquals("item", RegistryKeys.getPath(RegistryKeys.ITEM)); + assertEquals("registry-keys/test", RegistryKeys.getPath(TEST_KEY)); + } + + @Test + void getTagPath() { + assertEquals("tags/item", RegistryKeys.getTagPath(RegistryKeys.ITEM)); + assertEquals("tags/registry-keys/test", RegistryKeys.getTagPath(TEST_KEY)); + } +}