@@ -45,25 +45,25 @@ public final class BlockChangeFlagRegistryModule implements RegistryModule {
4545
4646 @ RegisterCatalog (org .spongepowered .api .world .BlockChangeFlags .class )
4747 private final Map <String , SpongeBlockChangeFlag > flags = new LinkedHashMap <>();
48- private final Int2ObjectMap < SpongeBlockChangeFlag > maskedFlags = new Int2ObjectLinkedOpenHashMap <>( 70 ) ;
48+ private final SpongeBlockChangeFlag [] maskedFlags = new SpongeBlockChangeFlag [ 64 ] ;
4949 private static BlockChangeFlagRegistryModule INSTANCE = new BlockChangeFlagRegistryModule ();
5050
5151 public static BlockChangeFlagRegistryModule getInstance () {
5252 return INSTANCE ;
5353 }
5454
5555 public static SpongeBlockChangeFlag fromNativeInt (int flag ) {
56+ if (flag >= getInstance ().maskedFlags .length ) {
57+ return (SpongeBlockChangeFlag ) org .spongepowered .api .world .BlockChangeFlags .ALL ;
58+ }
5659 if (flag == 3 ) {
5760 return (SpongeBlockChangeFlag ) org .spongepowered .api .world .BlockChangeFlags .ALL ;
5861 }
5962 if (flag == 2 ) {
6063 return (SpongeBlockChangeFlag ) org .spongepowered .api .world .BlockChangeFlags .PHYSICS_OBSERVER ;
6164 }
62- final SpongeBlockChangeFlag spongeBlockChangeFlag = getInstance ().maskedFlags .get (flag );
63- if (spongeBlockChangeFlag != null ) {
64- return spongeBlockChangeFlag ;
65- }
66- return (SpongeBlockChangeFlag ) org .spongepowered .api .world .BlockChangeFlags .ALL ;
65+ final SpongeBlockChangeFlag spongeBlockChangeFlag = getInstance ().maskedFlags [flag ];
66+ return spongeBlockChangeFlag ;
6767 }
6868
6969 public static BlockChangeFlag andNotifyClients (BlockChangeFlag flag ) {
@@ -99,28 +99,28 @@ public void registerDefaults() {
9999 for (int i = 0 ; i < 64 ; i ++) { // 64 because we get to the 6th bit of possible combinations
100100 final StringJoiner builder = new StringJoiner ("|" );
101101 if ((i & Constants .BlockChangeFlags .NEIGHBOR_MASK ) != 0 ) {
102- builder .add (Flag . NOTIFY_NEIGHBOR . name );
102+ builder .add ("NEIGHBOR" );
103103 }
104104 if ((i & Constants .BlockChangeFlags .NOTIFY_CLIENTS ) != 0 ) {
105105 // We don't want to confuse that there are going to be multiple flags
106106 // but with slight differences because of the notify flag
107- builder .add (Flag . NOTIFY_CLIENTS . name );
107+ builder .add (" NOTIFY_CLIENTS" );
108108 }
109109 if ((i & Constants .BlockChangeFlags .IGNORE_RENDER ) != 0 ) {
110110 // We don't want to confuse that there are going to be multiple flags
111111 // but with a slight difference because of the ignore render flag
112- builder .add (Flag . IGNORE_RENDER . name );
112+ builder .add (" IGNORE_RENDER" );
113113 }
114114 if ((i & Constants .BlockChangeFlags .FORCE_RE_RENDER ) != 0 ) {
115115 // We don't want to confuse that there are going to be multiple flags
116116 // but with a slight difference due to the client only flag.
117- builder .add (Flag . FORCE_RE_RENDER . name );
117+ builder .add (" FORCE_RE_RENDER" );
118118 }
119119 if ((i & Constants .BlockChangeFlags .OBSERVER_MASK ) == 0 ) {
120- builder .add (Flag . IGNORE_OBSERVER . name );
120+ builder .add ("OBSERVER" );
121121 }
122122 if ((i & Constants .BlockChangeFlags .PHYSICS_MASK ) == 0 ) {
123- builder .add (Flag . IGNORE_PHYSICS . name );
123+ builder .add ("PHYSICS" );
124124 }
125125 if (Constants .BlockChangeFlags .NONE == i ) {
126126 register (new SpongeBlockChangeFlag ("NONE" .toLowerCase (Locale .ENGLISH ), i ));
@@ -143,41 +143,15 @@ public void registerDefaults() {
143143 register (new SpongeBlockChangeFlag (builder .toString ().toLowerCase (Locale .ENGLISH ), i ));
144144 }
145145 }
146- RegistryHelper .mapFields (org .spongepowered .api .world .BlockChangeFlags .class , this .flags );
147146 }
148147
149148 private void register (SpongeBlockChangeFlag flag ) {
150- this .maskedFlags . put ( flag .getRawFlag (), flag ) ;
149+ this .maskedFlags [ flag .getRawFlag ()] = flag ;
151150 this .flags .put (flag .getName (), flag );
152151 }
153152
154153 public Collection <SpongeBlockChangeFlag > getValues () {
155154 return Collections .unmodifiableCollection (this .flags .values ());
156155 }
157156
158- public static final class Flag {
159-
160- public static final Flag NOTIFY_NEIGHBOR = new Flag ("NEIGHBOR" , Constants .BlockChangeFlags .NEIGHBOR_MASK );
161- public static final Flag NOTIFY_CLIENTS = new Flag ("NOTIFY_CLIENTS" , Constants .BlockChangeFlags .NOTIFY_CLIENTS );
162- public static final Flag IGNORE_RENDER = new Flag ("IGNORE_RENDER" , Constants .BlockChangeFlags .IGNORE_RENDER );
163- public static final Flag FORCE_RE_RENDER = new Flag ("FORCE_RE_RENDER" , Constants .BlockChangeFlags .FORCE_RE_RENDER );
164- public static final Flag IGNORE_OBSERVER = new Flag ("OBSERVER" , Constants .BlockChangeFlags .OBSERVER_MASK );
165- public static final Flag IGNORE_PHYSICS = new Flag ("PHYSICS" , Constants .BlockChangeFlags .PHYSICS_MASK );
166-
167- private static final ImmutableList <Flag > flags = ImmutableList .of (NOTIFY_NEIGHBOR , NOTIFY_CLIENTS , IGNORE_RENDER , FORCE_RE_RENDER , IGNORE_OBSERVER , IGNORE_PHYSICS );
168-
169- private final String name ;
170- private final int mask ;
171-
172- public static Collection <Flag > values () {
173- return flags ;
174- }
175-
176- private Flag (String name , int mask ) {
177- this .name = name ;
178- this .mask = mask ;
179- }
180-
181- }
182-
183157}
0 commit comments