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
11 changes: 11 additions & 0 deletions packages/bolt/examples/weird_char/beet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

data_pack:
load: .

output: build

require:
- bolt

pipeline:
- mecha
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
say "🗡 "
tellraw @a {text: "🗡"}


recipe example:sharp_diamond {
"type":"minecraft:crafting_shapeless",
"ingredients":[["minecraft:diamond"]],
"result":{
"id":"minecraft:diamond",
"components":{"minecraft:item_name":"🗡"}
}
}
TEAM_1 = "duels.team_1"
TEAM_2 = "duels.team_2"

execute function ./load:
team add TEAM_1 "Duels Team 1"
team add TEAM_2 "Duels Team 2"

for team in [TEAM_1, TEAM_2]:
team modify team friendlyFire false
team modify team prefix "🗡 "
team modify team seeFriendlyInvisibles false

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Lectern snapshot

## Data pack

`@data_pack pack.mcmeta`

```json
{
"pack": {
"min_format": [
94,
1
],
"max_format": [
94,
1
],
"description": ""
}
}
```

### example

`@function example:say`

```mcfunction
say "🗡 "
tellraw @a {text: "\U0001f5e1"}
function example:load
```

`@function example:load`

```mcfunction
team add duels.team_1 "Duels Team 1"
team add duels.team_2 "Duels Team 2"
team modify duels.team_1 friendlyFire false
team modify duels.team_1 prefix "\U0001f5e1 "
team modify duels.team_1 seeFriendlyInvisibles false
team modify duels.team_2 friendlyFire false
team modify duels.team_2 prefix "\U0001f5e1 "
team modify duels.team_2 seeFriendlyInvisibles false
```

`@recipe example:sharp_diamond`

```json
{
"type": "minecraft:crafting_shapeless",
"ingredients": [
[
"minecraft:diamond"
]
],
"result": {
"id": "minecraft:diamond",
"components": {
"minecraft:item_name": "\ud83d\udde1"
}
}
}
```
10 changes: 10 additions & 0 deletions packages/mecha/src/mecha/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,18 @@ def handle_substitution(self, token: Token, match: "re.Match[str]") -> str:
return chr(int(unicode_hex, 16))
return super().handle_substitution(token, match)

def encode_non_bmp_char(self, codepoint: int) -> str:
return f"\\U{codepoint:08x}"

def handle_quoting(self, value: str) -> str:
value = super().handle_quoting(value)

def escape_char(char: str) -> str:
codepoint = ord(char)
if codepoint < 128:
return char
if codepoint > 65535:
return self.encode_non_bmp_char(codepoint)
return f"\\u{codepoint:04x}"

return "".join(escape_char(c) for c in value)
Expand All @@ -156,6 +161,11 @@ class JsonQuoteHelper(QuoteHelperWithUnicode):
}
)

def encode_non_bmp_char(self, codepoint: int) -> str:
low_surrogate = 0xD800 + ((codepoint - 0x10000) >> 10)
high_surrogate = 0xDC00 + (codepoint & 0x3FF)
return f"\\u{low_surrogate:04x}\\u{high_surrogate:04x}"


@dataclass
class NbtQuoteHelper(QuoteHelperWithUnicode):
Expand Down