Negative Space Font

repository·master·Indexed 43 days ago

https://github.com/amberwat/negativespacefont

A Minecraft Java Edition resource and data pack providing a font with positive and negative spaces. It enables developers to manipulate text layout, overlap text, and shift elements horizontally using translation keys (space.<width>, offset.<width>, newlayer), magic digits for dynamic widths in data packs, or raw Unicode characters.

Tokens
1.2K
Snippets
4
Records
6
Agent score
6%

What's inside Negative Space Font

  1. Use Magic Digits in Data Packs

    master

    For data pack creators, Magic Digits allow for simple scoreboard math to display dynamic widths. These digits are reskinned into space characters.

    Requirements:

    • Requires Minecraft 1.16+ for multi-font support.
    • You must set the font to "font":"space:default" because these digits replace ordinary numbers.
    CharWidth
    91
    83
    78
    621
    555
    4144
    3377
    2987
    12584
    --6765

    Example JSON:

    [
    	{"text": "Start", "color": "blue"},
    	{"font": "space:default", "score": {"name": "spacer", "objective": "spacefont"}},
    	{"text": "End (moved by a dynamic amount)", "color": "red"}
    ]

    Helper Data Pack: If you load this as a data pack, you can use the function spacefont:magic_digits to convert a width between -6764 and 6764 into a set of magic digits.

    [
    	{"text": "Start", "color": "blue"},
    	{"font": "space:default", "score": {"name": "spacer", "objective": "spacefont"}},
    	{"text": "End (moved by a dynamic amount)", "color": "red"}
    ]
  2. Use `newlayer` to prevent rendering overlap issues

    master

    The newlayer translation key inserts a special character that splits the rendering of the current text. Everything following the split is rendered on a new layer on top of everything that came before. This is useful for preventing content from being hidden behind other elements, though it carries a slight performance penalty if used excessively.

    Example JSON:

    [
    	{"text": "Start", "color": "blue"},
    	{"translate": "space.-51"},
    	{"translate": "newlayer"},
    	{"text": "End (moved back 51 pixels and placed on a new layer)", "color": "red"}
    ]
    [
    	{"text": "Start", "color": "blue"},
    	{"translate": "space.-51"},
    	{"translate": "newlayer"},
    	{"text": "End (moved back 51 pixels and placed on a new layer)", "color": "red"}
    ]
  3. Use `offset.<width>` for advanced content positioning

    master

    The offset.<width> translation key is an advanced option. It inserts a space character, then your chosen content, and finally the opposite of the first space character. This allows you to offset specific content without affecting the position of surrounding text.

    Example JSON:

    [
    	"Unaffected part.",
    	{
    		"translate": "offset.-14",
    		"with": [{"text":"This part offset 14 pixels."}]
    	},
    	"Also an unaffected part."
    ]
    [
    	"Unaffected part.",
    	{
    		"translate": "offset.-14",
    		"with": [{"text":"This part offset 14 pixels."}]
    	},
    	"Also an unaffected part."
    ]
  4. Use translation keys for negative space (Recommended)

    master

    The easiest and most future-proof way to use this pack is via translation keys. This method allows the language file to handle the conversion into special characters, ensuring compatibility regardless of the active language.

    space.<width>

    Inserts only a space character of the specified width. This is the recommended method for basic spacing or overlapping.

    Example JSON:

    [
    	{"text": "Start", "color": "blue"},
    	{"translate": "space.-11"},
    	{"text": "End (moved back 11 pixels)", "color": "red"}
    ]
    [
    	{"text": "Start", "color": "blue"},
    	{"translate": "space.-11"},
    	{"text": "End (moved back 11 pixels)", "color": "red"}
    ]
  5. Supported width values for translation keys

    master

    When using space.<width> or offset.<width>, the <width> placeholder supports the following formats:

    • Integers: From -8192 to 8192 (e.g., space.691).
    • Aliases: max and -max (currently 8192 and -8192).
    • Fractions: In the form <numerator>/<denominator> where the value is between -1 and 1. Supported denominators: 2, 3, 4, 5, 6, 8, 10, 12, 15, 16, 20, 24, 25, 30, 32, 40, 48, 50, 60, 64, 75, 80, 96, 100 (e.g., space.39/60).
    • Infinities: infinity and -infinity (e.g., space.infinity).
  6. Advanced: Use raw character codes and escape sequences

    master

    If you are developing plugins or tools that do not support translation components or escape codes, you can use raw Unicode characters or escape sequences.

    Integer Widths

    Formula: 0xD0000 + width converted to a character (where -8192 <= width <= 8192).

    CharCodeFor MinecraftWidth
    󎀀\u{CE000}\uDAF8\uDC00-8192
    󐀀\u{D0000}\uDB00\uDC000
    󒀀\u{D2000}\uDB08\uDC008192

    Fraction Widths

    Formula: 0xD0000 + round(width * 4800) converted to a character (where -1 <= width <= 1).

    CharCodeFor MinecraftWidth
    񎵀\u{4ED40}\uD8FB\uDD40(-1) -4800/4800
    񐀀\u{50000}\uD900\uDC00(0) 0/4800
    񑋀\u{512C0}\uD904\uDEC0(1) 4800/4800

    Infinities and New Layer

    CharCodeFor MinecraftWidth/Type
    󀀁\u{C0001}\uDAC0\uDC01-infinity
    󟿿\u{DFFFF}\uDB3F\uDFFFinfinity
    󀀀\u{C0000}\uDAC0\uDC00newlayer

    Note: For codes above \uFFFF, use surrogate pairs (e.g., \uD800 through \uDFFF).