From c758f70c338ffa1f1a43d48c1f0aafd1a2456b9f Mon Sep 17 00:00:00 2001 From: Tert0 <62036464+Tert0@users.noreply.github.com> Date: Mon, 10 Oct 2022 00:18:15 +0200 Subject: [PATCH] Implement Weather (#106) * implemented raining, rain level and thunder level * fix linter and cargo fmt * removed field from the client, removed weather getters, added docs, ensuring valid rain/thunder level values and sending weather changing directly * Remove results from `set_rain_level` and `set_thunder_level` * Remove unused import Co-authored-by: Ryan --- src/client.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/client.rs b/src/client.rs index 727b846..373f65e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -464,6 +464,44 @@ impl Client { self.new_game_mode = game_mode; } + /// Sets whether or not the client sees rain. + pub fn set_raining(&mut self, raining: bool) { + self.send_packet(GameEvent { + reason: if raining { + GameStateChangeReason::BeginRaining + } else { + GameStateChangeReason::EndRaining + }, + value: 0.0, + }) + } + + /// Sets the client's rain level. This changes the sky color and lightning + /// on the client. + /// + /// The rain level is clamped between `0.0.` and `1.0`. + pub fn set_rain_level(&mut self, rain_level: f32) { + self.send_packet(GameEvent { + reason: GameStateChangeReason::RainLevelChange, + value: rain_level.clamp(0.0, 1.0), + }); + } + + /// Sets the client's thunder level. This changes the sky color and + /// lightning on the client. + /// + /// For this to take effect, it must already be raining via + /// [`set_raining`](Self::set_raining) or + /// [`set_rain_level`](Self::set_rain_level). + /// + /// The thunder level is clamped between `0.0` and `1.0`. + pub fn set_thunder_level(&mut self, thunder_level: f32) { + self.send_packet(GameEvent { + reason: GameStateChangeReason::ThunderLevelChange, + value: thunder_level.clamp(0.0, 1.0), + }); + } + /// Plays a sound to the client at a given position. pub fn play_sound( &mut self,