diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..04f6c57 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +/target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..1c06a0d --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "mcpi" +version = "0.1.0" +authors = ["blackfur <64478051+theblackfurguy@users.noreply.github.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..d7bb923 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,56 @@ +use std::io::prelude::*; +use std::net::TcpStream; +use std::io::{Result as IoResult, Error}; + +#[cfg(test)] +mod tests { + use crate::create; + + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + let mut mc = create("localhost:4711"); + mc.post_to_chat("Test"); + } +} + +pub struct Minecraft { + conn:Connection +} + +struct Connection { + stream:TcpStream +} + +struct Vec3 { + x:i32, + y:i32, + z:i32 +} + +impl Connection { + pub fn send(&mut self, msg:&str) { + self.stream.write(&format!("{}\n",msg).as_bytes()); + } +} + +impl Minecraft { + pub fn post_to_chat(&mut self, msg:&str) { + self.conn.send(&format!("chat.post({})", msg)); + } +} + +pub fn create(adress:&str) -> Minecraft { + let mut stream = TcpStream::connect(adress); + match stream { + Ok(_) => {} + Err(e) => { + panic!(e) + } + } + Minecraft { + conn: Connection { + stream: stream.unwrap() + } + } +} \ No newline at end of file