/
ForgeRegistryWrapper.java
56 lines (46 loc) · 1.81 KB
/
ForgeRegistryWrapper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package mezz.jei.forge.platform;
import mezz.jei.common.platform.IPlatformRegistry;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.registries.ForgeRegistry;
import net.minecraftforge.registries.IForgeRegistryEntry;
import net.minecraftforge.registries.RegistryManager;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Optional;
public class ForgeRegistryWrapper<T extends IForgeRegistryEntry<T>> implements IPlatformRegistry<T> {
public static <T, V extends IForgeRegistryEntry<V>> IPlatformRegistry<T> getRegistry(ResourceKey<? extends Registry<T>> key) {
ForgeRegistry<V> registry = RegistryManager.ACTIVE.getRegistry(key.location());
IPlatformRegistry<V> registryWrapper = new ForgeRegistryWrapper<>(registry);
@SuppressWarnings("unchecked")
IPlatformRegistry<T> castRegistry = (IPlatformRegistry<T>) registryWrapper;
return castRegistry;
}
private final ForgeRegistry<T> forgeRegistry;
private ForgeRegistryWrapper(ForgeRegistry<T> forgeRegistry) {
this.forgeRegistry = forgeRegistry;
}
@Override
public Collection<T> getValues() {
return this.forgeRegistry.getValues();
}
@Nullable
@Override
public T getValue(ResourceLocation resourceLocation) {
return this.forgeRegistry.getValue(resourceLocation);
}
@Override
public int getId(T entry) {
return this.forgeRegistry.getID(entry);
}
@Override
public Optional<T> getValue(int id) {
T value = this.forgeRegistry.getValue(id);
return Optional.ofNullable(value);
}
@Override
public boolean contains(T entry) {
return this.forgeRegistry.containsValue(entry);
}
}