Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 00:00:41 +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;
|
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.
|
* 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
|
* @param strength value between 0 and 1
|
||||||
*/
|
*/
|
||||||
public void updateRain(float strength) {
|
public void updateRain(float strength) {
|
||||||
this.raining = strength > 0;
|
boolean wasRaining = isRaining();
|
||||||
|
this.rainStrength = strength;
|
||||||
|
|
||||||
LevelEventPacket rainPacket = new LevelEventPacket();
|
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.setData((int) (strength * 65535));
|
||||||
rainPacket.setPosition(Vector3f.ZERO);
|
rainPacket.setPosition(Vector3f.ZERO);
|
||||||
|
sendUpstreamPacket(rainPacket);
|
||||||
|
|
||||||
if (this.raining) {
|
// Keep thunder in sync with rain when starting/stopping a storm
|
||||||
sendUpstreamPacket(rainPacket);
|
if ((wasRaining != isRaining()) && isThunder()) {
|
||||||
} else {
|
if (isRaining()) {
|
||||||
// The bedrock client might ignore this packet if it is sent in the same tick as another rain packet
|
LevelEventPacket thunderPacket = new LevelEventPacket();
|
||||||
// https://github.com/GeyserMC/Geyser/issues/3679
|
thunderPacket.setType(LevelEvent.START_THUNDERSTORM);
|
||||||
scheduleInEventLoop(() -> {
|
thunderPacket.setData((int) (this.thunderStrength * 65535));
|
||||||
if (!this.raining) {
|
thunderPacket.setPosition(Vector3f.ZERO);
|
||||||
sendUpstreamPacket(rainPacket);
|
sendUpstreamPacket(thunderPacket);
|
||||||
}
|
} else {
|
||||||
}, 100, TimeUnit.MILLISECONDS);
|
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
|
* @param strength value between 0 and 1
|
||||||
*/
|
*/
|
||||||
public void updateThunder(float strength) {
|
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();
|
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.setData((int) (strength * 65535));
|
||||||
thunderPacket.setPosition(Vector3f.ZERO);
|
thunderPacket.setPosition(Vector3f.ZERO);
|
||||||
|
sendUpstreamPacket(thunderPacket);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.thunder) {
|
public boolean isRaining() {
|
||||||
sendUpstreamPacket(thunderPacket);
|
return this.rainStrength > 0;
|
||||||
} 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
|
public boolean isThunder() {
|
||||||
scheduleInEventLoop(() -> {
|
return this.thunderStrength > 0;
|
||||||
if (!this.thunder) {
|
|
||||||
sendUpstreamPacket(thunderPacket);
|
|
||||||
}
|
|
||||||
}, 100, TimeUnit.MILLISECONDS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren