Compare commits

..

3 Commits

Author SHA1 Message Date
Moritz Hölting 811d715082 allow access to registered scoreboards 2025-02-27 21:41:07 +01:00
Moritz Hölting 1950c29ac3 only generate uninstall function if it contains commands 2025-02-27 16:38:23 +01:00
Moritz Hölting 9337d09d7b implement registering scoreboards in datapack for automatic creation and deletion 2025-02-27 16:34:39 +01:00
2 changed files with 18 additions and 12 deletions

View File

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- support for commands using macros
- support for registering scoreboards (automatic creation and deletion)
### Changed
- use "return" command for conditionals instead of data storage when using supported pack format

View File

@ -128,6 +128,12 @@ impl Datapack {
);
}
/// Scoreboards registered in the datapack.
#[must_use]
pub fn scoreboards(&self) -> &BTreeMap<String, (Option<String>, Option<String>)> {
&self.scoreboards
}
/// Add a custom file to the datapack.
pub fn add_custom_file(&mut self, path: &str, file: VFile) {
self.custom_files.add_file(path, file);
@ -164,7 +170,7 @@ impl Datapack {
.or_insert_with(|| Cow::Owned(Namespace::new(&self.main_namespace_name)));
let register_scoreboard_function = main_namespace
.to_mut()
.function_mut("shu/register_scoreboards");
.function_mut("sb/register_scoreboards");
for (name, (criteria, display_name)) in &self.scoreboards {
let mut creation_command = format!(
"scoreboard objectives add {name} {criteria}",
@ -189,12 +195,13 @@ impl Datapack {
.to_mut()
.tag_mut("load", tag::TagType::Function)
.add_value(tag::TagValue::Simple(format!(
"{}:shu/register_scoreboards",
"{}:sb/register_scoreboards",
self.main_namespace_name
)));
}
if let Some(uninstall_commands) = uninstall_commands {
if !uninstall_commands.is_empty() {
let main_namespace = modified_namespaces
.entry(&self.main_namespace_name)
.or_insert_with(|| Cow::Owned(Namespace::new(&self.main_namespace_name)));
@ -203,9 +210,7 @@ impl Datapack {
.get_commands_mut()
.extend(uninstall_commands);
}
dbg!(&self.namespaces);
dbg!(&modified_namespaces);
}
// Compile namespaces
for (name, namespace) in modified_namespaces {