Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make dynamic registry element path include namespace #4180

Open
wants to merge 4 commits into
base: 1.21.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends Registry<?>> 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<? extends Registry<?>> registryRef) {
Identifier id = registryRef.getValue();

if (!id.getNamespace().equals(Identifier.DEFAULT_NAMESPACE)) {
return "tags/" + id.getNamespace() + "/" + id.getPath();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -79,27 +77,4 @@ private static void beforeLoad(@Coerce Object registryLoadable, List<RegistryWra

DynamicRegistrySetupCallback.EVENT.invoker().onRegistrySetup(new DynamicRegistryViewImpl(registries));
}

// Vanilla doesn't mark namespaces in the directories of dynamic registries at all,
// so we prepend the directories with the namespace if it's a modded registry registered using the Fabric API.
@WrapOperation(
method = {
"loadFromNetwork(Ljava/util/Map;Lnet/minecraft/resource/ResourceFactory;Lnet/minecraft/registry/RegistryOps$RegistryInfoGetter;Lnet/minecraft/registry/MutableRegistry;Lcom/mojang/serialization/Decoder;Ljava/util/Map;)V",
"loadFromResource(Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/registry/RegistryOps$RegistryInfoGetter;Lnet/minecraft/registry/MutableRegistry;Lcom/mojang/serialization/Decoder;Ljava/util/Map;)V"
},
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/registry/RegistryKeys;getPath(Lnet/minecraft/registry/RegistryKey;)Ljava/lang/String;"
)
)
private static String prependDirectoryWithNamespace(RegistryKey<? extends Registry<?>> registryKey, Operation<String> 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;
}
}