|
3 | 3 | import dev.latvian.mods.kubejs.DevProperties; |
4 | 4 | import dev.latvian.mods.kubejs.KubeJS; |
5 | 5 | import dev.latvian.mods.kubejs.plugin.builtin.wrapper.JavaWrapper; |
| 6 | +import dev.latvian.mods.kubejs.util.Cast; |
6 | 7 | import dev.latvian.mods.rhino.type.TypeInfo; |
7 | 8 | import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; |
8 | 9 | import net.minecraft.Util; |
@@ -42,33 +43,26 @@ public static synchronized <T> void register(ResourceKey<Registry<T>> key, TypeI |
42 | 43 | } |
43 | 44 |
|
44 | 45 | @Nullable |
45 | | - public static synchronized RegistryType<?> ofKey(ResourceKey<?> key) { |
46 | | - return (RegistryType<?>) of(key); |
| 46 | + public static synchronized <T> RegistryType<T> ofKey(ResourceKey<? extends Registry<T>> key) { |
| 47 | + Scanner.startIfNotFrozen(); |
| 48 | + return Cast.to(KEY_MAP.get(key)); |
47 | 49 | } |
48 | 50 |
|
49 | 51 | @Nullable |
50 | 52 | public static synchronized RegistryType<?> ofType(TypeInfo typeInfo) { |
51 | | - return (RegistryType<?>) of(typeInfo); |
| 53 | + Scanner.startIfNotFrozen(); |
| 54 | + return TYPE_MAP.get(typeInfo); |
52 | 55 | } |
53 | 56 |
|
54 | 57 | @Nullable |
55 | | - public static synchronized RegistryType<?> ofClass(Class<?> type) { |
56 | | - var regList = ((List<RegistryType<?>>) of(type)); |
| 58 | + public static synchronized <T> RegistryType<T> ofClass(Class<T> type) { |
| 59 | + var regList = allOfClass(type); |
57 | 60 | return regList != null && regList.size() == 1 ? regList.getFirst() : null; |
58 | 61 | } |
59 | 62 |
|
60 | | - public static synchronized List<RegistryType<?>> allOfClass(Class<?> type) { |
61 | | - return (List<RegistryType<?>>) of(type); |
62 | | - } |
63 | | - |
64 | | - private static synchronized Object of(Object obj) { |
| 63 | + public static synchronized <T> List<RegistryType<T>> allOfClass(Class<T> type) { |
65 | 64 | Scanner.startIfNotFrozen(); |
66 | | - return switch (obj) { |
67 | | - case ResourceKey key -> KEY_MAP.get(key); |
68 | | - case Class clazz -> CLASS_MAP.getOrDefault(clazz, List.of()); |
69 | | - case TypeInfo info -> TYPE_MAP.get(info); |
70 | | - default -> List.of(); |
71 | | - }; |
| 65 | + return Cast.to(CLASS_MAP.getOrDefault(type, List.of())); |
72 | 66 | } |
73 | 67 |
|
74 | 68 | @Nullable |
|
0 commit comments