Skip to content

Commit

Permalink
Item Detection: Document and follow new conventions
Browse files Browse the repository at this point in the history
This documents all functions and declarations in item detection (Work
towards #5).

This also renames some tremporary declarations to follow new conventions
better (work towards #4).
  • Loading branch information
NeunEinser committed Mar 11, 2021
1 parent a2967f6 commit 8b74b5d
Show file tree
Hide file tree
Showing 184 changed files with 2,350 additions and 420 deletions.
4 changes: 2 additions & 2 deletions data/bingo/functions/init/init.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ scoreboard objectives add bingo.const dummy
scoreboard objectives add bingo.schedule dummy

#>
# This objective holds the game state, such as wether a game is currently
# This objective holds the game state, such as whether a game is currently
# running
#
# @internal
scoreboard objectives add bingo.state dummy

#>
# Wether a game is currently in progress.
# Whether a game is currently in progress.
#
# @internal
#declare score_holder $game_in_progress
Expand Down
35 changes: 26 additions & 9 deletions data/bingo/functions/item_detection/helper/announce.mcfunction
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
#> bingo:item_detection/helper/announce
#
# This function is called to announce the item get of the current item.
#
# It also announces reaching a goal, when applicable
#
# @within bingo:item_detection/helper/check_and_announce

#>
# @private
#declare score_holder $item_detect/announce.has_bingo
#>
# @within
# function bingo:item_detection/helper/announce
# function bingo:item_detection/helper/goals/bingo/detect_bingo_and_20_no_bingo
#declare score_holder $item_detect/announce.items

# announce
execute in bingo:lobby run function neun_einser.timer:store_current_time

execute at @s run playsound minecraft:block.end_portal_frame.fill master @s ~ ~ ~ 1 2
tellraw @a {"translate": "bingo.got_item", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@s"}, {"storage": "bingo:card", "nbt": "slots[{selected: true}].item.textComponent", "interpret": true}]}

data modify storage bingo:tmp slots append from storage bingo:tmp previousSlots[]
data modify storage bingo:card teams[-1].slots set from storage bingo:tmp slots
execute store result score $item_detect/announce.has_bingo bingo.tmp run data get storage bingo:card teams[-1].hasBingo

execute store result score $has_bingo bingo.tmp run data get storage bingo:card teams[-1].hasBingo
execute store result score $items bingo.tmp run data get storage bingo:card teams[-1].itemCount
scoreboard players add $items bingo.tmp 1
execute store result storage bingo:card teams[-1].itemCount int 1 run scoreboard players get $items bingo.tmp
# Update item count
execute store result score $item_detect/announce.items bingo.tmp run data get storage bingo:card teams[-1].itemCount
scoreboard players add $item_detect/announce.items bingo.tmp 1
execute store result storage bingo:card teams[-1].itemCount int 1 run scoreboard players get $item_detect/announce.items bingo.tmp

execute if score $has_bingo bingo.tmp matches 0 run function bingo:item_detection/helper/goals/bingo/detect_bingo
execute if score $items bingo.tmp matches 25 run function bingo:item_detection/helper/goals/announce_blackout
# detect goals
execute if score $item_detect/announce.has_bingo bingo.tmp matches 0 run function bingo:item_detection/helper/goals/bingo/detect_bingo_and_20_no_bingo
execute if score $item_detect/announce.items bingo.tmp matches 25 run function bingo:item_detection/helper/goals/announce_blackout

# clear item
#You srsly can't append from a score directly?!
execute store result storage bingo:tmp player int 1 run scoreboard players get @s bingo.id
data modify storage bingo:card slots[{selected: true}].players append from storage bingo:tmp player

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#> bingo:item_detection/helper/check_and_announce
#
# This function checks whether @s' team already has obtained the currently
# selcted item. If they didn't it announces the item receivement and also
# checks if a goal was reached.
#
# @within bingo:item_detection/items/*
# @context entity Player who just obtained the item

function bingo:util/find_player_team

function bingo:item_detection/helper/set_border
execute if score $success bingo.tmp matches 1 run function bingo:item_detection/helper/announce
execute if score $item_detect/set_border.success bingo.tmp matches 1 run function bingo:item_detection/helper/announce

data modify storage bingo:card slots[{selected: true}].selected set value false
28 changes: 24 additions & 4 deletions data/bingo/functions/item_detection/helper/find_slot.mcfunction
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
data modify storage bingo:tmp slots append from storage bingo:tmp previousSlots[0]
data remove storage bingo:tmp previousSlots[0]
#> bingo:item_detection/helper/find_slot
#
# This function is used to iterate through the current slots until the correct
# one is found
#
# @within
# function bingo:item_detection/helper/find_slot
# function bingo:item_detection/helper/set_border
# @input score $item_detect/find_slot.slot_id bingo.tmp The slot id of the slot that is searched

scoreboard players remove $i bingo.tmp 1
execute if score $i bingo.tmp matches 0.. run function bingo:item_detection/helper/find_slot
#>
# The slot id of the slot that is searched
#
# This is an input for function bingo:item_detection/helper/find_slot
#
# @within
# function bingo:item_detection/helper/find_slot
# function bingo:item_detection/helper/set_border
#declare score_holder $item_detect/find_slot.slot_id

data modify storage temp:bingo.item_detection/set_border slots append from storage temp:bingo.item_detection/set_border previousSlots[0]
data remove storage temp:bingo.item_detection/set_border previousSlots[0]

scoreboard players remove $item_detect/find_slot.slot_id bingo.tmp 1
execute if score $item_detect/find_slot.slot_id bingo.tmp matches 0.. run function bingo:item_detection/helper/find_slot
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
#> bingo:item_detection/helper/goals/announce_20_no_bingo
#
# Announces a 20 no bingo and plays the goal completed effect for the entire
# team
#
# @within function bingo:item_detection/helper/goals/bingo/detect_bingo_and_20_no_bingo

tellraw @a {"translate": "bingo.got_20_no_bingo", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}]}
execute as @a[tag=bingo.in_current_team] at @s run function bingo:item_detection/helper/goals/completed_goal_effects
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
#> bingo:item_detection/helper/goals/announce_blackout
#
# Announces a blackout and plays the goal completed effect for the entire team
#
# @within function bingo:item_detection/helper/announce

tellraw @a {"translate": "bingo.got_blackout", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}]}
execute as @a[tag=bingo.in_current_team] at @s run function bingo:item_detection/helper/goals/completed_goal_effects
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
tellraw @a {"translate":"bingo.got_bingo.col", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$col", "objective": "bingo.tmp"}}]}
#> bingo:item_detection/helper/goals/bingo/announce/col
#
# Announces reaching a bingo in one column
#
# @within function bingo:item_detection/helper/goals/bingo/detect_bingo_and_20_no_bingo

tellraw @a {"translate":"bingo.got_bingo.col", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$item_detect/bingo.column", "objective": "bingo.tmp"}}]}

execute as @a[tag=bingo.in_current_team] at @s run function bingo:item_detection/helper/goals/completed_goal_effects

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
execute if score $diag bingo.tmp matches 1 run tellraw @a {"translate":"bingo.got_bingo.double.col_diag.top_left", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$col", "objective": "bingo.tmp"}}]}
execute if score $diag bingo.tmp matches 2 run tellraw @a {"translate":"bingo.got_bingo.double.col_diag.bottom_left", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$col", "objective": "bingo.tmp"}}]}
execute if score $diag bingo.tmp matches 3 run tellraw @a {"translate":"bingo.got_bingo.triple.col_diags", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$col", "objective": "bingo.tmp"}}]}
#> bingo:item_detection/helper/goals/bingo/announce/col_diag
#
# Announces reaching a bingo in a column and at least one diagonal
#
# @within function bingo:item_detection/helper/goals/bingo/detect_bingo_and_20_no_bingo

execute if score $item_detect/bingo.diagonal bingo.tmp matches 1 run tellraw @a {"translate":"bingo.got_bingo.double.col_diag.top_left", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$item_detect/bingo.column", "objective": "bingo.tmp"}}]}
execute if score $item_detect/bingo.diagonal bingo.tmp matches 2 run tellraw @a {"translate":"bingo.got_bingo.double.col_diag.bottom_left", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$item_detect/bingo.column", "objective": "bingo.tmp"}}]}
execute if score $item_detect/bingo.diagonal bingo.tmp matches 3 run tellraw @a {"translate":"bingo.got_bingo.triple.col_diags", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$item_detect/bingo.column", "objective": "bingo.tmp"}}]}

execute as @a[tag=bingo.in_current_team] at @s run function bingo:item_detection/helper/goals/completed_goal_effects

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
tellraw @a {"translate":"bingo.got_bingo.double.col_row", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$col", "objective": "bingo.tmp"}}, {"score": {"name": "$row", "objective": "bingo.tmp"}}]}
#> bingo:item_detection/helper/goals/bingo/announce/col_row
#
# Announces reaching a bingo in one column and one row
#
# @within function bingo:item_detection/helper/goals/bingo/detect_bingo_and_20_no_bingo

tellraw @a {"translate":"bingo.got_bingo.double.col_row", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$item_detect/bingo.column", "objective": "bingo.tmp"}}, {"score": {"name": "$item_detect/bingo.row", "objective": "bingo.tmp"}}]}

execute as @a[tag=bingo.in_current_team] at @s run function bingo:item_detection/helper/goals/completed_goal_effects

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
execute if score $diag bingo.tmp matches 1 run tellraw @a {"translate":"bingo.got_bingo.triple.top_left", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$col", "objective": "bingo.tmp"}}, {"score": {"name": "$row", "objective": "bingo.tmp"}}]}
execute if score $diag bingo.tmp matches 2 run tellraw @a {"translate":"bingo.got_bingo.triple.bottom_left", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$col", "objective": "bingo.tmp"}}, {"score": {"name": "$row", "objective": "bingo.tmp"}}]}
execute if score $diag bingo.tmp matches 3 run tellraw @a {"translate":"bingo.got_bingo.quadruple", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}]}
#> bingo:item_detection/helper/goals/bingo/announce/col_row_diag
#
# Announces reaching a bingo in one column, one row and at least one diagonal
#
# @within function bingo:item_detection/helper/goals/bingo/detect_bingo_and_20_no_bingo

execute if score $item_detect/bingo.diagonal bingo.tmp matches 1 run tellraw @a {"translate":"bingo.got_bingo.triple.top_left", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$item_detect/bingo.column", "objective": "bingo.tmp"}}, {"score": {"name": "$item_detect/bingo.row", "objective": "bingo.tmp"}}]}
execute if score $item_detect/bingo.diagonal bingo.tmp matches 2 run tellraw @a {"translate":"bingo.got_bingo.triple.bottom_left", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$item_detect/bingo.column", "objective": "bingo.tmp"}}, {"score": {"name": "$item_detect/bingo.row", "objective": "bingo.tmp"}}]}
execute if score $item_detect/bingo.diagonal bingo.tmp matches 3 run tellraw @a {"translate":"bingo.got_bingo.quadruple", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}]}

execute as @a[tag=bingo.in_current_team] at @s run function bingo:item_detection/helper/goals/completed_goal_effects

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
execute if score $diag bingo.tmp matches 1 run tellraw @a {"translate":"bingo.got_bingo.diag.top_left", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}]}
execute if score $diag bingo.tmp matches 2 run tellraw @a {"translate":"bingo.got_bingo.diag.bottom_left", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}]}
execute if score $diag bingo.tmp matches 3 run tellraw @a {"translate":"bingo.got_bingo.double.diags", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}]}
#> bingo:item_detection/helper/goals/bingo/announce/diag
#
# Announces reaching a bingo in at least one diagonal
#
# @within function bingo:item_detection/helper/goals/bingo/detect_bingo_and_20_no_bingo

execute if score $item_detect/bingo.diagonal bingo.tmp matches 1 run tellraw @a {"translate":"bingo.got_bingo.diag.top_left", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}]}
execute if score $item_detect/bingo.diagonal bingo.tmp matches 2 run tellraw @a {"translate":"bingo.got_bingo.diag.bottom_left", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}]}
execute if score $item_detect/bingo.diagonal bingo.tmp matches 3 run tellraw @a {"translate":"bingo.got_bingo.double.diags", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}]}

