Fix - Only add namespace to registries added using the Fabric API. ()

* Fix  - Only add namespace to registries added using the Fabric API.

* Cleanup
This commit is contained in:
modmuss 2023-07-25 14:03:45 +01:00 committed by modmuss50
parent 95a3e5738f
commit 95ae871652
2 changed files with 7 additions and 3 deletions
fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric
impl/registry/sync
mixin/registry/sync

View file

@ -35,6 +35,7 @@ import net.fabricmc.fabric.api.event.registry.DynamicRegistries;
public final class DynamicRegistriesImpl {
private static final List<RegistryLoader.Entry<?>> DYNAMIC_REGISTRIES = new ArrayList<>(RegistryLoader.DYNAMIC_REGISTRIES);
public static final Set<RegistryKey<?>> FABRIC_DYNAMIC_REGISTRY_KEYS = new HashSet<>();
public static final Set<RegistryKey<? extends Registry<?>>> DYNAMIC_REGISTRY_KEYS = new HashSet<>();
public static final Set<RegistryKey<? extends Registry<?>>> SKIP_EMPTY_SYNC_REGISTRIES = new HashSet<>();
@ -61,6 +62,7 @@ public final class DynamicRegistriesImpl {
var entry = new RegistryLoader.Entry<>(key, codec);
DYNAMIC_REGISTRIES.add(entry);
FABRIC_DYNAMIC_REGISTRY_KEYS.add(key);
}
public static <T> void addSyncedRegistry(RegistryKey<? extends Registry<T>> registryKey, Codec<T> networkCodec, DynamicRegistries.SyncOption... options) {

View file

@ -37,6 +37,7 @@ import net.minecraft.resource.ResourceManager;
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)
@ -61,11 +62,12 @@ public class RegistryLoaderMixin {
}
// 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 id.
// so we prepend the directories with the namespace if it's a modded registry registered using the Fabric API.
@Inject(method = "getPath", at = @At("RETURN"), cancellable = true)
private static void prependDirectoryWithNamespace(Identifier id, CallbackInfoReturnable<String> info) {
if (!id.getNamespace().equals(Identifier.DEFAULT_NAMESPACE)) {
String newPath = id.getNamespace() + "/" + info.getReturnValue();
if (!id.getNamespace().equals(Identifier.DEFAULT_NAMESPACE)
&& DynamicRegistriesImpl.FABRIC_DYNAMIC_REGISTRY_KEYS.contains(RegistryKey.ofRegistry(id))) {
final String newPath = id.getNamespace() + "/" + info.getReturnValue();
info.setReturnValue(newPath);
}
}