Added .vscode to .gitignore, renamed Player function names, added setting function to Player

This commit is contained in:
blackfur 2021-03-26 17:46:02 +01:00
parent 2edfd26bb6
commit 05efd7143c
3 changed files with 23 additions and 5 deletions

1
.gitignore vendored
View file

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

View file

@ -164,14 +164,27 @@ impl Minecraft {
} }
impl Player<'_> { impl Player<'_> {
pub fn get_player_pos(&mut self) -> Vec3 { pub fn get_pos(&mut self) -> Vec3 {
let vec:Vec<f32> = self.conn.send_receive(&format!("player.getPos()")).split(',').map(|s| s.parse()).collect::<Result<Vec<f32>, _>>().unwrap(); let vec:Vec<f32> = self.conn.send_receive(&format!("player.getPos()")).split(',').map(|s| s.parse()).collect::<Result<Vec<f32>, _>>().unwrap();
Vec3::from_vector(&vec) Vec3::from_vector(&vec)
} }
pub fn set_player_pos(&mut self, pos:&Vec3) { pub fn set_pos(&mut self, pos:&Vec3) {
self.conn.send(&format!("player.setPos({},{},{})", pos.x, pos.y, pos.z)); self.conn.send(&format!("player.setPos({},{},{})", pos.x, pos.y, pos.z));
} }
pub fn get_tile_pos(&mut self) -> TileVec3 {
let vec:Vec<i32> = self.conn.send_receive(&format!("player.getTile()")).split(',').map(|s| s.parse()).collect::<Result<Vec<i32>, _>>().unwrap();
TileVec3::from_vector(&vec)
}
pub fn set_tile_pos(&mut self, pos:&TileVec3) {
self.conn.send(&format!("player.setTile({},{},{})", pos.x, pos.y, pos.z))
}
pub fn setting(&mut self, setting:&str, status:bool) {
self.conn.send(&format!("player.setting({},{})",setting,if status {1} else {0}));
}
} }
pub fn create(adress:&str) -> Minecraft { pub fn create(adress:&str) -> Minecraft {

View file

@ -1,9 +1,13 @@
use mcpi::{Vec3, create}; use mcpi::{Vec3, create, TileVec3};
#[test] #[test]
fn main() { fn main() {
let mut mc = create("localhost:4711"); let mut mc = create("localhost:4711");
let posp = mc.player().get_player_pos(); let posp = mc.player().get_pos();
let posp2 = Vec3::from(posp.x, posp.y + 10.0, posp.z); let posp2 = Vec3::from(posp.x, posp.y + 10.0, posp.z);
mc.player().set_player_pos(&posp2); mc.player().set_pos(&posp2);
let post = mc.player().get_tile_pos();
let post2 = TileVec3::from(post.x, post.y + 10, post.z);
mc.player().set_tile_pos(&post2);
mc.player().setting("autojump", true);
} }