-
Notifications
You must be signed in to change notification settings - Fork 79
/
ModConflictContext.java
168 lines (143 loc) · 3.71 KB
/
ModConflictContext.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package mod.chiselsandbits.client;
import java.lang.annotation.Annotation;
import java.util.HashSet;
import java.util.Set;
import mod.chiselsandbits.api.KeyBindingContext;
import mod.chiselsandbits.core.ClientSide;
import mod.chiselsandbits.helpers.ChiselToolType;
import mod.chiselsandbits.helpers.ModUtil;
import mod.chiselsandbits.interfaces.IVoxelBlobItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraftforge.client.settings.IKeyConflictContext;
import net.minecraftforge.client.settings.KeyConflictContext;
public enum ModConflictContext implements IKeyConflictContext
{
HOLDING_ROTATEABLE
{
@Override
public boolean isActive()
{
if ( super.isActive() )
{
return true;
}
final ItemStack held = ClientSide.instance.getPlayer().getHeldItemMainhand();
return !ModUtil.isEmpty( held ) && held.getItem() instanceof IVoxelBlobItem;
}
@Override
public boolean conflicts(
final IKeyConflictContext other )
{
return this == other || other == KeyConflictContext.IN_GAME || other == HOLDING_MENUITEM;
}
},
HOLDING_MENUITEM
{
@Override
public boolean isActive()
{
if ( super.isActive() )
{
return true;
}
final ChiselToolType tool = ClientSide.instance.getHeldToolType( EnumHand.MAIN_HAND );
return tool != null && tool.hasMenu();
}
@Override
public boolean conflicts(
final IKeyConflictContext other )
{
return this == other || other == KeyConflictContext.IN_GAME || other == HOLDING_POSTIVEPATTERN || other == HOLDING_CHISEL || other == HOLDING_TAPEMEASURE;
}
},
HOLDING_TAPEMEASURE
{
@Override
public boolean isActive()
{
return super.isActive() || ClientSide.instance.getHeldToolType( EnumHand.MAIN_HAND ) == ChiselToolType.TAPEMEASURE;
}
@Override
public boolean conflicts(
final IKeyConflictContext other )
{
return this == other || other == KeyConflictContext.IN_GAME;
}
},
HOLDING_POSTIVEPATTERN
{
@Override
public boolean isActive()
{
return super.isActive() || ClientSide.instance.getHeldToolType( EnumHand.MAIN_HAND ) == ChiselToolType.POSITIVEPATTERN;
}
@Override
public boolean conflicts(
final IKeyConflictContext other )
{
return this == other || other == KeyConflictContext.IN_GAME;
}
},
HOLDING_CHISEL
{
@Override
public boolean isActive()
{
if ( super.isActive() )
{
return true;
}
final ChiselToolType tool = ClientSide.instance.getHeldToolType( EnumHand.MAIN_HAND );
return tool != null && tool.isBitOrChisel();
}
@Override
public boolean conflicts(
final IKeyConflictContext other )
{
return this == other || other == KeyConflictContext.IN_GAME;
}
};
private Set<Class<? extends Item>> activeItemClasses = new HashSet<Class<? extends Item>>();
public void setItemActive(
final Item item )
{
activeItemClasses.add( item.getClass() );
}
@Override
public boolean isActive()
{
final ItemStack held = ClientSide.instance.getPlayer().getHeldItemMainhand();
if ( ModUtil.isEmpty( held ) )
{
return false;
}
for ( Class<? extends Item> itemClass : activeItemClasses )
{
if ( itemClass.isInstance( held.getItem() ) )
{
return true;
}
}
if ( held.getItem().getClass().isAnnotationPresent( KeyBindingContext.class ) )
{
final Annotation annotation = held.getItem().getClass().getAnnotation( KeyBindingContext.class );
if ( annotation instanceof KeyBindingContext )
{
for ( String name : ( (KeyBindingContext) annotation ).value() )
{
if ( name.equals( getName() ) )
{
return true;
}
}
}
}
return false;
}
public String getName()
{
return toString().toLowerCase().replace( "holding_", "" );
}
}