Skip to main content

A parser to convert a descriptive text format into minecraft text components

Project description

Allay

A parser to convert a descriptive text format into minecraft text components

Getting Started

First, install the package with pip install allay. Next, create a python script and import allay.

Usage is extremely simple:

import allay 

parser = allay.Parser()
text_component = parser.parse(string)

Format

Allay uses a markdown-inspired format. To start, we'll define our types.

  • string - "string"
  • integer - 49
  • url/link - "https://example.com"
  • boolean - true/false
  • hex code - #ff0000 or any built-in color: red/blue/black/etc.
  • scope block - <text>. Scope blocks are just like normal text, except any modifier that involves clicking or hovering cannot be used and will raise an error. They are only used in hover_text, and can use normal modifiers like bold, color, or font.
  • selector - @e[type=minecraft:allay]
  • json - {"text": "Hello, World"}
  • keybind - Any valid keybind. Should not include the key.. key.advancements should be input as advancements.

Text is interpreted as exactly that, text. To format our text, we'll need to put it in what's called a text isolator, which is just text wrapped in square brackets. Then, we'll attach a modifier block to it. A modifier block is just a set of key value pairs (some exceptions apply) wrapped in parenthesis. For instance: (color=blue, bold=true) is a modifier block. Attaching a text isolator and a modifier block is as simple as putting them next to each other, like so: [text](color=blue).

If more than one modifier needs to be specified, they should be separated by commas: (color=white, insertion="You shift clicked the chat")

Modifiers should always be a set of key and value pairs separated by an equal sign. The only exceptions to this are:

  • Links are automatically inferred if they begin with https:// or http://
  • Hex codes are automatically interpreted as colors
  • bold, italic, strikethrough, underlined, and obfuscated do not require =true. Instead, you can just add the keywords. These two samples are equivalent: [text](bold=true, italic=true) - [text](bold, italic).

Here's a full list of all valid modifiers and their expected types (not including the exceptions listed above):

  • hover_item - json, should describe contents.show_item as demonstrated here.
  • hover_text - scope block
  • color - color
  • link - url
  • font - string
  • copy - font
  • suggest - string
  • run - string
  • insertion - string
  • page - integer
  • bold - boolean
  • italic - boolean
  • strikethrough - boolean
  • underlined - boolean
  • obfuscated - boolean

Modifier blocks can also be applied to standalone blocks. Standalone blocks are used to show entity selectors, translation keys, keybinds, and NBT selectors. They are also given in key value pairs, however, unlike modifier blocks, multiple standalone blocks cannot be combined. Every individual component of a standalone block should be separated by commas.

Here is a list of all valid arguments in a standalone block:

  • selector - selector
  • translate - string, specifies the translation key
  • with - json, optional. Only used with translate and must be used after translate.
  • nbt - string, defines the NBT path on the location specified
  • block/entity/storage - string, defines the location that the NBT path should be looked up in. Selectors and coordinates should be put in strings as well ("@s" / "83 76 239") Must be included with nbt.
  • sep or separator - Optional. Defines the string that should be inserted between entity/NBT selectors that target multiple values. Only used with nbt and selector. Must be specified last.
  • key - keybind

And some examples:

  • {@s}
  • {@s, sep=" - "}
  • {@s, separator=" - "}
  • {translate="k:ey"}
  • {translate="k:ey", with=["raw", "json"]}
  • {nbt="path", entity="@s"}
  • {nbt="path", block="88 72 239", sep=" : "}
  • {nbt="path", storage="store:age", sep="><"}
  • {key=advancements}
  • {@s}(hover_text=<gone fancy>, #00aced)

If you have any questions, need any help, etc., feel free to make an issue with your question.


Credits

  • fizzy/vberlier - Creator of TokenStream. Helped walk me through using it and any issues I had. 10/10 customer service.
  • Amber - Helped with designing the Allay format, gave me the idea in the first place
  • nphhpn, vdvman1, discohund, Repertor, miestrode, rx, Ravbug, Ersatz, and a bunch of others on the Minecraft Commands Discord - Helped walk me through the process (and grief) of creating a parser by hand before I started using TokenStream.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

allay-1.0.0.tar.gz (8.0 kB view hashes)

Uploaded Source

Built Distribution

allay-1.0.0-py3-none-any.whl (8.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page