Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-6213

MinecraftFont.getWidth(" ") returns 2 when it should be 3.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • Not related to error.

    • This server is running CraftBukkit version git-Spigot-57bbdd8-dea4138 (MC: 1.16.3) (Implementing API version 1.16.3-R0.1-SNAPSHOT)
    • Yes

      While making a book-parsing method I spent about a night and a morning trying to figure out why the line-wrapping was not working.

       

      To reproduce:

      MinecraftFont font = new MinecraftFont();
      System.out.println("pixels wide: " + font.getWidth("Homeblocks have an HP")); System.out.println("space char is " + font.getWidth(" ") + " pixels wide.");

      which will output:
      pixels wide: 112
      space char is 2 pixels wide.

      The maximum pixel count for a line is 113.
      The screenshot below shows how the above test string actually renders in game.

      The reference for the font shows the space character as having 3 pixels and I am inclined to believe them: https://minecraft.gamepedia.com/Language#Font after I added a pixel for every space to my line parser's lineWidth it worked perfectly.

        1. ticket1.PNG
          ticket1.PNG
          24 kB
        2. ticket2.png
          ticket2.png
          8 kB
        3. ticket3.png
          ticket3.png
          2 kB
        4. ticket4.png
          ticket4.png
          2 kB

            Unassigned Unassigned
            LlmDl Llm Dl
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: