Added get_blocks_with_data() function

This commit is contained in:
blackfur 2021-03-15 08:29:47 +01:00
parent 13977d9da0
commit b1b6f9ae0a

View file

@ -5,7 +5,7 @@ use std::cmp::{min, max};
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{create}; use crate::{create, Vec3};
#[test] #[test]
fn it_works() { fn it_works() {
@ -73,6 +73,18 @@ impl Minecraft {
results results
} }
pub fn get_blocks_with_data(&mut self, pos1:Vec3, pos2:Vec3) -> Vec<Vec<u8>> {
let mut results:Vec<Vec<u8>> = vec![];
for y in min(pos1.y, pos2.y)..max(pos1.y, pos2.y)+1 {
for x in min(pos1.x, pos2.x)..max(pos1.x, pos2.x)+1 {
for z in min(pos1.z, pos2.z)..max(pos1.z, pos2.z) + 1 {
results.push(self.conn.send_receive(&format!("world.getBlockWithData({},{},{})", x,y,z)).split(',').map(|s| s.parse()).collect::<Result<Vec<u8>, _>>().unwrap());
}
}
}
results
}
pub fn set_block(&mut self, pos:Vec3, blocktype:u8, blockdata:u8) { pub fn set_block(&mut self, pos:Vec3, blocktype:u8, blockdata:u8) {
self.conn.send(&format!("world.setBlock({},{},{},{},{})", pos.x, pos.y, pos.z, blocktype, blockdata)); self.conn.send(&format!("world.setBlock({},{},{},{},{})", pos.x, pos.y, pos.z, blocktype, blockdata));
} }