summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs6
-rw-r--r--src/to_clt.rs39
-rw-r--r--src/to_clt/env.rs14
-rw-r--r--src/to_clt/hud.rs6
-rw-r--r--src/to_clt/sky.rs192
5 files changed, 219 insertions, 38 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 644d25e..36ffec9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,7 @@
#![feature(iterator_try_collect)]
+pub use mt_ser;
+
#[cfg(feature = "random")]
pub use generate_random;
@@ -9,8 +11,6 @@ pub use rand;
#[cfg(feature = "serde")]
pub use serde;
-pub use mt_ser;
-
use enumset::{EnumSet, EnumSetType};
use mt_ser::mt_derive;
use std::{
@@ -19,7 +19,7 @@ use std::{
};
#[cfg(any(feature = "client", feature = "server"))]
-use mt_ser::{DefCfg, DeserializeError, MtCfg, MtDeserialize, MtSerialize, SerializeError, Utf16};
+use mt_ser::{DefCfg, MtCfg, MtDeserialize, MtSerialize, Utf16};
#[cfg(feature = "random")]
use generate_random::GenerateRandom;
diff --git a/src/to_clt.rs b/src/to_clt.rs
index ce6216d..9aa9196 100644
--- a/src/to_clt.rs
+++ b/src/to_clt.rs
@@ -22,12 +22,14 @@ mod chat;
mod env;
mod hud;
mod media;
+mod sky;
mod status;
pub use chat::*;
pub use env::*;
pub use hud::*;
pub use media::*;
+pub use sky::*;
pub use status::*;
#[mt_derive(to = "clt", repr = "u16", tag = "type", content = "data")]
@@ -81,7 +83,7 @@ pub enum ToCltPkt {
vel: [f32; 3],
} = 43,
MediaPush {
- no_len_hash: String,
+ raw_hash: String,
filename: String,
callback_token: u32,
should_cache: bool,
@@ -255,8 +257,7 @@ pub enum ToCltPkt {
Breath {
breath: u16,
} = 78,
- // TODO
- SkyParams = 79,
+ SkyParams(SkyParams) = 79,
OverrideDayNightRatio {
#[serde(rename = "override")]
ratio_override: bool,
@@ -276,14 +277,7 @@ pub enum ToCltPkt {
RemoveParticleSpawner {
id: u32,
} = 83,
- CloudParams {
- density: f32,
- diffuse_color: Color,
- ambient_color: Color,
- height: f32,
- thickness: f32,
- speed: [f32; 2],
- } = 84,
+ CloudParams(CloudParams) = 84,
FadeSound {
id: u32,
step: f32,
@@ -306,26 +300,9 @@ pub enum ToCltPkt {
#[mt(size = "u32")]
changed: HashMap<[i16; 3], NodeMeta>,
} = 89,
- SunParams {
- visible: bool,
- texture: String,
- tone_map: String,
- rise: String,
- rising: bool,
- size: f32,
- } = 90,
- MoonParams {
- visible: bool,
- texture: String,
- tone_map: String,
- size: f32,
- } = 91,
- StarParams {
- visible: bool,
- count: u32,
- color: Color,
- size: f32,
- } = 92,
+ SunParams(SunParams) = 90,
+ MoonParams(MoonParams) = 91,
+ StarParams(StarParams) = 92,
SrpBytesSaltB {
salt: Vec<u8>,
b: Vec<u8>,
diff --git a/src/to_clt/env.rs b/src/to_clt/env.rs
index 031ee96..ecd3db3 100644
--- a/src/to_clt/env.rs
+++ b/src/to_clt/env.rs
@@ -1,5 +1,15 @@
use super::*;
+#[mt_derive(to = "clt", repr = "str")]
+pub enum ObjVisual {
+ Cube,
+ Sprite,
+ UprightSprite,
+ Mesh,
+ Wielditem,
+ Item,
+}
+
#[mt_derive(to = "clt")]
pub struct ObjProps {
#[mt(const_before = "4u8")] // version
@@ -9,7 +19,7 @@ pub struct ObjProps {
pub collision_box: ([f32; 3], [f32; 3]),
pub selection_box: ([f32; 3], [f32; 3]),
pub pointable: bool,
- pub visual: String,
+ pub visual: ObjVisual,
pub visual_size: [f32; 3],
pub textures: Vec<String>,
pub sprite_sheet_size: [i16; 2], // in sprites
@@ -93,7 +103,7 @@ pub struct ObjPhysicsOverride {
pub old_sneak: bool,
}
-const GENERIC_CAO: u8 = 101;
+pub const GENERIC_CAO: u8 = 101;
#[mt_derive(to = "clt", repr = "u8", tag = "type", content = "data")]
pub enum ObjMsg {
diff --git a/src/to_clt/hud.rs b/src/to_clt/hud.rs
index 64fe26b..3b2a456 100644
--- a/src/to_clt/hud.rs
+++ b/src/to_clt/hud.rs
@@ -123,7 +123,7 @@ impl MtSerialize for MinimapModesPkt {
fn mt_serialize<C: MtCfg>(
&self,
writer: &mut impl std::io::Write,
- ) -> Result<(), SerializeError> {
+ ) -> Result<(), mt_ser::SerializeError> {
DefCfg::write_len(self.modes.len(), writer)?;
self.current.mt_serialize::<DefCfg>(writer)?;
self.modes.mt_serialize::<()>(writer)?;
@@ -134,7 +134,9 @@ impl MtSerialize for MinimapModesPkt {
#[cfg(feature = "client")]
impl MtDeserialize for MinimapModesPkt {
- fn mt_deserialize<C: MtCfg>(reader: &mut impl std::io::Read) -> Result<Self, DeserializeError> {
+ fn mt_deserialize<C: MtCfg>(
+ reader: &mut impl std::io::Read,
+ ) -> Result<Self, mt_ser::DeserializeError> {
let len = DefCfg::read_len(reader)?;
let current = MtDeserialize::mt_deserialize::<DefCfg>(reader)?;
let modes = mt_ser::mt_deserialize_sized_seq::<DefCfg, _>(&len, reader)?.try_collect()?;
diff --git a/src/to_clt/sky.rs b/src/to_clt/sky.rs
new file mode 100644
index 0000000..c9cb642
--- /dev/null
+++ b/src/to_clt/sky.rs
@@ -0,0 +1,192 @@
+use super::*;
+
+#[mt_derive(to = "clt", tag = "type", content = "data", custom)]
+pub enum Sky {
+ Regular {
+ day_sky: Color,
+ day_horizon: Color,
+ dawn_sky: Color,
+ dawn_horizon: Color,
+ night_sky: Color,
+ night_horizon: Color,
+ indoor: Color,
+ },
+ Skybox {
+ textures: Vec<String>,
+ },
+ Plain,
+}
+
+#[mt_derive(to = "clt", tag = "type", custom)]
+pub enum FogTint {
+ Default,
+ Custom { sun: Color, moon: Color },
+}
+
+#[mt_derive(to = "clt", custom)]
+pub struct SkyParams {
+ pub bg_color: Color,
+ pub clouds: bool,
+ pub fog_tint: FogTint,
+ pub sky: Sky,
+}
+
+#[cfg(feature = "server")]
+impl MtSerialize for SkyParams {
+ fn mt_serialize<C: MtCfg>(
+ &self,
+ writer: &mut impl std::io::Write,
+ ) -> Result<(), mt_ser::SerializeError> {
+ self.bg_color.mt_serialize::<DefCfg>(writer)?;
+
+ match &self.sky {
+ Sky::Regular { .. } => "regular",
+ Sky::Skybox { .. } => "skybox",
+ Sky::Plain => "plain",
+ }
+ .mt_serialize::<DefCfg>(writer)?;
+
+ self.clouds.mt_serialize::<DefCfg>(writer)?;
+
+ match &self.fog_tint {
+ FogTint::Default => {
+ let unused_color = Color {
+ a: 0,
+ r: 0,
+ g: 0,
+ b: 0,
+ };
+
+ unused_color.mt_serialize::<DefCfg>(writer)?;
+ unused_color.mt_serialize::<DefCfg>(writer)?;
+ "default".mt_serialize::<DefCfg>(writer)?;
+ }
+ FogTint::Custom { sun, moon } => {
+ sun.mt_serialize::<DefCfg>(writer)?;
+ moon.mt_serialize::<DefCfg>(writer)?;
+ "custom".mt_serialize::<DefCfg>(writer)?;
+ }
+ }
+
+ match &self.sky {
+ Sky::Regular {
+ day_sky,
+ day_horizon,
+ dawn_sky,
+ dawn_horizon,
+ night_sky,
+ night_horizon,
+ indoor,
+ } => {
+ day_sky.mt_serialize::<DefCfg>(writer)?;
+ day_horizon.mt_serialize::<DefCfg>(writer)?;
+ dawn_sky.mt_serialize::<DefCfg>(writer)?;
+ dawn_horizon.mt_serialize::<DefCfg>(writer)?;
+ night_sky.mt_serialize::<DefCfg>(writer)?;
+ night_horizon.mt_serialize::<DefCfg>(writer)?;
+ indoor.mt_serialize::<DefCfg>(writer)?;
+ }
+ Sky::Skybox { textures } => {
+ textures.mt_serialize::<DefCfg>(writer)?;
+ }
+ Sky::Plain => {}
+ }
+
+ Ok(())
+ }
+}
+
+#[cfg(feature = "client")]
+impl MtDeserialize for SkyParams {
+ fn mt_deserialize<C: MtCfg>(
+ reader: &mut impl std::io::Read,
+ ) -> Result<Self, mt_ser::DeserializeError> {
+ use mt_ser::DeserializeError::InvalidEnum;
+
+ let bg_color = MtDeserialize::mt_deserialize::<DefCfg>(reader)?;
+ let sky_type = String::mt_deserialize::<DefCfg>(reader)?;
+ let clouds = MtDeserialize::mt_deserialize::<DefCfg>(reader)?;
+
+ let sun = MtDeserialize::mt_deserialize::<DefCfg>(reader)?;
+ let moon = MtDeserialize::mt_deserialize::<DefCfg>(reader)?;
+
+ let fog_tint_type = String::mt_deserialize::<DefCfg>(reader)?;
+ let fog_tint = match fog_tint_type.as_str() {
+ "default" => FogTint::Default,
+ "custom" => FogTint::Custom { sun, moon },
+ _ => return Err(InvalidEnum("FogTint", Box::new(fog_tint_type))),
+ };
+
+ let sky = match sky_type.as_str() {
+ "regular" => {
+ let day_sky = MtDeserialize::mt_deserialize::<DefCfg>(reader)?;
+ let day_horizon = MtDeserialize::mt_deserialize::<DefCfg>(reader)?;
+ let dawn_sky = MtDeserialize::mt_deserialize::<DefCfg>(reader)?;
+ let dawn_horizon = MtDeserialize::mt_deserialize::<DefCfg>(reader)?;
+ let night_sky = MtDeserialize::mt_deserialize::<DefCfg>(reader)?;
+ let night_horizon = MtDeserialize::mt_deserialize::<DefCfg>(reader)?;
+ let indoor = MtDeserialize::mt_deserialize::<DefCfg>(reader)?;
+
+ Sky::Regular {
+ day_sky,
+ day_horizon,
+ dawn_sky,
+ dawn_horizon,
+ night_sky,
+ night_horizon,
+ indoor,
+ }
+ }
+ "skybox" => {
+ let textures = MtDeserialize::mt_deserialize::<DefCfg>(reader)?;
+
+ Sky::Skybox { textures }
+ }
+ "plain" => Sky::Plain,
+ _ => return Err(InvalidEnum("Sky", Box::new(sky_type))),
+ };
+
+ Ok(Self {
+ bg_color,
+ clouds,
+ fog_tint,
+ sky,
+ })
+ }
+}
+
+#[mt_derive(to = "clt")]
+pub struct SunParams {
+ pub visible: bool,
+ pub texture: String,
+ pub tone_map: String,
+ pub rise: String,
+ pub rising: bool,
+ pub size: f32,
+}
+
+#[mt_derive(to = "clt")]
+pub struct MoonParams {
+ pub visible: bool,
+ pub texture: String,
+ pub tone_map: String,
+ pub size: f32,
+}
+
+#[mt_derive(to = "clt")]
+pub struct StarParams {
+ pub visible: bool,
+ pub count: u32,
+ pub color: Color,
+ pub size: f32,
+}
+
+#[mt_derive(to = "clt")]
+pub struct CloudParams {
+ pub density: f32,
+ pub diffuse_color: Color,
+ pub ambient_color: Color,
+ pub height: f32,
+ pub thickness: f32,
+ pub speed: [f32; 2],
+}