-
-
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.
- Loading branch information
Showing
6 changed files
with
115 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,47 @@ | ||
"""Plugin that allows hanging indents to spread commands on multiple lines.""" | ||
|
||
|
||
__all__ = [ | ||
"fold_hanging_commands", | ||
] | ||
|
||
|
||
from typing import List | ||
|
||
from beet import Context | ||
|
||
|
||
def beet_default(ctx: Context): | ||
for function in ctx.data.functions.values(): | ||
function.lines = fold_hanging_commands(function.lines) | ||
|
||
|
||
def fold_hanging_commands(lines: List[str]) -> List[str]: | ||
"""Fold hanging commands on a single line.""" | ||
result = [] | ||
current, *lines = lines | ||
indentation = 0 | ||
hanging_blank_lines = 0 | ||
|
||
for line in lines: | ||
stripped = line.lstrip() | ||
|
||
if stripped: | ||
indentation = len(line) - len(stripped) | ||
|
||
if indentation > 0: | ||
if stripped.startswith("#"): | ||
result.append(stripped) | ||
elif stripped: | ||
hanging_blank_lines = 0 | ||
current += " " + stripped | ||
else: | ||
hanging_blank_lines += 1 | ||
else: | ||
result.append(current) | ||
result.extend([""] * hanging_blank_lines) | ||
current = stripped | ||
|
||
result.append(current) | ||
|
||
return result |
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 @@ | ||
{ | ||
"data_pack": { | ||
"load": ["src"] | ||
}, | ||
"pipeline": ["beet.contrib.hangman"] | ||
} |
37 changes: 37 additions & 0 deletions
37
tests/examples/load_hangman/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,37 @@ | ||
|
||
|
||
# This is the beginning | ||
|
||
say hello | ||
|
||
tellraw @s | ||
{ | ||
"text": "Hover me!", | ||
"hoverEvent": { | ||
"action": "show_text", | ||
"value": "Hi!" | ||
} | ||
} | ||
|
||
execute | ||
# When the player is on wool | ||
as @a | ||
at @s | ||
if block ~ ~-1 ~ #wool | ||
|
||
# Give a special stone block | ||
run give @s | ||
stone{ | ||
display: { | ||
Name: '[{ | ||
"text": "Hello", | ||
"bold": true | ||
}]', | ||
Lore: [ | ||
'[{ "text": "Something else here" }]' | ||
] | ||
} | ||
} | ||
1 | ||
|
||
say foo |
13 changes: 13 additions & 0 deletions
13
...build_load_hangman__0.data_pack/load_hangman_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,13 @@ | ||
|
||
|
||
# This is the beginning | ||
|
||
say hello | ||
|
||
tellraw @s { "text": "Hover me!", "hoverEvent": { "action": "show_text", "value": "Hi!" } } | ||
|
||
# When the player is on wool | ||
# Give a special stone block | ||
execute as @a at @s if block ~ ~-1 ~ #wool run give @s stone{ display: { Name: '[{ "text": "Hello", "bold": true }]', Lore: [ '[{ "text": "Something else here" }]' ] } } 1 | ||
|
||
say foo |
6 changes: 6 additions & 0 deletions
6
tests/snapshots/examples__build_load_hangman__0.data_pack/load_hangman_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
...hots/examples__build_load_hangman__1.resource_pack/load_hangman_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": "" | ||
} | ||
} |