Add orientation pattern

This commit is contained in:
Lixfel
2024-12-21 21:19:40 +01:00
parent a2710628a5
commit 7d9996529e
@@ -44,11 +44,9 @@ import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.BitSet;
import java.util.concurrent.ConcurrentHashMap;
public class TechHiderWrapper extends StateDependent implements TechHider.LocationEvaluator, Listener {
@@ -135,7 +133,7 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati
if(hiddenRegion.computeIfAbsent(player, this::getHiddenRegion).inRegion(x, y, z)) {
if(FightSystem.getHullHider().isBlockHidden(player, x, y, z)) {
int id = ((y&3) << 4) + ((z&3) << 2) + (x&3);
return (patterns.computeIfAbsent(player, this::getPattern) & (1L << id)) == 0 ? TechHider.State.HIDE : TechHider.State.HIDE_AIR;
return (patterns.computeIfAbsent(player, this::getPattern) & (1L << id)) == 0 ? TechHider.State.HIDE_AIR : TechHider.State.HIDE;
} else {
return TechHider.State.CHECK;
}
@@ -145,40 +143,32 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati
}
public long getPattern(Player player) {
long pattern = SteamwarUser.get(player.getUniqueId()).getId();
byte[] bytes = new byte[]{
(byte) (pattern & 0xFF),
(byte) ((pattern >>> 8) & 0xFF),
(byte) ((pattern >>> 16) & 0xFF),
(byte) ((pattern >>> 24) & 0xFF)
};
try {
byte[] bytes = new byte[6];
long id = SteamwarUser.get(player.getUniqueId()).getId();
bytes[0] = (byte) (id & 0xFF);
bytes[1] = (byte) ((id >>> 8) & 0xFF);
bytes[2] = (byte) ((id >>> 16) & 0xFF);
bytes[3] = (byte) ((id >>> 24) & 0xFF);
bytes[4] = (byte) ((id >>> 32) & 0xFF);
bytes[5] = (byte) ((id >>> 40) & 0xFF);
bytes = cipher.doFinal(bytes);
id = bytes[0] & 0xFFL |
((bytes[1] & 0xFFL) << 8) |
((bytes[2] & 0xFFL) << 16) |
((bytes[3] & 0xFFL) << 24) |
((bytes[4] & 0xFFL) << 32) |
((bytes[5] & 0xFFL) << 40);
long result = 0b0000000000000000000000000001001100000001000101110000001101110111L;
for (int i = 0; i < 64; i++) {
int mask = 1 << i;
if ((result & mask) != 0) continue;
if ((id & 1) == 1) {
result |= mask;
}
id = id >>> 1;
}
return result;
} catch (IllegalBlockSizeException | BadPaddingException e) {
throw new SecurityException(e);
}
pattern = bytes[0] & 0xFFL |
((bytes[1] & 0xFFL) << 8) |
((bytes[2] & 0xFFL) << 16) |
((bytes[3] & 0xFFL) << 24);
/* XXXO OOOX
* XXXO OOOX
* XXOX OOXO
* OOXX XXOO */
pattern |= 0b1110_1110_1101_0011___0001_0001_0010_1100___0000_0000_0000_0000___0000_0000_0000_0000L;
return pattern;
}
@Override