From cef1dab727cdd99eb5a15931faa4450f17bf2671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20H=C3=B6lting?= <87192362+moritz-hoelting@users.noreply.github.com> Date: Mon, 10 Jun 2024 20:58:37 +0200 Subject: [PATCH] add basic.rs example file --- .gitignore | 1 + examples/basic.rs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 examples/basic.rs diff --git a/.gitignore b/.gitignore index 4fffb2f..75239f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +/dist /target /Cargo.lock diff --git a/examples/basic.rs b/examples/basic.rs new file mode 100644 index 0000000..3f0768b --- /dev/null +++ b/examples/basic.rs @@ -0,0 +1,35 @@ +use std::path::Path; + +use shulkerbox::{ + datapack::{Command, Condition, Datapack, Execute}, + util::compile::CompileOptions, +}; + +fn main() { + let mut dp = Datapack::new(16).with_supported_formats(16..=20); + let namespace = dp.namespace_mut("test"); + + let foo_function = namespace.function_mut("foo"); + foo_function.add_command("say Hello, world!"); + foo_function.add_command(Command::Debug("debug message".into())); + + let call_func = Command::from(foo_function); + let bar_function = namespace.function_mut("bar"); + bar_function.add_command(call_func); + bar_function.add_command(Command::Execute(Execute::As( + "@a".to_string(), + Box::new(Execute::If( + Condition::from("block ~ ~ ~ minecraft:stone") + | !(!Condition::from("block ~ ~1 ~ minecraft:stone") + | "block ~ ~-1 ~ minecraft:stone".into()), + Box::new(Execute::Run(Box::new("say bar".into()))), + None, + )), + ))); + + namespace.get_main_function_mut().add_command("say tick"); + + let v_folder = dp.compile(&CompileOptions::default()); + + v_folder.place(Path::new("./dist")).unwrap(); +}