Class MapImage

java.lang.Object
studio.magemonkey.codex.mccore.gui.MapImage
Direct Known Subclasses:
MapBuffer, MapString

public class MapImage extends Object
Represents an image in the format used by Minecraft maps to speed up the drawing process. MapImages loaded from files/URLs can take a little while to load though, so set them up on enable to avoid any stalls during the game.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initializes a default map image matching the size of a general map (128x128).
    MapImage(int[] size)
    Creates an empty image with a format that works better with the map canvas.
    MapImage(int width, int height)
    Creates an empty image with a format that works better with the map canvas.
    MapImage(File file)
    Initializes a new MapImage from a file, converting it to a format that works better with the map canvas
    Initializes a new MapImage from an external URL, converting it to a format that works better with the map canvas.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears the image
    int
    drawColorString(MapFont font, byte color, String str, int x, int y, char token)
    Draws a string to the image
    void
    drawImg(MapImage img, int x, int y)
    Draws an image onto this image
    int
    drawString(MapFont font, byte color, String str, int x, int y)
    Draws a string to the image
    void
    drawTo(org.bukkit.map.MapCanvas canvas, int x, int y)
    Draws the image to the canvas.
    void
    fill(byte color)
    Fills the image with the given color
    static Color
    getColor(byte id)
    Retrieves a color by a given Map Palette ID
    byte[]
    Retrieves the byte data of the image
    int
    Retrieves the height of the image
    int
    Retrieves the width of the image
    static void
     
    static byte
    Gets the closest color to the provided one that is available for the map canvas.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • offset

      protected int offset
  • Constructor Details

    • MapImage

      public MapImage()
      Initializes a default map image matching the size of a general map (128x128).
    • MapImage

      public MapImage(int width, int height)
      Creates an empty image with a format that works better with the map canvas.
      Parameters:
      width - width of the image
      height - height of the image
    • MapImage

      public MapImage(int[] size)
      Creates an empty image with a format that works better with the map canvas.
      Parameters:
      size - size of the image { width, height }
    • MapImage

      public MapImage(URL url) throws IOException
      Initializes a new MapImage from an external URL, converting it to a format that works better with the map canvas.
      Parameters:
      url - URL to load from
      Throws:
      IOException
    • MapImage

      public MapImage(File file) throws IOException
      Initializes a new MapImage from a file, converting it to a format that works better with the map canvas
      Parameters:
      file - file to load from
      Throws:
      IOException
  • Method Details

    • init

      public static void init()
    • matchColor

      public static byte matchColor(Color color)
      Gets the closest color to the provided one that is available for the map canvas.
      Parameters:
      color - color to convert to a map palette color
      Returns:
      map palette color closest to the original
    • getColor

      public static Color getColor(byte id)
      Retrieves a color by a given Map Palette ID
      Parameters:
      id - map palette ID
      Returns:
      java color represented by the ID
    • getData

      public byte[] getData()
      Retrieves the byte data of the image
      Returns:
      byte data of the image
    • getHeight

      public int getHeight()
      Retrieves the height of the image
      Returns:
      height of the image
    • getWidth

      public int getWidth()
      Retrieves the width of the image
      Returns:
      width of the image
    • clear

      public void clear()
      Clears the image
    • fill

      public void fill(byte color)
      Fills the image with the given color
      Parameters:
      color - color to fill
    • drawImg

      public void drawImg(MapImage img, int x, int y)
      Draws an image onto this image
      Parameters:
      img - image to draw
      x - horizontal position
      y - vertical position
    • drawString

      public int drawString(MapFont font, byte color, String str, int x, int y)
      Draws a string to the image
      Parameters:
      font - font to use
      color - color of the text
      str - string to draw
      x - starting horizontal position
      y - baseline position of the text
      Returns:
      x-coordinate at the end of the render
    • drawColorString

      public int drawColorString(MapFont font, byte color, String str, int x, int y, char token)
      Draws a string to the image
      Parameters:
      font - font to use
      color - starting color of the text
      str - string to draw
      x - starting horizontal position
      y - baseline position of the text
      Returns:
      x-coordinate at the end of the render
    • drawTo

      public void drawTo(org.bukkit.map.MapCanvas canvas, int x, int y)
      Draws the image to the canvas. Normally you should instead draw to a MapBuffer and then draw the mapBuffer to the canvas unless you are only drawing a single small image.
      Parameters:
      canvas - canvas to draw to