Skip to content

Commit 81fa1b2

Browse files
committed
Add javadocs.
Signed-off-by: 秋雨落 <i@rain.cx>
1 parent e242d89 commit 81fa1b2

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

‎src/main/java/games/moegirl/sinocraft/sinocore/api/registry/RegistryBuilder.java‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package games.moegirl.sinocraft.sinocore.api.registry;
22

3-
import games.moegirl.sinocraft.sinocore.platform.RegistryPlatform;
43
import lombok.Getter;
54
import net.minecraft.core.Registry;
65
import net.minecraft.resources.ResourceKey;
76

87
/**
98
* A builder for creating custom registries.
9+
*
1010
* @param <T> Registry entry type.
1111
* @see RegistryManager#createRegistry(RegistryBuilder)
1212
*/
@@ -20,10 +20,21 @@ public RegistryBuilder(ResourceKey<Registry<T>> key) {
2020
this.key = key;
2121
}
2222

23+
/**
24+
* Set the registry to be synchronized to client.
25+
*
26+
* @return this
27+
*/
2328
public RegistryBuilder<T> sync() {
2429
return sync(true);
2530
}
2631

32+
/**
33+
* Set whether the registry should be synchronized to client.
34+
*
35+
* @param value Whether to sync.
36+
* @return this
37+
*/
2738
public RegistryBuilder<T> sync(boolean value) {
2839
this.sync = value;
2940
return this;

‎src/main/java/games/moegirl/sinocraft/sinocore/api/registry/RegistryManager.java‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ private static <T, U extends IRegistrable<T>> U appendRegistrable(Map<String, Li
4343
return registrable;
4444
}
4545

46+
/**
47+
* Get all registries created by SinoCore for a mod and registry key.
48+
*
49+
* @param modId Mod Id.
50+
* @param key Registry key.
51+
* @param <T> Registry entry type.
52+
* @param <U> Registry type.
53+
* @return List of registries.
54+
*/
4655
@SuppressWarnings("unchecked")
4756
public static <T, U extends IRegistryBase<T>> List<U> getRegistries(String modId, ResourceKey<Registry<T>> key) {
4857
if (!REGISTRIES.containsKey(modId)) {
@@ -59,27 +68,62 @@ public static <T, U extends IRegistryBase<T>> List<U> getRegistries(String modId
5968
.build();
6069
}
6170

71+
/**
72+
* Check if a registry exists.
73+
*
74+
* @param key Registry key.
75+
* @param <T> Registry entry type.
76+
* @return true if exists.
77+
*/
6278
public static <T> boolean hasRegistry(ResourceKey<Registry<T>> key) {
6379
if (!key.isFor(BuiltInRegistries.REGISTRY.key())) {
6480
return false;
6581
}
6682
return BuiltInRegistries.REGISTRY.containsKey(key.location());
6783
}
6884

85+
/**
86+
* Get a registry by its key.
87+
*
88+
* @param key Registry key.
89+
* @param <T> Registry entry type.
90+
* @return The registry, or null if not found.
91+
*/
6992
@Nullable
7093
@SuppressWarnings("unchecked")
7194
public static <T> Registry<T> getRegistry(ResourceKey<Registry<T>> key) {
7295
return (Registry<T>) BuiltInRegistries.REGISTRY.get(key.location());
7396
}
7497

98+
/**
99+
* Create a new registry (sync by default).
100+
*
101+
* @param key Registry key.
102+
* @param <T> Registry entry type.
103+
* @return The created registry.
104+
*/
75105
public static <T> Registry<T> createRegistry(ResourceKey<Registry<T>> key) {
76106
return createRegistry(new RegistryBuilder<>(key).sync());
77107
}
78108

109+
/**
110+
* Create a new registry.
111+
*
112+
* @param builder Registry builder.
113+
* @param <T> Registry entry type.
114+
* @return The created registry.
115+
*/
79116
public static <T> Registry<T> createRegistry(RegistryBuilder<T> builder) {
80117
return RegistryPlatform.createRegistry(builder);
81118
}
82119

120+
/**
121+
* Get if the registry exists, otherwise create a new one (sync by default).
122+
*
123+
* @param key Registry key.
124+
* @param <T> Registry entry type.
125+
* @return The registry.
126+
*/
83127
public static <T> Registry<T> getOrCreateRegistry(ResourceKey<Registry<T>> key) {
84128
Registry<T> registry = getRegistry(key);
85129
if (registry != null) {

0 commit comments

Comments
 (0)