#Which Command Method is better ?
1 messages · Page 1 of 1 (latest)
I have two implementations for iterating through an NBT list recursively in a Minecraft datapack. Which approach would you consider cleaner or more efficient and why? Which method would you choose?
Method 1:
Function 1 - This Function is called every tick if player views current chat menu page
scoreboard players set #index 0
execute store result score #list_length run data get storage list
# ABC
data modify storage set value {current_search_index:0b,target_name:"abc"}
function function_2 with storage
# DEF
data modify storage set value {current_search_index:0b,target_name:"def"}
function function_2 with storage
# GHI
data modify storage set value {current_search_index:0b,target_name:"ghi"}
function function_2 with storage
and
Function 2 - This Function is called when a key is unset
data modify set value $(target_name) / or data modify storage set from storage (without macro is also possible)
execute store success storage run data modify storage set from storage
or
execute store success score run data modify storage set from storage
execute if data success 0 run data modify storage[$(property_index)] set from storage[$(current_search_index)]
or
execute if score success 0 run data modify storage[$(property_index)] set from storage[$(current_search_index)]
scoreboard players add #index 1
execute store result storage current_search_index run scoreboard get #index
execute if data success 1 if score #index < #list_length run function function_2 with storage
or
execute if score success 1 if score #index < #list_length run function function_2 with storage
Method 2:
Function 1 - This Function is called every tick if player views current chat menu page
# ABC
data modify storage set value {current_search_index:0b,next_search_index:1b,target_name:"abc"}
function function_2 with storage
# DEF
data modify storage set value {current_search_index:0b,next_search_index:1b,target_name:"def"}
function function_2 with storage
# GHI
data modify storage set value {current_search_index:0b,next_search_index:1b,target_name:"ghi"}
function function_2 with storage
and
Function 2 - This Function is called when a key is unset
data modify set value $(target_name) / or data modify storage set from storage (without macro is also possible)
execute store success storage run data modify storage set from storage
or
execute store success score run data modify storage set from storage
execute if data success 0 run data modify storage[$(property_index)] set from storage[$(current_search_index)]
or
execute if score success 0 run data modify storage[$(property_index)] set from storage[$(current_search_index)]
execute store result score #index run data get storage next_search_index
scoreboard add #index 1
data modify current_search_index set from next_search_index
execute store result storage next_search_index run scoreboard get #index
execute if data success 1 if data storage[$(next_search_index)] run function function_2 with storage
or
execute if score success 1 if data storage[$(next_search_index)] run function function_2 with storage
Method 1:
- 2 scores
- 1 nbt
- score-compare repeat condition
Method 2:
- 1 score
- 2 nbts
- if-data repeat condition