-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add generate.objective() and beet.contrib.scoreboard
- Loading branch information
Showing
17 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
"""Plugin that adds generated scoreboards to the data pack.""" | ||
|
||
|
||
__all__ = [ | ||
"scoreboard", | ||
] | ||
|
||
|
||
from typing import Iterable, cast | ||
|
||
from beet import Context, Function, Plugin | ||
from beet.core.utils import JsonDict | ||
|
||
|
||
def beet_default(ctx: Context): | ||
config = ctx.meta.get("scoreboard", cast(JsonDict, {})) | ||
|
||
function = config.get("function", "{namespace}:{path}scoreboard") | ||
tags = config.get("tags", ["minecraft:load"]) | ||
|
||
ctx.require(scoreboard(function, tags)) | ||
|
||
|
||
def scoreboard( | ||
function: str = "{namespace}:{path}scoreboard", | ||
tags: Iterable[str] = ("minecraft:load",), | ||
) -> Plugin: | ||
"""Return a plugin that adds generated scoreboards to the data pack.""" | ||
|
||
def plugin(ctx: Context): | ||
if scoreboard_data := ctx.meta.get("generate_scoreboard"): | ||
commands = [ | ||
f"scoreboard objectives add {name} {criterion}" | ||
for name, criterion in scoreboard_data.items() | ||
] | ||
|
||
ctx.generate(function, Function(commands, prepend_tags=list(tags))) | ||
scoreboard_data.clear() | ||
|
||
return plugin |
This file contains 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
This file contains 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
This file contains 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,8 @@ | ||
{ | ||
"pipeline": ["demo", "beet.contrib.scoreboard"], | ||
"meta": { | ||
"scoreboard": { | ||
"function": "{namespace}:add_objectives" | ||
} | ||
} | ||
} |
This file contains 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,18 @@ | ||
from beet import Context | ||
|
||
|
||
def beet_default(ctx: Context): | ||
ctx.generate.objective() | ||
ctx.generate.objective("{hash}", "something") | ||
ctx.generate.objective("hello", criterion="playerKillCount") | ||
ctx.generate.objective("world", display="Something") | ||
|
||
generate = ctx.generate["foo"]["bar"] | ||
generate.objective() | ||
generate.objective("{hash}", "something") | ||
generate.objective("hello", criterion="playerKillCount") | ||
generate.objective("world", display="Something") | ||
|
||
ctx.generate.objective( | ||
"{hash}", "something", display={"text": "Update name", "color": "red"} | ||
) |
This file contains 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,14 @@ | ||
{ | ||
"data_pack": { | ||
"load": ["src"], | ||
"render": { | ||
"functions": ["*"] | ||
} | ||
}, | ||
"pipeline": ["beet.contrib.scoreboard"], | ||
"meta": { | ||
"generate_scoreboard": { | ||
"from_config": "dummy" | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
examples/load_scoreboard/src/data/demo/functions/foo.mcfunction
This file contains 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 @@ | ||
#!set obj1 = ctx.generate.objective() | ||
#!set obj2 = ctx.generate.objective("foo") | ||
|
||
scoreboard players operation @s {{ obj1 }} += @s {{ obj2 }} | ||
|
||
#!set generate = ctx.generate["thing"] | ||
#!set obj1 = generate.objective() | ||
#!set obj2 = generate.objective("foo") | ||
|
||
scoreboard players operation @s {{ obj1 }} += @s {{ obj2 }} |
8 changes: 8 additions & 0 deletions
8
...ild_code_scoreboard__0.data_pack/data/code_scoreboard/functions/add_objectives.mcfunction
This file contains 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,8 @@ | ||
scoreboard objectives add 2ZVpgb8kGcG dummy "code_scoreboard.0" | ||
scoreboard objectives add 7TSQihUbNLa dummy {"text": "Update name", "color": "red"} | ||
scoreboard objectives add c27bB4cS5F6 playerKillCount "code_scoreboard.hello" | ||
scoreboard objectives add 9WJtktDktnC dummy "Something" | ||
scoreboard objectives add F3hNMFMkWK1 dummy "code_scoreboard.foo.bar.0" | ||
scoreboard objectives add bCnEsPUVaU1 dummy "code_scoreboard.foo.bar.gJha1dTMehg" | ||
scoreboard objectives add XFFrTkAcRD9 playerKillCount "code_scoreboard.foo.bar.hello" | ||
scoreboard objectives add 5SYSLQGpc3D dummy "Something" |
5 changes: 5 additions & 0 deletions
5
...hots/examples__build_code_scoreboard__0.data_pack/data/minecraft/tags/functions/load.json
This file contains 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,5 @@ | ||
{ | ||
"values": [ | ||
"code_scoreboard:add_objectives" | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
tests/snapshots/examples__build_code_scoreboard__0.data_pack/pack.mcmeta
This file contains 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,6 @@ | ||
{ | ||
"pack": { | ||
"pack_format": 6, | ||
"description": "" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
tests/snapshots/examples__build_code_scoreboard__1.resource_pack/pack.mcmeta
This file contains 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,6 @@ | ||
{ | ||
"pack": { | ||
"pack_format": 6, | ||
"description": "" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...snapshots/examples__build_load_scoreboard__0.data_pack/data/demo/functions/foo.mcfunction
This file contains 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,3 @@ | ||
scoreboard players operation @s bT7PpNaNgfP += @s 9fP76NV5kv5 | ||
|
||
scoreboard players operation @s U466Vqh61Yo += @s baxdp7xLz9q |
5 changes: 5 additions & 0 deletions
5
...__build_load_scoreboard__0.data_pack/data/load_scoreboard/functions/scoreboard.mcfunction
This file contains 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,5 @@ | ||
scoreboard objectives add from_config dummy | ||
scoreboard objectives add bT7PpNaNgfP dummy "load_scoreboard.0" | ||
scoreboard objectives add 9fP76NV5kv5 dummy "load_scoreboard.foo" | ||
scoreboard objectives add U466Vqh61Yo dummy "load_scoreboard.thing.0" | ||
scoreboard objectives add baxdp7xLz9q dummy "load_scoreboard.thing.foo" |
5 changes: 5 additions & 0 deletions
5
...hots/examples__build_load_scoreboard__0.data_pack/data/minecraft/tags/functions/load.json
This file contains 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,5 @@ | ||
{ | ||
"values": [ | ||
"load_scoreboard:scoreboard" | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
tests/snapshots/examples__build_load_scoreboard__0.data_pack/pack.mcmeta
This file contains 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,6 @@ | ||
{ | ||
"pack": { | ||
"pack_format": 6, | ||
"description": "" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
tests/snapshots/examples__build_load_scoreboard__1.resource_pack/pack.mcmeta
This file contains 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,6 @@ | ||
{ | ||
"pack": { | ||
"pack_format": 6, | ||
"description": "" | ||
} | ||
} |
This file contains 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