Skip to content
Open
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
2 changes: 2 additions & 0 deletions smithed_libraries/packs/actionbar/beet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ data_pack:
name: Smithed Actionbar
load: .

output: dist

require:
- bolt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ scoreboard players set $min.freeze smithed.actionbar.const 0
scoreboard players set #100 smithed.actionbar.const 100

schedule function smithed.actionbar:impl/technical/tick 1t

function smithed.title:impl/technical/load
schedule function smithed.title:impl/technical/tick 1t
10 changes: 10 additions & 0 deletions smithed_libraries/packs/title/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Title
This library helps multiple data packs manage title & subtitle by aggregating usage by priority. This allows persistent messages to display without interrupting more urgent notification type messages.

## Usage
For usage information, see the [documentation](https://wiki.smithed.dev/libraries/smithed-core)
## Downloading
You can download this library from [the website](https://smithed.dev/packs/smithed/title)
or
You can build it from source using [beet](https://github.com/mcbeet/beet)

15 changes: 15 additions & 0 deletions smithed_libraries/packs/title/beet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extend: "@smithed_libraries/common.yaml"

id: smithed.title
name: Smithed Title
version: "0.0.1"
description: Native Title Library for Smithed

data_pack:
name: Smithed Title
load: .

output: dist

require:
- bolt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# display the message to the player
# @s = player that needs a new title shown
# location undefined; based on how the user calls the function
# run from message

# yes, if you define raw and json, you'll get 2 messages
# i left this "bug" in so that folks catch this in testing

execute if data storage smithed.title:input message.subtitle_raw run title @s subtitle {"storage": "smithed.title:input", "nbt": "message.subtitle_raw"}
execute if data storage smithed.title:input message.subtitle_json run title @s subtitle {"storage": "smithed.title:input", "nbt": "message.subtitle_json", "interpret": true}

execute if data storage smithed.title:input message.title_raw run title @s title {"storage": "smithed.title:input", "nbt": "message.title_raw"}
execute if data storage smithed.title:input message.title_json run title @s title {"storage": "smithed.title:input", "nbt": "message.title_json", "interpret": true}


# copy freeze w/ bounds checking
scoreboard players operation @s smithed.title.freeze = $freeze smithed.title.temp
scoreboard players operation @s smithed.title.freeze > $min.freeze smithed.title.const
scoreboard players operation @s smithed.title.freeze < $max.freeze smithed.title.const

# unless freeze is explicitly 0, copy priority
# allows folks to let their messages disappear
# prolly won't interact nicely w/ persistent messages
execute unless score @s smithed.title.freeze matches 0 run scoreboard players operation @s smithed.title.priority = $priority smithed.title.temp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# @public

# get the message input
# @s = player that needs a new title shown
# location undefined; based on how the user calls the function
# run from #smithed.title:message

# force-give player a priority score
scoreboard players add @s smithed.title.priority 0

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

# convert string priority into number
# if we introduce new priorities in future versions
# we can renumber our ints w/o issues
execute if data storage smithed.title:input message{priority:'override'} run scoreboard players set $priority smithed.title.temp 1
execute if data storage smithed.title:input message{priority:'notification'} run scoreboard players set $priority smithed.title.temp 2
execute if data storage smithed.title:input message{priority:'conditional'} run scoreboard players set $priority smithed.title.temp 3
execute if data storage smithed.title:input message{priority:'persistent'} run scoreboard players set $priority smithed.title.temp 4
execute unless data storage smithed.title:input message.priority run scoreboard players set $priority smithed.title.temp 99

# grab freeze
# load default freeze if not defined
execute store result score $freeze smithed.title.temp run data get storage smithed.title:input message.freeze
execute
unless data storage smithed.title:input message.freeze
run scoreboard players operation $freeze smithed.title.temp = $default.freeze smithed.title.const

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# @public

# resets player's title scores so they can see any new title
# @s = player that has a freeze score of 1
# located at @s
# run from technical/tick


scoreboard players reset @s smithed.title.freeze
scoreboard players set @s smithed.title.priority 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
scoreboard objectives add smithed.title.temp dummy
scoreboard objectives add smithed.title.const dummy
scoreboard objectives add smithed.title.priority dummy
scoreboard objectives add smithed.title.freeze dummy


scoreboard players set $default.freeze smithed.title.const 20
scoreboard players set $max.freeze smithed.title.const 50
scoreboard players set $min.freeze smithed.title.const 0
scoreboard players set #100 smithed.title.const 100

schedule function smithed.title:impl/technical/tick 1t
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# loop every tick
schedule function smithed.title:impl/technical/tick 1t replace

# reset scores when at 1
execute as @a[scores={smithed.title.freeze=1}] run function smithed.title:impl/reset

# decrement everyone's score
scoreboard players remove @a[scores={smithed.title.freeze=1..}] smithed.title.freeze 1

# reset sneak_time score
scoreboard players reset @a smithed.title.sneaking
Binary file added smithed_libraries/packs/title/pack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.