-
Notifications
You must be signed in to change notification settings - Fork 11
feat: new title / subtitle library #52
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
Open
edayot
wants to merge
4
commits into
main
Choose a base branch
from
actionbar_change
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,7 @@ data_pack: | |
name: Smithed Actionbar | ||
load: . | ||
|
||
output: dist | ||
|
||
require: | ||
- bolt |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
24 changes: 24 additions & 0 deletions
24
smithed_libraries/packs/title/data/smithed.title/function/impl/display.mcfunction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
40 changes: 40 additions & 0 deletions
40
smithed_libraries/packs/title/data/smithed.title/function/impl/message.mcfunction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
10 changes: 10 additions & 0 deletions
10
smithed_libraries/packs/title/data/smithed.title/function/impl/reset.mcfunction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
12 changes: 12 additions & 0 deletions
12
smithed_libraries/packs/title/data/smithed.title/function/impl/technical/load.mcfunction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
11 changes: 11 additions & 0 deletions
11
smithed_libraries/packs/title/data/smithed.title/function/impl/technical/tick.mcfunction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.