]> git.lizzy.rs Git - mt_net.git/commitdiff
Implement objects
authorLizzy Fleckenstein <eliasfleckenstein@web.de>
Sun, 12 Feb 2023 22:49:03 +0000 (23:49 +0100)
committerLizzy Fleckenstein <eliasfleckenstein@web.de>
Sun, 12 Feb 2023 22:49:03 +0000 (23:49 +0100)
src/lib.rs
src/to_clt.rs
src/to_clt/env.rs
src/to_clt/hud.rs

index a1b8469e2287884da044af15906dbfad7afefe2a..9b410a64e9601ecbbe793f078036c88e1c241c37 100644 (file)
@@ -9,6 +9,8 @@ pub use rand;
 #[cfg(feature = "serde")]
 pub use serde;
 
+pub use mt_ser;
+
 use enumset::{EnumSet, EnumSetType};
 use mt_ser::mt_derive;
 use std::{
index 33b9c79270b8fc88cc6980993a9aa4faab11670b..a0d28a94490f0341c05ccfc5ed1d53c1f9bb54f8 100644 (file)
@@ -1,7 +1,7 @@
 use super::*;
 
 #[mt_derive(to = "clt")]
-pub struct ArgbColor {
+pub struct Color {
     pub a: u8,
     pub r: u8,
     pub g: u8,
@@ -99,7 +99,8 @@ pub enum ToCltPkt {
         add: Vec<ObjAdd>,
     } = 49,
     ObjMsgs {
-        msgs: Vec<ObjMsg>,
+        #[mt(len0)]
+        msgs: Vec<ObjIdMsg>,
     } = 50,
     Hp {
         hp: u16,
@@ -270,8 +271,8 @@ pub enum ToCltPkt {
     } = 83,
     CloudParams {
         density: f32,
-        diffuse_color: ArgbColor,
-        ambient_color: ArgbColor,
+        diffuse_color: Color,
+        ambient_color: Color,
         height: f32,
         thickness: f32,
         speed: [f32; 2],
@@ -294,7 +295,10 @@ pub enum ToCltPkt {
         signal: ModChanSig,
         channel: String,
     } = 88,
-    NodeMetasChanged(#[mt(size32)] HashMap<[i16; 3], NodeMeta>) = 89,
+    NodeMetasChanged {
+        #[mt(size32)]
+        changed: HashMap<[i16; 3], NodeMeta>,
+    } = 89,
     SunParams {
         visible: bool,
         texture: String,
@@ -322,5 +326,5 @@ pub enum ToCltPkt {
     FormspecPrepend {
         prepend: String,
     } = 97,
-    MinimapModes(MinimapModePkt) = 98,
+    MinimapModes(MinimapModesPkt) = 98,
 }
index f242298e5ac73956da9e5986ef7e8b2b85730c8e..4b035e27088da8f06e4681ec8c0786521cbe66e6 100644 (file)
 use super::*;
 
 #[mt_derive(to = "clt")]
-pub struct ObjAdd; // TODO
+pub struct ObjProps {
+    #[mt(const8 = 4)] // version
+    pub max_hp: u16, // player only
+    pub collide_with_nodes: bool,
+    pub weight: f32, // deprecated
+    pub collision_box: ([f32; 3], [f32; 3]),
+    pub selection_box: ([f32; 3], [f32; 3]),
+    pub pointable: bool,
+    pub visual: String,
+    pub visual_size: [f32; 3],
+    pub textures: Vec<String>,
+    pub sprite_sheet_size: [i16; 2], // in sprites
+    pub sprite_pos: [i16; 2],        // in sprite sheet
+    pub visible: bool,
+    pub make_footstep_sounds: bool,
+    pub rotate_speed: f32, // in radians per second
+    pub mesh: String,
+    pub colors: Vec<Color>,
+    pub collide_with_objs: bool,
+    pub step_height: f32,
+    pub face_rotate_dir: bool,
+    pub face_rotate_dir_off: f32, // in degrees
+    pub backface_cull: bool,
+    pub nametag: String,
+    pub nametag_color: Color,
+    pub face_rotate_speed: f32, // in degrees per second
+    pub infotext: String,
+    pub itemstring: String,
+    pub glow: i8,
+    pub max_breath: u16, // player only
+    pub eye_height: f32, // player only
+    pub zoom_fov: f32,   // in degrees. player only
+    pub use_texture_alpha: bool,
+    pub dmg_texture_mod: String, // suffix
+    pub shaded: bool,
+    pub show_on_minimap: bool,
+    pub nametag_bg: Color,
+}
+
+#[mt_derive(to = "clt")]
+pub struct ObjPos {
+    pub pos: [f32; 3],
+    pub vel: [f32; 3],
+    pub acc: [f32; 3],
+    pub rot: [f32; 3],
+    pub interpolate: bool,
+    pub end: bool,
+    pub update_interval: f32,
+}
+
+#[mt_derive(to = "clt")]
+pub struct ObjSprite {
+    pub frame0: [i16; 2],
+    pub frames: u16,
+    pub frame_duration: f32,
+    pub view_angle_frames: bool,
+}
+
+#[mt_derive(to = "clt")]
+pub struct ObjAnim {
+    pub frames: [i32; 2],
+    pub speed: f32,
+    pub blend: f32,
+    pub no_loop: bool,
+}
+
+#[mt_derive(to = "clt")]
+pub struct ObjBonePos {
+    pub pos: [f32; 3],
+    pub rot: [f32; 3],
+}
+
+#[mt_derive(to = "clt")]
+pub struct ObjAttach {
+    pub parent_id: u16,
+    pub bone: String,
+    pub pos: [f32; 3],
+    pub rot: [f32; 3],
+    pub force_visible: bool,
+}
+
+#[mt_derive(to = "clt")]
+pub struct ObjPhysicsOverride {
+    pub walk: f32,
+    pub jump: f32,
+    pub gravity: f32,
+    // the following are player only
+    pub no_sneak: bool,
+    pub no_sneak_glitch: bool,
+    pub old_sneak: bool,
+}
+
+#[mt_derive(to = "clt", repr = "u8", tag = "type", content = "data")]
+pub enum ObjMsg {
+    Props(ObjProps) = 0,
+    Pos(ObjPos),
+    TextureMod {
+        #[serde(rename = "mod")]
+        texture_mod: String,
+    },
+    Sprite(ObjSprite),
+    Hp {
+        hp: u16,
+    },
+    ArmorGroups {
+        armor: HashMap<String, u16>,
+    },
+    Anim(ObjAnim),
+    BonePos {
+        bone: String,
+        pos: ObjBonePos,
+    },
+    Attach(ObjAttach),
+    PhysicsOverride(ObjPhysicsOverride),
+    SpawnInfant {
+        id: u16,
+        #[mt(const8 = 101)] // GenericCAO
+        infant_type: (),
+    } = 11,
+    AnimSpeed {
+        speed: f32,
+    },
+}
 
 #[mt_derive(to = "clt")]
-pub struct ObjMsg; // TODO
+pub struct ObjIdMsg {
+    pub id: u16,
+    #[mt(size16)]
+    pub msg: ObjMsg,
+}
+
+#[mt_derive(to = "clt")]
+pub struct ObjInitMsg(#[mt(size32)] ObjMsg);
+
+#[mt_derive(to = "clt")]
+pub struct ObjInitData {
+    #[mt(const8 = 1)] // version
+    pub name: String,
+    pub is_player: bool,
+    pub id: u16,
+    pub pos: [f32; 3],
+    pub rot: [f32; 3],
+    pub hp: u16,
+    #[mt(len8)]
+    pub msgs: Vec<ObjInitMsg>,
+}
+
+#[mt_derive(to = "clt")]
+pub struct ObjAdd {
+    pub id: u16,
+    #[mt(const8 = 101)] // GenericCAO
+    #[mt(size32)]
+    pub init_data: ObjInitData,
+}
 
 #[mt_derive(to = "clt", repr = "u8", enumset)]
 pub enum MapBlockFlag {
index f45d735cf670e94caf1b41be92f3a205d7b0da77..cf9e3379162857c7a4c476b2e5a57d926ffe92b1 100644 (file)
@@ -110,13 +110,13 @@ pub struct MinimapMode {
 }
 
 #[mt_derive(to = "clt", custom)]
-pub struct MinimapModePkt {
+pub struct MinimapModesPkt {
     current: u16,
     modes: Vec<MinimapMode>,
 }
 
 #[cfg(feature = "server")]
-impl MtSerialize for MinimapModePkt {
+impl MtSerialize for MinimapModesPkt {
     fn mt_serialize<C: MtCfg>(
         &self,
         writer: &mut impl std::io::Write,
@@ -130,7 +130,7 @@ impl MtSerialize for MinimapModePkt {
 }
 
 #[cfg(feature = "client")]
-impl MtDeserialize for MinimapModePkt {
+impl MtDeserialize for MinimapModesPkt {
     fn mt_deserialize<C: MtCfg>(reader: &mut impl std::io::Read) -> Result<Self, DeserializeError> {
         let len = DefCfg::read_len(reader)?;
         let current = MtDeserialize::mt_deserialize::<DefCfg>(reader)?;