book-n-quill
v1.0.0
Published
A library to convert BBCode-like strings to Minecraft JSON formatted text
Downloads
2
Readme
Formatting:
This is plain text.
This text is [b]bold[/b].
This text is [i]italic[/i], [s]strikethrough[/s].
This is [u]underlined[/u], this is [o]obfuscated[/o].
This [color=red]text[/color] is [color=#00aaee]colored[/color].
[font=minecraft:alt]This[/font] has different font.
Interactivity
[url=google.com]Open Google[/url]
[file=%appdata%/.minecraft/log/latest.log]Open the console log[/file]
[run=say hello @a[distance=..10] :D]Say hello to the neighbors![/run]
[suggest=say hi]Now you should say hi :D[/suggest]
[page=3]Go to page 3[/page]
[copy=ur cute <3]Just a simple copy, don't worry[/copy]
[text=This is shown on hover, it can do [b]this[/b]!]Boo![/text]
[item=minecraft:stick|count=4|tag={display:{Name:'"something idk"'}}]Show an item on hover[/item]
[entity=minecraft:skeleton|name=Boo!]Scary stuff![/entity]
[insert=I'm in your chat now]Hey, click this[/insert]
Content
[score=count|objective=temp/]
Look at yourself: [selector=@s/]
This is how you move forward: [key=key.forward/]
Let's peek inside the shulker box: [nbt=Items|block=~ ~ ~/]
and yourself: [nbt=Inventory|entity=@s/]
or your private storage: [nbt=items|storage=my:private/storage/]
[translate=This is not supported yet because I don't really know how translate works/]
Mixed
You [b]can [i]mix [selector=@s/][text=scary stuff]things[/text] just fine[/i][/b]
Custom tags
You can define custom tags like this:
class MyParser extends Parser {
constructor() {
super(
// this one is the formatting + interactivity tags, the tags mustn't be self-closing
{
// it can only return formatting or interactivity
golden: () => ({
color: 'gold'
})
},
// this one is for content tags, these tags must be self-closing
{
myScore: ({ source, notMine }) => ({
score: {
name: source,
objective: `this_is_${notMine ? 'not' : ''}mine`
}
}),
// it can return any valid JSON text structure
blackSelf: () => ({
selector: '@s',
color: 'black'
})
}
)
}
}
Then, parsing
[golden]Some golden [myScore|source=height|notMine/][/golden]
[blackSelf/]
with the new parser giving the same result as
[color=gold]Some golden [score=height|objective=this_is_notmine/][/color]
[color=black][selector=@s/][/color]
This is the compiled result of the texts above:
{"text":"This is plain text."}
["This text is ",{"bold":true,"text":"bold"},"."]
["This text is ",{"italic":true,"text":"italic"},", ",{"strikethrough":true,"text":"strikethrough"},"."]
["This is ",{"underlined":true,"text":"underlined"},", this is ",{"obfuscated":true,"text":"obfuscated"},"."]
["This ",{"color":"red","text":"text"}," is ",{"color":"#00aaee","text":"colored"},"."]
[{"font":"minecraft:alt","text":"This"}," has different font"]
{"clickEvent":{"action":"open_url","value":"google.com"},"text":"Open Google"}
{"clickEvent":{"action":"open_file","value":"%appdata%/.minecraft/log/latest.log"},"text":"Open the console log"}
{"clickEvent":{"action":"run_command","value":"say hello @a[distance=..10] :D"},"text":"Say hello to the neighbors!"}
{"clickEvent":{"action":"suggest_command","value":"say hi"},"text":"Now you should say hi :D"}
{"clickEvent":{"action":"change_page","value":"3"},"text":"Go to page 3"}
{"clickEvent":{"action":"copy_to_clipboard","value":"ur cute <3"},"text":"Just a simple copy, don't worry"}
{"hoverEvent":{"action":"show_text","contents":["This is shown on hover, it can do ",{"bold":true,"text":"this"},"!"]},"text":"Boo!"}
{"hoverEvent":{"action":"show_item","contents":{"id":"minecraft:stick","count":4,"tag":"{display:{Name:'\"something idk\"'}}"}},"text":"Show an
item on hover"}
{"hoverEvent":{"action":"show_entity","contents":{"type":"minecraft:skeleton","name":"Boo!","id":"0000001c-000f-000a-0000-000000000bd7"}},"text":"Scary stuff!"}
{"insertion":"I'm in your chat now","text":"Hey, click this"}
{"score":{"name":"count","objective":"temp"}}
["Look at yourself: ",{"selector":"@s"}]
["This is how you move forward: ",{"keybind":"key.forward"}]
["Let's peek inside the shulker box: ",{"nbt":"Items","block":"~ ~ ~"}]
["and yourself: ",{"nbt":"Inventory","entity":"@s"}]
["or your private storage (/ must be escaped): ",{"nbt":"items","storage":"my:private/storage"}]
["You ",[{"bold":true,"text":""},"can ",[{"italic":true,"text":""},"mix ",{"selector":"@s"},{"hoverEvent":{"action":"show_text","contents":{"text":"scary stuff"}},"text":"things"}," just fine"]]]
[{"color":"golden","text":""},"Some golden ",{"score":{"name":"height","objective":"this_is_notmine"}}]
[{"bold":true,"text":""},"asd",{"selector":"@s","color":"black"}]