Skip to content

Commit 1fd65ed

Browse files
Add generic bounds to RegistryType
1 parent 927fdc1 commit 1fd65ed

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

src/main/java/dev/latvian/mods/kubejs/recipe/component/TagKeyComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private static TagKeyComponent<?> of(ResourceKey<? extends Registry<?>> registry
5151
} else if (key == Registries.FLUID) {
5252
return (TagKeyComponent<?>) (hashed ? HASHED_FLUID : FLUID).instance();
5353
} else {
54-
var r = RegistryType.ofKey(registry);
54+
var r = RegistryType.ofKey(key);
5555
return new TagKeyComponent<>(null, key, r != null ? r.type() : TypeInfo.NONE, hashed);
5656
}
5757
}

src/main/java/dev/latvian/mods/kubejs/registry/RegistryType.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import dev.latvian.mods.kubejs.DevProperties;
44
import dev.latvian.mods.kubejs.KubeJS;
55
import dev.latvian.mods.kubejs.plugin.builtin.wrapper.JavaWrapper;
6+
import dev.latvian.mods.kubejs.util.Cast;
67
import dev.latvian.mods.rhino.type.TypeInfo;
78
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
89
import net.minecraft.Util;
@@ -42,33 +43,26 @@ public static synchronized <T> void register(ResourceKey<Registry<T>> key, TypeI
4243
}
4344

4445
@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));
4749
}
4850

4951
@Nullable
5052
public static synchronized RegistryType<?> ofType(TypeInfo typeInfo) {
51-
return (RegistryType<?>) of(typeInfo);
53+
Scanner.startIfNotFrozen();
54+
return TYPE_MAP.get(typeInfo);
5255
}
5356

5457
@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);
5760
return regList != null && regList.size() == 1 ? regList.getFirst() : null;
5861
}
5962

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) {
6564
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()));
7266
}
7367

7468
@Nullable

0 commit comments

Comments
 (0)