-
Notifications
You must be signed in to change notification settings - Fork 79
/
IMCHandlerKeyBinding.java
64 lines (56 loc) · 1.6 KB
/
IMCHandlerKeyBinding.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
package mod.chiselsandbits.core.api;
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 IMCHandlerKeyBinding implements IMCMessageHandler
{
@Override
public void excuteIMC(
final IMCMessage message )
{
try
{
String errorName = "UNKNOWN";
Item item = null;
if ( message.isStringMessage() )
{
final String name = message.getStringValue();
errorName = name;
item = Item.REGISTRY.getObject( new ResourceLocation( name ) );
// try finding the item in the mod instead...
if ( item == null )
{
errorName = message.getSender() + ":" + name;
item = Item.REGISTRY.getObject( new ResourceLocation( message.getSender(), name ) );
}
}
else if ( message.isResourceLocationMessage() )
{
errorName = message.getResourceLocationValue().toString();
item = Item.REGISTRY.getObject( message.getResourceLocationValue() );
}
else
{
Log.info( "Invalid Type for IMC: " + message.getMessageType().getName() );
return;
}
if ( item == null )
{
throw new RuntimeException( "Unable to locate item " + errorName );
}
for ( final ModConflictContext conflictContext : ModConflictContext.values() )
{
if ( conflictContext.getName().equals( message.key ) )
{
conflictContext.setItemActive( item );
}
}
}
catch ( final Throwable e )
{
Log.logError( "IMC registeritemwithkeybinding From " + message.getSender(), e );
}
}
}