blob: c6c2d5b52e0544b0d03f9497e0845906906fc186 (
plain)
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
|
/*
* Roughly Enough Items by Danielshe.
* Licensed under the MIT License.
*/
package me.shedaniel.rei.server;
import com.google.common.collect.Maps;
import net.minecraft.container.Container;
import net.minecraft.util.Identifier;
import java.util.Map;
public class ContainerInfoHandler {
private static final Map<String, Map<Class<? extends Container>, ContainerInfo<? extends Container>>> containerInfoMap = Maps.newLinkedHashMap();
public static void registerContainerInfo(Identifier category, ContainerInfo<? extends Container> containerInfo) {
if (!containerInfoMap.containsKey(category.toString()))
containerInfoMap.put(category.toString(), Maps.newLinkedHashMap());
containerInfoMap.get(category.toString()).put(containerInfo.getContainerClass(), containerInfo);
}
public static boolean isCategoryHandled(Identifier category) {
return containerInfoMap.containsKey(category.toString()) && !containerInfoMap.get(category.toString()).isEmpty();
}
public static ContainerInfo<? extends Container> getContainerInfo(Identifier category, Class<?> containerClass) {
if (!isCategoryHandled(category))
return null;
Map<Class<? extends Container>, ContainerInfo<? extends Container>> infoMap = containerInfoMap.get(category.toString());
if (infoMap.containsKey(containerClass))
return infoMap.get(containerClass);
for (Map.Entry<Class<? extends Container>, ContainerInfo<? extends Container>> entry : infoMap.entrySet())
if (entry.getKey().isAssignableFrom(containerClass))
return entry.getValue();
return null;
}
}
|