From 9e16587205cdf3dd1368c49488532465a20b4238 Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Sat, 27 Apr 2019 15:02:10 -0400 Subject: [PATCH] Add a rust program to put designs into minecraft Currently just finds the origin position below a player's feet and places a marker there. --- .gitignore | 1 + mc-mask/Cargo.lock | 97 +++++++++++++++++++++++++++++++++++++++++++++ mc-mask/Cargo.toml | 9 +++++ mc-mask/src/main.rs | 37 +++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 .gitignore create mode 100644 mc-mask/Cargo.lock create mode 100644 mc-mask/Cargo.toml create mode 100644 mc-mask/src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..00806d2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/mc-mask/target diff --git a/mc-mask/Cargo.lock b/mc-mask/Cargo.lock new file mode 100644 index 0000000..77e87ce --- /dev/null +++ b/mc-mask/Cargo.lock @@ -0,0 +1,97 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aho-corasick" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bufstream" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "lazy_static" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "mc-mask" +version = "0.1.0" +dependencies = [ + "rcon 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "memchr" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "podio" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rcon" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bufstream 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex-syntax" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "thread_local" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ucd-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "utf8-ranges" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c" +"checksum bufstream 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "40e38929add23cdf8a366df9b0e088953150724bcbe5fc330b0d8eb3b328eec8" +"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" +"checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" +"checksum podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "780fb4b6698bbf9cf2444ea5d22411cef2953f0824b98f33cf454ec5615645bd" +"checksum rcon 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6ad19d5facadd71ec864bda6a1e7486e70b904cca7be626b178610f7353fc722" +"checksum regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8f0a0bcab2fd7d1d7c54fa9eae6f43eddeb9ce2e7352f8518a814a4f65d60c58" +"checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" +"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" +"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" +"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" diff --git a/mc-mask/Cargo.toml b/mc-mask/Cargo.toml new file mode 100644 index 0000000..6e99e9b --- /dev/null +++ b/mc-mask/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "mc-mask" +version = "0.1.0" +authors = ["C Jones "] +edition = "2018" + +[dependencies] +rcon = "0.1" +regex = "1" diff --git a/mc-mask/src/main.rs b/mc-mask/src/main.rs new file mode 100644 index 0000000..1f0cacc --- /dev/null +++ b/mc-mask/src/main.rs @@ -0,0 +1,37 @@ +use rcon::{self, Connection}; +use regex::Regex; +use std::error::Error; + +fn block_below_player(conn: &mut Connection, user: &str) + -> Result<(i32, i32, i32), Box> + { + let cmd = format!("execute at {user} run tp {user} ~ ~ ~", user=user); + let text = conn.cmd(&cmd)?; + let re = Regex::new(r"Teleported .* to (.*), (.*), (.*)").unwrap(); + if let Some(cap) = re.captures(&text) { + let x = (cap[1].parse::()? + 0.0) as i32; + let y = (cap[2].parse::()? - 1.0) as i32; + let z = (cap[3].parse::()? - 1.0) as i32; + Ok((x, y, z)) + } else { + Err(text)? + } +} + +fn main() -> Result<(), Box> { + if std::env::args().len() != 4 { + println!( + "Usage: {} ", + std::env::args().nth(0).unwrap(), + ); + return Ok(()); + } + let addr = std::env::args().nth(1).unwrap(); + let password = std::env::args().nth(2).unwrap(); + let user = std::env::args().nth(3).unwrap(); + let mut conn = Connection::connect(&addr, &password)?; + let (x, y, z) = block_below_player(&mut conn, &user)?; + let cmd = format!("setblock {} {} {} gold_block", x, y, z); + conn.cmd(&cmd)?; + Ok(()) +} -- 2.47.0