]>
Witch of Git - minecraft-eda/blob - mc-mask/src/bin/litho.rs
1 use rcon
::{self, Connection
};
9 fn block_below_player(conn
: &mut Connection
, user
: &str)
10 -> Result
<(i32, i32, i32), Box
<dyn Error
>>
12 let cmd
= format
!("execute at {user} run tp {user} ~ ~ ~", user
=user
);
13 let text
= conn
.cmd(&cmd
)?
;
14 let re
= Regex
::new(r
"Teleported .* to (.*), (.*), (.*)").unwrap
();
15 if let Some(cap
) = re
.captures(&text
) {
16 let x
= (cap
[1].parse
::<f32>()?
+ 0.0) as i32;
17 let y
= (cap
[2].parse
::<f32>()?
- 1.0) as i32;
18 let z
= (cap
[3].parse
::<f32>()?
- 1.0) as i32;
25 fn main() -> Result
<(), Box
<dyn Error
>> {
26 if let [_
, addr
, pass
, user
] = &env
::args().collect
::<Vec
<_
>>()[..] {
27 let mut conn
= Connection
::connect(&addr
, &pass
)?
;
28 let (x0
, y0
, z0
) = block_below_player(&mut conn
, &user
)?
;
29 println
!("Placing design at player {}, at {} {} {}", user
, x0
, y0
, z0
);
30 println
!("Reading commands on stdin");
31 for (i
, line
) in io
::stdin().lock().lines().enumerate() {
33 let mut parts
= line
.split_whitespace();
34 let x
= parts
.next().ok_or("Missing x")?
.parse
::<i32>()?
;
35 let y
= parts
.next().ok_or("Missing y")?
.parse
::<i32>()?
;
36 let z
= parts
.next().ok_or("Missing z")?
.parse
::<i32>()?
;
37 let block
= parts
.next().ok_or("Missing block name")?
;
38 if let Some(txt
) = parts
.next() {
39 println
!("Warning: Unexpected trailing {} on line {}", txt
, i
);
41 // We shuffle y and z in input coordinates in order to make coordinates good :3
42 conn
.cmd(&format
!("setblock {} {} {} {}", x0
+ x
, y0
+ z
, z0
+ y
, block
))?
;
47 "Usage: {} <server> <rcon-password> <user>",
48 env
::args().nth(0).unwrap
(),