Global-proximity fix.

This commit is contained in:
ayunami2000 2022-07-18 23:14:42 -04:00
parent 782235327b
commit 79b87e32a2
4 changed files with 46151 additions and 46120 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1122,23 +1122,25 @@ public class Minecraft implements Runnable {
if(this.currentScreen == null || !this.currentScreen.blockHotKeys()) {
EaglerAdapter.activateVoice(EaglerAdapter.isKeyDown(gameSettings.voicePTTKey));
}
if (EaglerAdapter.getVoiceChannel() == Voice.VoiceChannel.PROXIMITY) {
if (this.theWorld != null && this.thePlayer != null) {
HashSet<String> seenPlayers = new HashSet<>();
for (Object playerObject : this.theWorld.playerEntities) {
EntityPlayer player = (EntityPlayer) playerObject;
if (player == this.thePlayer) continue;
EaglerAdapter.updateVoicePosition(player.username, player.posX, player.posY + player.getEyeHeight(), player.posZ);
int prox = EaglerAdapter.getVoiceProximity();
// cube
if (Math.abs(thePlayer.posX - player.posX) <= prox && Math.abs(thePlayer.posY - player.posY) <= prox && Math.abs(thePlayer.posZ - player.posZ) <= prox) {
if (this.theWorld != null && this.thePlayer != null) {
HashSet<String> seenPlayers = new HashSet<>();
for (Object playerObject : this.theWorld.playerEntities) {
EntityPlayer player = (EntityPlayer) playerObject;
if (player == this.thePlayer) continue;
if (EaglerAdapter.getVoiceChannel() == Voice.VoiceChannel.PROXIMITY) EaglerAdapter.updateVoicePosition(player.username, player.posX, player.posY + player.getEyeHeight(), player.posZ);
int prox = EaglerAdapter.getVoiceProximity();
// cube
if (Math.abs(thePlayer.posX - player.posX) <= prox && Math.abs(thePlayer.posY - player.posY) <= prox && Math.abs(thePlayer.posZ - player.posZ) <= prox) {
if (EaglerAdapter.getVoiceChannel() == Voice.VoiceChannel.PROXIMITY) {
EaglerAdapter.addNearbyPlayer(player.username);
seenPlayers.add(player.username);
} else if (EaglerAdapter.getVoiceChannel() == Voice.VoiceChannel.GLOBAL) {
EaglerAdapter.sendVoiceRequestIfNeeded(player.username);
}
}
EaglerAdapter.cleanupNearbyPlayers(seenPlayers);
}
if (EaglerAdapter.getVoiceChannel() == Voice.VoiceChannel.PROXIMITY) EaglerAdapter.cleanupNearbyPlayers(seenPlayers);
}
}

View File

@ -2036,7 +2036,7 @@ public class EaglerAdapterImpl2 {
for(int i = 0; i < voicePlayers.length; i++) voicePlayers[i] = streamIn.readUTF();
for (String username : voicePlayers) {
// notice that literally everyone except for those already connected using voice chat will receive the request; however, ones using proximity will simply ignore it.
if (!voiceGains.containsKey(username)) addNearbyPlayer(username);
sendVoiceRequestIfNeeded(username);
}
break;
case VOICE_SIGNAL_ALLOWED:
@ -2055,11 +2055,7 @@ public class EaglerAdapterImpl2 {
} catch (EOFException e) { // this is actually a connect ANNOUNCE, not an absolute "yes please connect" situation
if (enabledChannel == Voice.VoiceChannel.PROXIMITY && !nearbyPlayers.contains(peerId)) return;
// send request to peerId
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.write(VOICE_SIGNAL_REQUEST);
dos.writeUTF(peerId);
returnSignalHandler.accept(baos.toByteArray());
sendVoiceRequest(peerId);
}
break;
case VOICE_SIGNAL_DISCONNECT:
@ -2100,16 +2096,25 @@ public class EaglerAdapterImpl2 {
recentlyNearbyPlayers.remove(username);
if (nearbyPlayers.add(username)) {
if (getVoiceStatus() == Voice.VoiceStatus.DISCONNECTED || getVoiceStatus() == Voice.VoiceStatus.UNAVAILABLE) return;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.write(VOICE_SIGNAL_REQUEST);
dos.writeUTF(username);
returnSignalHandler.accept(baos.toByteArray());
} catch (IOException ignored) { }
sendVoiceRequest(username);
}
}
private static final void sendVoiceRequest(String username) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.write(VOICE_SIGNAL_REQUEST);
dos.writeUTF(username);
returnSignalHandler.accept(baos.toByteArray());
} catch (IOException ignored) { }
}
public static final void sendVoiceRequestIfNeeded(String username) {
if (getVoiceStatus() == Voice.VoiceStatus.DISCONNECTED || getVoiceStatus() == Voice.VoiceStatus.UNAVAILABLE) return;
if (!voiceGains.containsKey(username)) sendVoiceRequest(username);
}
private static final ExpiringSet<String> recentlyNearbyPlayers = new ExpiringSet<>(5000, new ExpiringSet.ExpiringEvent<String>() {
@Override
public void onExpiration(String username) {
@ -2134,23 +2139,20 @@ public class EaglerAdapterImpl2 {
public static final void sendInitialVoice() {
returnSignalHandler.accept(new byte[] { VOICE_SIGNAL_CONNECT });
for (String username : nearbyPlayers) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.write(VOICE_SIGNAL_REQUEST);
dos.writeUTF(username);
returnSignalHandler.accept(baos.toByteArray());
} catch (IOException ignored) { }
}
for (String username : nearbyPlayers) sendVoiceRequest(username);
}
public static final void enableVoice(Voice.VoiceChannel enable) {
if (enabledChannel == enable) return;
if (enabledChannel != Voice.VoiceChannel.NONE) {
if (enabledChannel == Voice.VoiceChannel.PROXIMITY) {
for (String username : nearbyPlayers) voiceClient.signalDisconnect(username, false);
for (String username : recentlyNearbyPlayers) voiceClient.signalDisconnect(username, false);
nearbyPlayers.clear();
recentlyNearbyPlayers.clear();
returnSignalHandler.accept(new byte[] { VOICE_SIGNAL_DISCONNECT });
} else if(enabledChannel == Voice.VoiceChannel.GLOBAL) {
Set<String> antiConcurrentModificationUsernames = new HashSet<>(voiceGains.keySet());
for (String username : antiConcurrentModificationUsernames) voiceClient.signalDisconnect(username, false);
returnSignalHandler.accept(new byte[] { VOICE_SIGNAL_DISCONNECT });
}
enabledChannel = enable;