Added basic structure and post_to_chat() function

master
blackfur 2021-02-09 12:30:20 +01:00
parent 0299f3b711
commit 97cec04999
3 changed files with 68 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.idea
/target
Cargo.lock

9
Cargo.toml Normal file
View File

@ -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]

56
src/lib.rs Normal file
View File

@ -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()
}
}
}