Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use data store for score tracking #29

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/data/adco/functions/core.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 0 additions & 9 deletions src/data/adco/functions/count.mcfunction

This file was deleted.

63 changes: 63 additions & 0 deletions src/data/adco/functions/recalculate.mcfunction
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions src/data/adco/functions/render.mcfunction
Original file line number Diff line number Diff line change
@@ -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 ~/
6 changes: 2 additions & 4 deletions src/data/adco/functions/reset.mcfunction
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
33 changes: 0 additions & 33 deletions src/data/adco/functions/unlock_previous.mcfunction

This file was deleted.

7 changes: 1 addition & 6 deletions src/data/adco/modules/advancements.bolt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading