comment basic example

This commit is contained in:
Moritz Hölting 2024-06-17 21:43:36 +02:00
parent e31f9f904a
commit 85f46d0453
1 changed files with 10 additions and 0 deletions

View File

@ -6,16 +6,23 @@ use shulkerbox::{
}; };
fn main() { fn main() {
// create a new datapack
let mut dp = Datapack::new(16).with_supported_formats(16..=20); let mut dp = Datapack::new(16).with_supported_formats(16..=20);
// get the namespace "test"
let namespace = dp.namespace_mut("test"); let namespace = dp.namespace_mut("test");
// get the function "foo" of the namespace "test" and add some commands
let foo_function = namespace.function_mut("foo"); let foo_function = namespace.function_mut("foo");
foo_function.add_command("say Hello, world!"); foo_function.add_command("say Hello, world!");
foo_function.add_command(Command::Debug("debug message".into())); foo_function.add_command(Command::Debug("debug message".into()));
// get a call command to the function "foo"
let call_func = Command::from(foo_function); let call_func = Command::from(foo_function);
let bar_function = namespace.function_mut("bar"); let bar_function = namespace.function_mut("bar");
// add the call command to the function "bar"
bar_function.add_command(call_func); bar_function.add_command(call_func);
// add a complex command to the function "bar"
bar_function.add_command(Command::Execute(Execute::As( bar_function.add_command(Command::Execute(Execute::As(
"@a".to_string(), "@a".to_string(),
Box::new(Execute::If( Box::new(Execute::If(
@ -27,9 +34,12 @@ fn main() {
)), )),
))); )));
// get the main function of the namespace "test" and add a command
namespace.get_main_function_mut().add_command("say tick"); namespace.get_main_function_mut().add_command("say tick");
// compile the datapack
let v_folder = dp.compile(&CompileOptions::default()); let v_folder = dp.compile(&CompileOptions::default());
// place the compiled datapack in the "./dist" folder
v_folder.place(Path::new("./dist")).unwrap(); v_folder.place(Path::new("./dist")).unwrap();
} }