Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.

Commit c7e615e

Browse files
feat(registry): AutomaticDynamicRegistryProvider
1 parent 8ead3b1 commit c7e615e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package dev.spiritstudios.specter.api.registry;
2+
3+
import java.util.concurrent.CompletableFuture;
4+
5+
import net.minecraft.registry.Registry;
6+
import net.minecraft.registry.RegistryKey;
7+
import net.minecraft.registry.RegistryWrapper;
8+
9+
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
10+
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
11+
import net.fabricmc.fabric.api.datagen.v1.provider.FabricDynamicRegistryProvider;
12+
13+
public abstract class AutomaticDynamicRegistryProvider<T> extends FabricDynamicRegistryProvider {
14+
private final RegistryKey<Registry<T>> registryKey;
15+
private final String namespace;
16+
17+
public AutomaticDynamicRegistryProvider(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> registriesFuture, RegistryKey<Registry<T>> registryKey, String namespace) {
18+
super(output, registriesFuture);
19+
this.registryKey = registryKey;
20+
this.namespace = namespace;
21+
}
22+
23+
@Override
24+
protected void configure(RegistryWrapper.WrapperLookup wrapperLookup, Entries entries) {
25+
RegistryWrapper<T> wrapper = wrapperLookup.getOrThrow(registryKey);
26+
27+
wrapper.streamKeys()
28+
.filter(key -> key.getValue().getNamespace().equals(namespace))
29+
.forEach(key -> entries.add(key, wrapper.getOrThrow(key).value()));
30+
}
31+
32+
public static <T> FabricDataGenerator.Pack.RegistryDependentFactory<AutomaticDynamicRegistryProvider<T>> factory(RegistryKey<Registry<T>> registryKey, String namespace) {
33+
return (output, registriesFuture) -> new AutomaticDynamicRegistryProvider<>(output, registriesFuture, registryKey, namespace) {
34+
@Override
35+
public String getName() {
36+
return "Dynamic Registry Entries for " + registryKey.getValue();
37+
}
38+
};
39+
}
40+
}

0 commit comments

Comments
 (0)