make sure that scoreboards get registered before all other functions

This commit is contained in:
Moritz Hölting 2025-03-10 14:37:02 +01:00
parent cf8c922704
commit c36c87c3db
3 changed files with 17 additions and 7 deletions

View File

@ -7,7 +7,7 @@ fn main() {
// create a new datapack // create a new datapack
let mut dp = Datapack::new("example", 16).with_supported_formats(16..=20); let mut dp = Datapack::new("example", 16).with_supported_formats(16..=20);
dp.register_scoreboard("example_scoreboard", Some("dummy"), None); dp.register_scoreboard("example_scoreboard", None::<&str>, None::<&str>);
// get the namespace "example" // get the namespace "example"
let namespace = dp.namespace_mut("example"); let namespace = dp.namespace_mut("example");

View File

@ -195,10 +195,14 @@ impl Datapack {
minecraft_namespace minecraft_namespace
.to_mut() .to_mut()
.tag_mut("load", tag::TagType::Function) .tag_mut("load", tag::TagType::Function)
.add_value(tag::TagValue::Simple(format!( .values_mut()
.insert(
0,
tag::TagValue::Simple(format!(
"{}:sb/register_scoreboards", "{}:sb/register_scoreboards",
self.main_namespace_name self.main_namespace_name
))); )),
);
} }
if let Some(uninstall_commands) = uninstall_commands { if let Some(uninstall_commands) = uninstall_commands {

View File

@ -37,10 +37,16 @@ impl Tag {
/// Get the values of the tag. /// Get the values of the tag.
#[must_use] #[must_use]
pub fn get_values(&self) -> &Vec<TagValue> { pub fn values(&self) -> &[TagValue] {
&self.values &self.values
} }
/// Get a mutable reference to the values of the tag.
#[must_use]
pub fn values_mut(&mut self) -> &mut Vec<TagValue> {
&mut self.values
}
/// Add a value to the tag. /// Add a value to the tag.
pub fn add_value(&mut self, value: TagValue) { pub fn add_value(&mut self, value: TagValue) {
self.values.push(value); self.values.push(value);
@ -186,7 +192,7 @@ mod tests {
required: true, required: true,
}); });
assert_eq!(tag.get_values().len(), 2); assert_eq!(tag.values().len(), 2);
let compiled = tag.compile(&CompileOptions::default(), &MutCompilerState::default()); let compiled = tag.compile(&CompileOptions::default(), &MutCompilerState::default());