execute as @a[tag=bingo.in_current_team] at @s run function bingo:item_detection/helper/goals/completed_goal_effects

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
tellraw @a {"translate":"bingo.got_bingo.row", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$row", "objective": "bingo.tmp"}}]}
#> bingo:item_detection/helper/goals/bingo/announce/row
#
# Announces reaching a bingo in one row
#
# @within function bingo:item_detection/helper/goals/bingo/detect_bingo_and_20_no_bingo

tellraw @a {"translate":"bingo.got_bingo.row", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$item_detect/bingo.row", "objective": "bingo.tmp"}}]}

execute as @a[tag=bingo.in_current_team] at @s run function bingo:item_detection/helper/goals/completed_goal_effects

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
execute if score $diag bingo.tmp matches 1 run tellraw @a {"translate":"bingo.got_bingo.double.row_diag.top_left", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$row", "objective": "bingo.tmp"}}]}
execute if score $diag bingo.tmp matches 2 run tellraw @a {"translate":"bingo.got_bingo.double.row_diag.bottom_left", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$row", "objective": "bingo.tmp"}}]}
execute if score $diag bingo.tmp matches 3 run tellraw @a {"translate":"bingo.got_bingo.triple.row_diags", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$row", "objective": "bingo.tmp"}}]}
#> bingo:item_detection/helper/goals/bingo/announce/row_diag
#
# Announces reaching a bingo one row at least one diagonal
#
# @within function bingo:item_detection/helper/goals/bingo/detect_bingo_and_20_no_bingo

execute if score $item_detect/bingo.diagonal bingo.tmp matches 1 run tellraw @a {"translate":"bingo.got_bingo.double.row_diag.top_left", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$item_detect/bingo.row", "objective": "bingo.tmp"}}]}
execute if score $item_detect/bingo.diagonal bingo.tmp matches 2 run tellraw @a {"translate":"bingo.got_bingo.double.row_diag.bottom_left", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$item_detect/bingo.row", "objective": "bingo.tmp"}}]}
execute if score $item_detect/bingo.diagonal bingo.tmp matches 3 run tellraw @a {"translate":"bingo.got_bingo.triple.row_diags", "with": [{"storage": "neun_einser.timer:display", "nbt": "\"hh:mm:ss.s\"", "interpret": true}, {"selector": "@a[tag=bingo.in_current_team]"}, {"score": {"name": "$item_detect/bingo.row", "objective": "bingo.tmp"}}]}

execute as @a[tag=bingo.in_current_team] at @s run function bingo:item_detection/helper/goals/completed_goal_effects

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
data modify storage bingo:tmp icon set value '"\\uFFFF"'
execute store success score $success bingo.tmp run data modify storage bingo:tmp icon set from storage bingo:tmp slots[0]
execute if score $success bingo.tmp matches 1 run function bingo:item_detection/helper/goals/bingo/col/1/2
#> bingo:item_detection/helper/goals/bingo/col/1
#
# @within function bingo:item_detection/helper/goals/bingo/detect_bingo_and_20_no_bingo

#>
# @within
# function bingo:item_detection/helper/goals/bingo/col/1
# function bingo:item_detection/helper/goals/bingo/col/1/*
#declare storage temp:bingo.item_detect/bingo/col/1

#>
# @private
#declare score_holder $item_detect/bingo/col/1/1.success

data modify storage temp:bingo.item_detect/bingo/col/1 icon set value '"\\uFFFF"'
execute store success score $item_detect/bingo/col/1/1.success bingo.tmp run data modify storage temp:bingo.item_detect/bingo/col/1 icon set from storage temp:bingo.item_detect/bingo/col/1 slots[0]
execute if score $item_detect/bingo/col/1/1.success bingo.tmp matches 1 run function bingo:item_detection/helper/goals/bingo/col/1/2
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
execute store success score $success bingo.tmp run data modify storage bingo:tmp icon set from storage bingo:tmp slots[5]
execute if score $success bingo.tmp matches 0 run function bingo:item_detection/helper/goals/bingo/col/1/3
#> bingo:item_detection/helper/goals/bingo/col/1/2
#
# @within function bingo:item_detection/helper/goals/bingo/col/1

#>
# @private
#declare score_holder $item_detect/bingo/col/1/2.success

execute store success score $item_detect/bingo/col/1/2.success bingo.tmp run data modify storage temp:bingo.item_detect/bingo/col/1 icon set from storage temp:bingo.item_detect/bingo/col/1 slots[5]
execute if score $item_detect/bingo/col/1/2.success bingo.tmp matches 1 run function bingo:item_detection/helper/goals/bingo/col/1/3
Loading

0 comments on commit 8b74b5d

Please sign in to comment.