Skip to content

Commit

Permalink
Fix #3215 - Only add namespace to registries added using the Fabric A…
Browse files Browse the repository at this point in the history
…PI. (#3219)

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

* Cleanup
  • Loading branch information
modmuss50 committed Jul 25, 2023
1 parent 95a3e57 commit 95ae871
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

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<>();

Expand All @@ -61,6 +62,7 @@ public static <T> void register(RegistryKey<? extends Registry<T>> key, Codec<T>

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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 All @@ -61,11 +62,12 @@ private static void beforeLoad(ResourceManager resourceManager, DynamicRegistryM
}

// 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);
}
}
Expand Down

0 comments on commit 95ae871

Please sign in to comment.