-
Notifications
You must be signed in to change notification settings - Fork 79
/
IMCHandlerKeyBindingAnnotations.java
75 lines (63 loc) · 1.93 KB
/
IMCHandlerKeyBindingAnnotations.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package mod.chiselsandbits.core.api;
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.List;
import mod.chiselsandbits.api.KeyBindingContext;
import mod.chiselsandbits.client.ModConflictContext;
import mod.chiselsandbits.core.Log;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage;
public class IMCHandlerKeyBindingAnnotations implements IMCMessageHandler
{
@Override
public void excuteIMC(
final IMCMessage message )
{
try
{
boolean found = false;
Class<?> itemClass;
Annotation annotation;
List<String> conflictContextNames;
ResourceLocation regName;
for ( Item item : Item.REGISTRY )
{
regName = item.getRegistryName();
if ( regName == null || !regName.getResourceDomain().equals( message.getSender().toLowerCase() ) )
{
continue;
}
itemClass = item.getClass();
while ( itemClass != Item.class )
{
if ( itemClass.isAnnotationPresent( KeyBindingContext.class ) )
{
annotation = itemClass.getAnnotation( KeyBindingContext.class );
if ( annotation instanceof KeyBindingContext )
{
conflictContextNames = Arrays.asList( ( (KeyBindingContext) annotation ).value() );
for ( ModConflictContext conflictContext : ModConflictContext.values() )
{
if ( conflictContextNames.contains( conflictContext.getName() ) )
{
conflictContext.setItemActive( item );
found = true;
}
}
}
}
itemClass = itemClass.getSuperclass();
}
}
if ( !found )
{
throw new RuntimeException( "No item classes were found with a KeyBindingContext annotation that applies to sub-classes. Add one with 'applyToSubClasses = true' to do so." );
}
}
catch ( final Throwable e )
{
Log.logError( "IMC initkeybindingannotations From " + message.getSender(), e );
}
}
}