21
21
import net .minecraft .world .World ;
22
22
import net .minecraftforge .fml .relauncher .Side ;
23
23
import net .minecraftforge .fml .relauncher .SideOnly ;
24
- import org .dimdev .utils .LeftIdentityPair ;
24
+ import org .dimdev .utils .Pair ;
25
25
26
26
import javax .annotation .Nullable ;
27
- import java .util .*;
27
+ import java .util .Collection ;
28
+ import java .util .HashMap ;
29
+ import java .util .List ;
30
+ import java .util .Map ;
28
31
29
32
/**
30
33
* An implementation of IBlockState which stores the properties in a bitfield rather
35
38
*/
36
39
@ SuppressWarnings ("deprecation" )
37
40
public class NumericalBlockState extends BlockStateBase {
38
- private static final Map <LeftIdentityPair <BlockStateContainer , Integer >, NumericalBlockState > blockStates = new HashMap <>(); // TODO: WeakHashMap?
39
- private static final Map <LeftIdentityPair <IProperty <?>, Comparable <?>>, Integer > valueToNumber = new HashMap <>();
40
- private static final Map <LeftIdentityPair <IProperty <?>, Integer >, Comparable <?>> numberToValue = new HashMap <>();
41
- private static final Map <IProperty <?>, Integer > propertyWidths = new IdentityHashMap <>();
41
+ private static final Map <Pair <BlockStateContainer , Integer >, NumericalBlockState > blockStates = new HashMap <>(); // TODO: WeakHashMap?
42
+ private static final Map <Pair <IProperty <?>, Comparable <?>>, Integer > valueToNumber = new HashMap <>();
43
+ private static final Map <Pair <IProperty <?>, Integer >, Comparable <?>> numberToValue = new HashMap <>();
44
+ private static final Map <IProperty <?>, Integer > propertyWidths = new HashMap <>();
42
45
43
46
protected final BlockStateContainer container ;
44
47
protected final Block block ;
@@ -54,7 +57,7 @@ public static NumericalBlockState get(BlockStateContainer container, int data) {
54
57
// Getting it from a cache is necessary to make sure == between two NumericalBlockStates
55
58
// with the same container and data will work. The cache is shared for all containers
56
59
// to avoid the overhead of many small HashMaps.
57
- LeftIdentityPair <BlockStateContainer , Integer > key = new LeftIdentityPair <>(container , data );
60
+ Pair <BlockStateContainer , Integer > key = new Pair <>(container , data );
58
61
NumericalBlockState blockState = blockStates .get (key );
59
62
60
63
if (blockState == null ) {
@@ -71,7 +74,7 @@ public static NumericalBlockState fromPropertyValueMap(BlockStateContainer conta
71
74
int data = 0 ;
72
75
for (Map .Entry <IProperty <?>, Comparable <?>> entry : map .entrySet ()) {
73
76
IProperty <?> property = entry .getKey ();
74
- data |= valueToNumber .get (new LeftIdentityPair <>(property , entry .getValue ())) << offsets .get (property );
77
+ data |= valueToNumber .get (new Pair <>(property , entry .getValue ())) << offsets .get (property );
75
78
}
76
79
77
80
return get (container , data );
@@ -88,8 +91,8 @@ public static <T extends Comparable<T>> void makePropertyInfo(IProperty<T> prope
88
91
// Fill the 'number -> value' and 'value -> number' maps
89
92
int i = 0 ;
90
93
for (T value : allowedValues ) {
91
- numberToValue .put (new LeftIdentityPair <>(property , i ), value );
92
- valueToNumber .put (new LeftIdentityPair <>(property , value ), i );
94
+ numberToValue .put (new Pair <>(property , i ), value );
95
+ valueToNumber .put (new Pair <>(property , value ), i );
93
96
i ++;
94
97
}
95
98
}
@@ -109,7 +112,7 @@ public <T extends Comparable<T>> T getValue(IProperty<T> property) {
109
112
110
113
int width = propertyWidths .get (property );
111
114
int number = data >>> offset & 0xFFFFFFFF >>> 32 - width ;
112
- Comparable <?> value = numberToValue .get (new LeftIdentityPair <>(property , number ));
115
+ Comparable <?> value = numberToValue .get (new Pair <>(property , number ));
113
116
114
117
return property .getValueClass ().cast (value );
115
118
}
@@ -122,7 +125,7 @@ public <T extends Comparable<T>, V extends T> IBlockState withProperty(IProperty
122
125
throw new IllegalArgumentException ("Cannot set property " + property + " as it does not exist in " + container );
123
126
}
124
127
125
- int number = valueToNumber .get (new LeftIdentityPair <>(property , value ));
128
+ int number = valueToNumber .get (new Pair <>(property , value ));
126
129
int width = propertyWidths .get (property );
127
130
int mask = (0xFFFFFFFF >>> offset & 0xFFFFFFFF >>> 32 - width ) << offset ;
128
131
int newData = data & ~mask | number << offset ;
0 commit comments