diff --git a/src/data/adco/functions/core.mcfunction b/src/data/adco/functions/core.mcfunction index ced966d..1de6144 100644 --- a/src/data/adco/functions/core.mcfunction +++ b/src/data/adco/functions/core.mcfunction @@ -19,6 +19,7 @@ function ~/load/install: scoreboard objectives add adco.score dummy scoreboard objectives setdisplay list adco.score scoreboard objectives modify adco.score rendertype integer + data modify storage adco:data root.players set value [] # Set the version in format: xx.xx.xx scoreboard players set $version adco.data ctx.meta.version diff --git a/src/data/adco/functions/count.mcfunction b/src/data/adco/functions/count.mcfunction deleted file mode 100644 index 02b2b37..0000000 --- a/src/data/adco/functions/count.mcfunction +++ /dev/null @@ -1,9 +0,0 @@ - -function ~/1: - scoreboard players add @s adco.score 1 - -function ~/2: - scoreboard players add @s adco.score 2 - -function ~/5: - scoreboard players add @s adco.score 5 diff --git a/src/data/adco/functions/recalculate.mcfunction b/src/data/adco/functions/recalculate.mcfunction new file mode 100644 index 0000000..6709241 --- /dev/null +++ b/src/data/adco/functions/recalculate.mcfunction @@ -0,0 +1,63 @@ +from 2mal3:log import log +from beet.contrib.vanilla import Vanilla + +log "debug" "@s" "Recalculating points" + +scoreboard players set .temp adco.data 0 + + +# Count the points for each unlocked advancement +vanilla = ctx.inject(Vanilla) +vanilla_advancements = vanilla.releases["1.21"].data.advancements +for name, advancement in vanilla_advancements.items(): + if "recipes" in name: # Skip recipe unlocking advancements + continue + + # Create a predicate for the advancement to test if it has been unlocked + predicate_name = name.split(":")[1].replace("/", "_") + predicate_content = { + "condition": "minecraft:entity_properties", + "entity": "this", + "predicate": { + "type_specific": { + "type": "player", + "advancements": {} + } + } + } + predicate_content["predicate"]["type_specific"]["advancements"][name] = true + predicate f"adco:unlock_previous/{predicate_name}" predicate_content + + # Give the corresponding points to all players that have unlocked the advancement + advancement_content = advancement.data + advancement_display = advancement_content["display"] + if "frame" not in advancement_display or advancement_display["frame"] == "task": + execute if predicate f"adco:unlock_previous/{predicate_name}" run scoreboard players add .temp adco.data 1 + elif advancement_display["frame"] == "goal": + execute if predicate f"adco:unlock_previous/{predicate_name}" run scoreboard players add .temp adco.data 2 + elif advancement_display["frame"] == "challenge": + execute if predicate f"adco:unlock_previous/{predicate_name}" run scoreboard players add .temp adco.data 5 + +# Get the player name +# 386f2fa2-430d-4c4c-aca1-85eaadcb3019 +summon armor_stand ~ ~ ~ \ + {UUID:[I;946810786,1124944972,-1398700566,-1379192807],Marker:1b,Invisible:1b} +loot replace entity 386f2fa2-430d-4c4c-aca1-85eaadcb3019 armor.head loot \ + {"pools":[{"rolls":1,"entries":[{"type":"minecraft:item","name":"minecraft:player_head","functions":[{"function":"minecraft:fill_player_head","entity":"this"}]}]}]} +data modify storage adco:data root.temp set from entity 386f2fa2-430d-4c4c-aca1-85eaadcb3019 ArmorItems[3].components."minecraft:profile".name +kill 386f2fa2-430d-4c4c-aca1-85eaadcb3019 + +# Store the calculated points with the player name in the data storage +data modify storage adco:data root.uuid set from entity @s UUID +execute with storage adco:data root: + $execute unless data storage adco:data root.players[{uuid: $(uuid)}] run function adco:recalculate/init_player + + $execute store result storage adco:data root.players[{uuid: $(uuid)}].points int 1 run scoreboard players get .temp adco.data + $data modify storage adco:data root.players[{uuid: $(uuid)}].name set from storage adco:data root.temp + +function ~/init_player: + data modify storage adco:data root.players append value {} + data modify storage adco:data root.players[-1].uuid set from storage adco:data root.uuid + +# Render the points +function adco:render diff --git a/src/data/adco/functions/render.mcfunction b/src/data/adco/functions/render.mcfunction new file mode 100644 index 0000000..d9d89c0 --- /dev/null +++ b/src/data/adco/functions/render.mcfunction @@ -0,0 +1,9 @@ +scoreboard players reset * adco.score +data modify storage adco:data root.temp set from storage adco:data root.players +function ~/render_loop +function ~/render_loop: + execute with storage adco:data root.temp[-1]: + $scoreboard players set $(name) adco.score $(points) + + data remove storage adco:data root.temp[-1] + execute if data storage adco:data root.temp[] run function ~/ diff --git a/src/data/adco/functions/reset.mcfunction b/src/data/adco/functions/reset.mcfunction index 3f7077e..1b48f9e 100644 --- a/src/data/adco/functions/reset.mcfunction +++ b/src/data/adco/functions/reset.mcfunction @@ -1,10 +1,8 @@ advancement revoke @a everything +data modify storage adco:data root.players set value [] -scoreboard objectives remove adco.score -scoreboard objectives add adco.score dummy -scoreboard objectives setdisplay list adco.score -scoreboard objectives modify adco.score rendertype integer +function adco:render tellraw @s: text: "Reset all Advancements for all current players" diff --git a/src/data/adco/functions/unlock_previous.mcfunction b/src/data/adco/functions/unlock_previous.mcfunction deleted file mode 100644 index 03c83e6..0000000 --- a/src/data/adco/functions/unlock_previous.mcfunction +++ /dev/null @@ -1,33 +0,0 @@ -from beet.contrib.vanilla import Vanilla - - -vanilla = ctx.inject(Vanilla) -vanilla_advancements = vanilla.releases["1.21"].data.advancements -for name, advancement in vanilla_advancements.items(): - if "recipes" in name: # Skip recipe unlocking advancements - continue - - # Create a predicate for the advancement to test if it has been unlocked - predicate_name = name.split(":")[1].replace("/", "-") - predicate_content = { - "condition": "minecraft:entity_properties", - "entity": "this", - "predicate": { - "type_specific": { - "type": "player", - "advancements": {} - } - } - } - predicate_content["predicate"]["type_specific"]["advancements"][name] = true - predicate f"adco:unlock_previous/{predicate_name}" predicate_content - - # Give the corresponding points to all players that have unlocked the advancement - advancement_content = advancement.data - advancement_display = advancement_content["display"] - if "frame" not in advancement_display or advancement_display["frame"] == "task": - execute if predicate f"adco:unlock_previous/{predicate_name}" run function adco:count/1 - elif advancement_display["frame"] == "goal": - execute if predicate f"adco:unlock_previous/{predicate_name}" run function adco:count/2 - elif advancement_display["frame"] == "challenge": - execute if predicate f"adco:unlock_previous/{predicate_name}" run function adco:count/5 diff --git a/src/data/adco/modules/advancements.bolt b/src/data/adco/modules/advancements.bolt index 127707d..e6c17a2 100644 --- a/src/data/adco/modules/advancements.bolt +++ b/src/data/adco/modules/advancements.bolt @@ -12,11 +12,6 @@ for name, advancement in vanilla_advancements.items(): modified_advancement["rewards"] = {} advancement_display = modified_advancement["display"] - if "frame" not in advancement_display or advancement_display["frame"] == "task": - modified_advancement["rewards"]["function"] = "adco:count/1" - elif advancement_display["frame"] == "goal": - modified_advancement["rewards"]["function"] = "adco:count/2" - elif advancement_display["frame"] == "challenge": - modified_advancement["rewards"]["function"] = "adco:count/5" + modified_advancement["rewards"]["function"] = "adco:recalculate" advancement name modified_advancement