-
Notifications
You must be signed in to change notification settings - Fork 79
/
WrenchModes.java
84 lines (72 loc) · 1.5 KB
/
WrenchModes.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
package mod.chiselsandbits.modes;
import mod.chiselsandbits.core.Log;
import mod.chiselsandbits.localization.LocalStrings;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagString;
public enum WrenchModes implements IToolMode
{
NUDGE_BIT( LocalStrings.WrenchNudgeBit ),
NUDGE_BLOCK( LocalStrings.WrenchNudgeBlock ),
ROTATE( LocalStrings.WrenchRotateBlock );
public final LocalStrings string;
public boolean isDisabled = false;
public Object binding;
private WrenchModes(
final LocalStrings str )
{
string = str;
}
public static WrenchModes getMode(
final ItemStack stack )
{
if ( stack != null )
{
try
{
final NBTTagCompound nbt = stack.getTagCompound();
if ( nbt != null && nbt.hasKey( "mode" ) )
{
return valueOf( nbt.getString( "mode" ) );
}
}
catch ( final IllegalArgumentException iae )
{
// nope!
}
catch ( final Exception e )
{
Log.logError( "Unable to determine mode.", e );
}
}
return WrenchModes.ROTATE;
}
@Override
public void setMode(
final ItemStack stack )
{
if ( stack != null )
{
stack.setTagInfo( "mode", new NBTTagString( name() ) );
}
}
public static WrenchModes castMode(
final IToolMode mode )
{
if ( mode instanceof WrenchModes )
{
return (WrenchModes) mode;
}
return WrenchModes.ROTATE;
}
@Override
public LocalStrings getName()
{
return string;
}
@Override
public boolean isDisabled()
{
return isDisabled;
}
}