add basic.rs example file

This commit is contained in:
Moritz Hölting 2024-06-10 20:58:37 +02:00
parent 86b2b2f2eb
commit cef1dab727
2 changed files with 36 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/dist
/target /target
/Cargo.lock /Cargo.lock

35
examples/basic.rs Normal file
View File

@ -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();
}