Skip to content

Commit e81efef

Browse files
committed
Extract all bit-twiddling to MiscUtils
1 parent 9cab0c9 commit e81efef

4 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/main/java/net/evmodder/evmod/apis/MapGroupUtils.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static final UUID getIdForMapState(MapState state, boolean evict){
3838

3939
uuid = UUID.nameUUIDFromBytes(state.colors);
4040
// set 1st bit = state.locked
41-
uuid = new UUID((uuid.getMostSignificantBits() & ~1l) | (state.locked ? 1l : 0l), uuid.getLeastSignificantBits());
41+
uuid = new UUID(MiscUtils.setLSB(uuid.getMostSignificantBits(), state.locked), uuid.getLeastSignificantBits());
4242
(state.locked ? stateToIdCache : unlockedStateToIdCache).put(state.colors, uuid);
4343
return uuid;
4444
}
@@ -76,8 +76,7 @@ public static final boolean shouldHighlightNotInCurrentGroup(final MapState stat
7676
UUID uuid = getIdForMapState(state);
7777
if(currentMapGroup.contains(uuid)) return false;
7878
if( Configs.Generic.MAPART_GROUP_UNLOCKED_HANDLING.getOptionListValue() == OptionUnlockedMapHandling.UNIQUE) return true;
79-
// toggle 1st bit on/off
80-
uuid = new UUID(uuid.getMostSignificantBits() ^ 1l, uuid.getLeastSignificantBits());
79+
uuid = new UUID(MiscUtils.toggleLSB(uuid.getMostSignificantBits()), uuid.getLeastSignificantBits());
8180
return !currentMapGroup.contains(uuid);
8281
}
8382
public static final boolean isConfirmedNull(int id){return nullMapIds.contains(id);}

src/main/java/net/evmodder/evmod/apis/MapIdsFromImg.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public static final byte[] colorsFromImg(final BufferedImage img, final int xo,
135135
private static UUID getLockedIdForColors(byte[] colors){
136136
UUID uuid = UUID.nameUUIDFromBytes(colors);
137137
// set 1st bit = state.locked
138-
return new UUID(uuid.getMostSignificantBits() | 1l, uuid.getLeastSignificantBits());
138+
return new UUID(MiscUtils.setLSB(uuid.getMostSignificantBits(), true), uuid.getLeastSignificantBits());
139139
}
140140

141141
public static HashSet<UUID> getIdsFromBinaryFile(String filename){

src/main/java/net/evmodder/evmod/apis/MapStateCacher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private static final UUID getIdForPlayer(boolean invOrEc){
8585
if(e == null) return null;
8686
UUID uuid = e.getUuid();
8787
// set 1st bit, 0= is inv, 1= is ec
88-
return new UUID((uuid.getMostSignificantBits() & ~1l) | (invOrEc ? 0l : 1l), uuid.getLeastSignificantBits());
88+
return new UUID(MiscUtils.setLSB(uuid.getMostSignificantBits(), !invOrEc), uuid.getLeastSignificantBits());
8989
}
9090

9191
private static final HashMap<?, ?> getInMemCachePerServer(String server, String cache){

src/main/java/net/evmodder/evmod/apis/MiscUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public static final byte getDimensionId(final World world){
3535
else return 3;
3636
}
3737

38+
public static final long toggleLSB(final long input){return input ^ 1l;}
39+
public static final long setLSB(final long input, final boolean set){return (input & ~1l) | (set ? 1l : 0l);}
40+
// public static final long setMSB(final long input, final boolean set){return (input & ~(1l << 63)) | (set ? 1l << 63 : 0l);}
41+
3842
private static final String ADDRESS_2B2T = "2b2t.org"; // TODO: make EvMod more server-independent
3943
public static final int HASHCODE_2B2T = ADDRESS_2B2T.hashCode(); // -437714968;
4044
private static final String getServerAddress(final ServerInfo serverInfo, final boolean USE_CANONICAL_IP){

0 commit comments

Comments
 (0)