Skip to content
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
3 changes: 3 additions & 0 deletions smithed_libraries/packs/actionbar/beet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ description: Native Actionbar Library for Smithed
data_pack:
name: Smithed Actionbar
load: .

require:
- bolt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@
# }
# ```
# The freeze value has a minimum value of 0 and a maximum value of 50.

#
# ## Additional Details
# When a message gets called to potentially display, the api will compare your message pack to the message
# that's currently being shown to the user. Your message will only display if:
# - Your priority is the same or lower than the current message
# - There is no current message (i.e. the freeze ran out)
# This is not the case if the current message is an "override".
# `priority: "override"` will continue to display **until** the freeze value counts down!

# get the message input
# @s = player that needs a new actionbar shown
Expand All @@ -62,6 +69,9 @@
# force-give player a priority score
scoreboard players add @s smithed.actionbar.priority 0

# if there is a message, but they forgot the priority, it should be the default
execute if data storage smithed.actionbar:input message run scoreboard players set $priority smithed.actionbar.temp 99

# convert string priority into number
# if we introduce new priorities in future versions
# we can renumber our ints w/o issues
Expand All @@ -74,15 +84,19 @@ execute unless data storage smithed.actionbar:input message.priority run scorebo
# grab freeze
# load default freeze if not defined
execute store result score $freeze smithed.actionbar.temp run data get storage smithed.actionbar:input message.freeze
execute unless data storage smithed.actionbar:input message.freeze run scoreboard players operation $freeze smithed.actionbar.temp = $default.freeze smithed.actionbar.const
execute
unless data storage smithed.actionbar:input message.freeze
run scoreboard players operation $freeze smithed.actionbar.temp = $default.freeze smithed.actionbar.const

# determine if display
# if priority is the same, check if freeze is 1..
# OR if priority is strictly lower,
# to determine if we display
# if priority is the same or lower AND current priority is not "override"
# OR if player has no shown actionbar
# then display the message
execute if score $priority smithed.actionbar.temp = @s smithed.actionbar.priority unless score @s smithed.actionbar.freeze matches 1.. run function smithed.actionbar:impl/display
execute if score $priority smithed.actionbar.temp < @s smithed.actionbar.priority run function smithed.actionbar:impl/display
execute
unless score @s smithed.actionbar.priority matches 1 # override notifications should not be "overriden"
if score $priority smithed.actionbar.temp <= @s smithed.actionbar.priority
run function smithed.actionbar:impl/display

execute if score @s smithed.actionbar.priority matches 0 run function smithed.actionbar:impl/display

# cleanup
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# @public

# @doc reset
# This function resets the current freeze and priority allowing you to display another message
# ```{admonition} ⚠️ Caution ⚠️
# :class: warning
# This api **will** disrupt other packs as it blatently resets the actionbar state.
# Do not use this in any normal circumstances, as it will break compatibility in most cases.
# ```

# resets player's actionbar scores so they can see any new actionbar
# @s = player that has a freeze score of 1
# located at @s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ scoreboard objectives add smithed.actionbar.const dummy
scoreboard objectives add smithed.actionbar.priority dummy
scoreboard objectives add smithed.actionbar.freeze dummy
scoreboard objectives add smithed.actionbar.sleep_t dummy

# We use score explicitly instead of sneaking predicate
# scores check for shift-key usage (intentional sneaking)
# predicates also check for force sneaking (like in 1x1 gap)
# Score's catch some false negatives that predicates would miss
scoreboard objectives add smithed.actionbar.sneaking minecraft.custom:minecraft.sneak_time

scoreboard players set $default.freeze smithed.actionbar.const 20
Expand Down