Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-25 15:50:14 +01:00
Do not send thunder strength if not raining (#5031)
* Do not send thunder strength if not raining * Address review * Minor optimization
Dieser Commit ist enthalten in:
Ursprung
723840c7fc
Commit
14cf104cff
@ -572,14 +572,16 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
||||
private float walkSpeed;
|
||||
|
||||
/**
|
||||
* Caches current rain status.
|
||||
* Caches current rain strength.
|
||||
* Value between 0 and 1.
|
||||
*/
|
||||
private boolean raining = false;
|
||||
private float rainStrength = 0.0f;
|
||||
|
||||
/**
|
||||
* Caches current thunder status.
|
||||
* Caches current thunder strength.
|
||||
* Value between 0 and 1.
|
||||
*/
|
||||
private boolean thunder = false;
|
||||
private float thunderStrength = 0.0f;
|
||||
|
||||
/**
|
||||
* Stores a map of all statistics sent from the server.
|
||||
@ -2023,23 +2025,30 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
||||
* @param strength value between 0 and 1
|
||||
*/
|
||||
public void updateRain(float strength) {
|
||||
this.raining = strength > 0;
|
||||
boolean wasRaining = isRaining();
|
||||
this.rainStrength = strength;
|
||||
|
||||
LevelEventPacket rainPacket = new LevelEventPacket();
|
||||
rainPacket.setType(this.raining ? LevelEvent.START_RAINING : LevelEvent.STOP_RAINING);
|
||||
rainPacket.setType(isRaining() ? LevelEvent.START_RAINING : LevelEvent.STOP_RAINING);
|
||||
rainPacket.setData((int) (strength * 65535));
|
||||
rainPacket.setPosition(Vector3f.ZERO);
|
||||
sendUpstreamPacket(rainPacket);
|
||||
|
||||
if (this.raining) {
|
||||
sendUpstreamPacket(rainPacket);
|
||||
} else {
|
||||
// The bedrock client might ignore this packet if it is sent in the same tick as another rain packet
|
||||
// https://github.com/GeyserMC/Geyser/issues/3679
|
||||
scheduleInEventLoop(() -> {
|
||||
if (!this.raining) {
|
||||
sendUpstreamPacket(rainPacket);
|
||||
}
|
||||
}, 100, TimeUnit.MILLISECONDS);
|
||||
// Keep thunder in sync with rain when starting/stopping a storm
|
||||
if ((wasRaining != isRaining()) && isThunder()) {
|
||||
if (isRaining()) {
|
||||
LevelEventPacket thunderPacket = new LevelEventPacket();
|
||||
thunderPacket.setType(LevelEvent.START_THUNDERSTORM);
|
||||
thunderPacket.setData((int) (this.thunderStrength * 65535));
|
||||
thunderPacket.setPosition(Vector3f.ZERO);
|
||||
sendUpstreamPacket(thunderPacket);
|
||||
} else {
|
||||
LevelEventPacket thunderPacket = new LevelEventPacket();
|
||||
thunderPacket.setType(LevelEvent.STOP_THUNDERSTORM);
|
||||
thunderPacket.setData(0);
|
||||
thunderPacket.setPosition(Vector3f.ZERO);
|
||||
sendUpstreamPacket(thunderPacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2050,24 +2059,28 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
||||
* @param strength value between 0 and 1
|
||||
*/
|
||||
public void updateThunder(float strength) {
|
||||
this.thunder = strength > 0;
|
||||
this.thunderStrength = strength;
|
||||
|
||||
// Do not send thunder packet if not raining
|
||||
// The bedrock client will start raining automatically when updating thunder strength
|
||||
// https://github.com/GeyserMC/Geyser/issues/3679
|
||||
if (!isRaining()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LevelEventPacket thunderPacket = new LevelEventPacket();
|
||||
thunderPacket.setType(this.thunder ? LevelEvent.START_THUNDERSTORM : LevelEvent.STOP_THUNDERSTORM);
|
||||
thunderPacket.setType(isThunder() ? LevelEvent.START_THUNDERSTORM : LevelEvent.STOP_THUNDERSTORM);
|
||||
thunderPacket.setData((int) (strength * 65535));
|
||||
thunderPacket.setPosition(Vector3f.ZERO);
|
||||
sendUpstreamPacket(thunderPacket);
|
||||
}
|
||||
|
||||
if (this.thunder) {
|
||||
sendUpstreamPacket(thunderPacket);
|
||||
} else {
|
||||
// The bedrock client might ignore this packet if it is sent in the same tick as another thunderstorm packet
|
||||
// https://github.com/GeyserMC/Geyser/issues/3679
|
||||
scheduleInEventLoop(() -> {
|
||||
if (!this.thunder) {
|
||||
sendUpstreamPacket(thunderPacket);
|
||||
}
|
||||
}, 100, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
public boolean isRaining() {
|
||||
return this.rainStrength > 0;
|
||||
}
|
||||
|
||||
public boolean isThunder() {
|
||||
return this.thunderStrength > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren