always use success uid for conditionals, never use fallback success_uid
This commit is contained in:
parent
2829316abe
commit
e1bc953b7a
|
@ -1,5 +1,6 @@
|
||||||
use chksum_md5 as md5;
|
use chksum_md5 as md5;
|
||||||
use std::{
|
use std::{
|
||||||
|
cell::LazyCell,
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
ops::{BitAnd, BitOr, Not},
|
ops::{BitAnd, BitOr, Not},
|
||||||
};
|
};
|
||||||
|
@ -69,7 +70,7 @@ fn compile_using_data_storage(
|
||||||
let then_count = then.get_count(options);
|
let then_count = then.get_count(options);
|
||||||
|
|
||||||
let str_cond = cond.clone().compile(options, global_state, function_state);
|
let str_cond = cond.clone().compile(options, global_state, function_state);
|
||||||
let require_grouping_uid = (el.is_some() || then_count > 1).then(|| {
|
let success_uid = LazyCell::new(|| {
|
||||||
// calculate a unique condition id for the else check
|
// calculate a unique condition id for the else check
|
||||||
let uid = function_state.request_uid();
|
let uid = function_state.request_uid();
|
||||||
let pre_hash = function_state.path().to_owned() + ":" + &uid.to_string();
|
let pre_hash = function_state.path().to_owned() + ":" + &uid.to_string();
|
||||||
|
@ -77,7 +78,8 @@ fn compile_using_data_storage(
|
||||||
md5::hash(pre_hash).to_hex_lowercase()
|
md5::hash(pre_hash).to_hex_lowercase()
|
||||||
});
|
});
|
||||||
#[allow(clippy::option_if_let_else)]
|
#[allow(clippy::option_if_let_else)]
|
||||||
let then = if let Some(success_uid) = require_grouping_uid.as_deref() {
|
let then = if el.is_some() || then_count > 1 {
|
||||||
|
let success_uid = &*success_uid;
|
||||||
// prepare commands for grouping
|
// prepare commands for grouping
|
||||||
let mut group_cmds = match then.clone() {
|
let mut group_cmds = match then.clone() {
|
||||||
Execute::Run(cmd) => vec![*cmd],
|
Execute::Run(cmd) => vec![*cmd],
|
||||||
|
@ -118,10 +120,7 @@ fn compile_using_data_storage(
|
||||||
};
|
};
|
||||||
// if the conditions have multiple parts joined by a disjunction, commands need to be grouped
|
// if the conditions have multiple parts joined by a disjunction, commands need to be grouped
|
||||||
let each_or_cmd = (str_cond.len() > 1).then(|| {
|
let each_or_cmd = (str_cond.len() > 1).then(|| {
|
||||||
let success_uid = require_grouping_uid.as_deref().unwrap_or_else(|| {
|
let success_uid = &*success_uid;
|
||||||
tracing::error!("No success_uid found for each_or_cmd, using default");
|
|
||||||
"if_success"
|
|
||||||
});
|
|
||||||
(
|
(
|
||||||
format!("data modify storage shulkerbox:cond {success_uid} set value true"),
|
format!("data modify storage shulkerbox:cond {success_uid} set value true"),
|
||||||
combine_conditions_commands(
|
combine_conditions_commands(
|
||||||
|
@ -135,10 +134,7 @@ fn compile_using_data_storage(
|
||||||
});
|
});
|
||||||
// build the condition for each then command
|
// build the condition for each then command
|
||||||
let successful_cond = if each_or_cmd.is_some() {
|
let successful_cond = if each_or_cmd.is_some() {
|
||||||
let success_uid = require_grouping_uid.as_deref().unwrap_or_else(|| {
|
let success_uid = &*success_uid;
|
||||||
tracing::error!("No success_uid found for each_or_cmd, using default");
|
|
||||||
"if_success"
|
|
||||||
});
|
|
||||||
Condition::Atom(MacroString::from(format!(
|
Condition::Atom(MacroString::from(format!(
|
||||||
"data storage shulkerbox:cond {{{success_uid}:1b}}"
|
"data storage shulkerbox:cond {{{success_uid}:1b}}"
|
||||||
)))
|
)))
|
||||||
|
@ -151,10 +147,7 @@ fn compile_using_data_storage(
|
||||||
// build the else part
|
// build the else part
|
||||||
let el_commands = el
|
let el_commands = el
|
||||||
.map(|el| {
|
.map(|el| {
|
||||||
let success_uid = require_grouping_uid.as_deref().unwrap_or_else(|| {
|
let success_uid = &*success_uid;
|
||||||
tracing::error!("No success_uid found for each_or_cmd, using default");
|
|
||||||
"if_success"
|
|
||||||
});
|
|
||||||
let else_cond = (!Condition::Atom(MacroString::from(format!(
|
let else_cond = (!Condition::Atom(MacroString::from(format!(
|
||||||
"data storage shulkerbox:cond {{{success_uid}:1b}}"
|
"data storage shulkerbox:cond {{{success_uid}:1b}}"
|
||||||
))))
|
))))
|
||||||
|
@ -173,10 +166,7 @@ fn compile_using_data_storage(
|
||||||
|
|
||||||
// reset the success storage if needed
|
// reset the success storage if needed
|
||||||
let reset_success_storage = if each_or_cmd.is_some() || el.is_some() {
|
let reset_success_storage = if each_or_cmd.is_some() || el.is_some() {
|
||||||
let success_uid = require_grouping_uid.as_deref().unwrap_or_else(|| {
|
let success_uid = &*success_uid;
|
||||||
tracing::error!("No success_uid found for each_or_cmd, using default");
|
|
||||||
"if_success"
|
|
||||||
});
|
|
||||||
Some(
|
Some(
|
||||||
CompiledCommand::new(format!("data remove storage shulkerbox:cond {success_uid}"))
|
CompiledCommand::new(format!("data remove storage shulkerbox:cond {success_uid}"))
|
||||||
.with_forbid_prefix(true),
|
.with_forbid_prefix(true),
|
||||||
|
|
Loading…
Reference in New Issue