Added basic structure and post_to_chat() function
This commit is contained in:
parent
0299f3b711
commit
97cec04999
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
.idea
|
||||
/target
|
||||
Cargo.lock
|
9
Cargo.toml
Normal file
9
Cargo.toml
Normal 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
56
src/lib.rs
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue