2024-06-10 20:58:37 +02:00
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
use shulkerbox::{
|
|
|
|
datapack::{Command, Condition, Datapack, Execute},
|
|
|
|
util::compile::CompileOptions,
|
|
|
|
};
|
|
|
|
|
|
|
|
fn main() {
|
2024-06-17 21:43:36 +02:00
|
|
|
// create a new datapack
|
2024-06-10 20:58:37 +02:00
|
|
|
let mut dp = Datapack::new(16).with_supported_formats(16..=20);
|
2024-06-17 21:43:36 +02:00
|
|
|
|
|
|
|
// get the namespace "test"
|
2024-06-10 20:58:37 +02:00
|
|
|
let namespace = dp.namespace_mut("test");
|
|
|
|
|
2024-06-17 21:43:36 +02:00
|
|
|
// get the function "foo" of the namespace "test" and add some commands
|
2024-06-10 20:58:37 +02:00
|
|
|
let foo_function = namespace.function_mut("foo");
|
|
|
|
foo_function.add_command("say Hello, world!");
|
|
|
|
foo_function.add_command(Command::Debug("debug message".into()));
|
|
|
|
|
2024-06-17 21:43:36 +02:00
|
|
|
// get a call command to the function "foo"
|
2024-06-10 20:58:37 +02:00
|
|
|
let call_func = Command::from(foo_function);
|
|
|
|
let bar_function = namespace.function_mut("bar");
|
2024-06-17 21:43:36 +02:00
|
|
|
// add the call command to the function "bar"
|
2024-06-10 20:58:37 +02:00
|
|
|
bar_function.add_command(call_func);
|
2024-06-17 21:43:36 +02:00
|
|
|
// add a complex command to the function "bar"
|
2024-06-10 20:58:37 +02:00
|
|
|
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,
|
|
|
|
)),
|
|
|
|
)));
|
|
|
|
|
2024-06-17 21:43:36 +02:00
|
|
|
// get the main function of the namespace "test" and add a command
|
2024-06-10 20:58:37 +02:00
|
|
|
namespace.get_main_function_mut().add_command("say tick");
|
|
|
|
|
2024-06-17 21:43:36 +02:00
|
|
|
// compile the datapack
|
2024-06-10 20:58:37 +02:00
|
|
|
let v_folder = dp.compile(&CompileOptions::default());
|
|
|
|
|
2024-06-17 21:43:36 +02:00
|
|
|
// place the compiled datapack in the "./dist" folder
|
2024-06-10 20:58:37 +02:00
|
|
|
v_folder.place(Path::new("./dist")).unwrap();
|
|
|
|
}
|