Skip to content
stefvanschie edited this page Feb 1, 2020 · 2 revisions

Languages: Dutch (Nederlands)

A font is a set of characters with a specific theme that can be used with the Label component in order to visualize text. These fonts have mappings for heads which will be displayed to signify the usage of a specific character. Different fonts have different amounts of characters and not every character may be available. This is why each font also has a default character that is used in case the requested character does not exist.

Information regarding the default character and the characters available for a font can be found on there individual pages. There are currently 33 fonts available:

You can also make your own fonts if you wish to do so, which will be explained here.

Custom Fonts

If you feel like no currently available font satisfies your needs, or if you prefer to use a different one that doesn't exist yet, you can make your own font. There are two different ways to do this: you can make a csv file which will be used as the source of your font; or you can specify the items programmatically.

Using CSV Files

If you want to use a CSV file for your font, you'll first have to make a CSV file. This CSV file should consist of two columns. The left columns should be the character your trying to use. If you want to use special characters which may lead to file encoding issues, you may represent them as a unicode character in the \uHHHH format. In the right column you specify the value from the url to the head you wish to use on https://textures.minecraft.net/. If you for example have the following URL: http://textures.minecraft.net/texture/a044e9d19bef47933aff42bce4b458f431315090d613f54b6e795da59db9d0de the value you'd specify would be a044e9d19bef47933aff42bce4b458f431315090d613f54b6e795da59db9d0de. Each character should go on its own row.

Now you can add your font somewhere. It is recommended to only keep one instance of this font in memory as to avoid having to read out the CSV file multiple times. You can create the font by creating a new CSVFont.

Font font = new CSVFont(' ', "my-csv-file.csv");

In the first parameter you specify the default character to use in case the requested character wasn't found. In the second argument you specify the path to your CSV file.

In case you want to use your font from XML, you can register it by calling registerFont.

Font.registerFont("my font name", font);

Here, the first parameter is your font name and the second argument is your font.

Programmatically specifying items

You can also create a font without using CSV files. To do so, you first need to create a class that extends the base Font class.

public class MyFont extends Font {

    @Override
    public ItemStack getDefaultItem() {}

    @Override
    public ItemStack toItem(char character) {}

}

Let's start by creating the getDefaultItem method. Here you return the item that should be used if the specified character cannot be found. Keep in mind that, while you could only specify heads with CSV files, you can now specify an item you wish.

Now we can continue to the toItem method. This method should return the appropriate item for the specified character, or null if none is found. It's advisable to create a mapping between different characters and their respective items as to easily look up the item when requested, however you can crate this method however you see fit.

Once you're done you may want to register your font to be used by XML. You can register it by calling registerFont.

Font.registerFont("my font name", font);

Here, the first parameter is your font name and the second argument is your font.

Clone this wiki locally