Interface MapCanvas


public interface MapCanvas
A 128×128 grid of map pixels, see MapPalette.

Column 0 is on the left, row 0 at the top, as the map is seen in hand or in an item frame. Drawing outside the grid is silently clipped, so shapes and text can overflow the edges. Canvases are safe to draw on from any thread; group related changes in a batch(Consumer) so viewers never see half of them.

Since:
0.1.0
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The width and height of a canvas.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    batch(Consumer<? super MapCanvas> edits)
    Runs several changes at once: other threads, and viewers, see either none or all of them.
    void
    copy(MapCanvas source)
    Copies every pixel of another canvas, transparent ones included.
    void
    draw(MapImage image, int x, int y)
    Draws an image.
    void
    fill(byte pixel)
    Fills the whole canvas.
    void
    fill(int x, int y, int width, int height, byte pixel)
    Fills a rectangle.
    void
    line(int x1, int y1, int x2, int y2, byte pixel)
    Draws a straight line, both ends included.
    byte
    pixel(int x, int y)
    Returns a pixel.
    void
    pixel(int x, int y, byte pixel)
    Sets a pixel.
    byte[]
    Returns a copy of every pixel, row by row.
    void
    pixels(byte[] pixels)
    Replaces every pixel.
    void
    rectangle(int x, int y, int width, int height, byte pixel)
    Draws the outline of a rectangle, one pixel thick.
    int
    text(int x, int y, String text, byte pixel)
    Writes text in one color, with the standard font.
    int
    text(int x, int y, ComponentLike text, MapFont font, byte pixel, boolean shadow)
    Writes text.
  • Field Details

  • Method Details

    • pixel

      byte pixel(int x, int y)
      Returns a pixel.
      Parameters:
      x - the column
      y - the row
      Returns:
      the pixel, MapPalette.TRANSPARENT outside the canvas
      Since:
      0.1.0
    • pixel

      void pixel(int x, int y, byte pixel)
      Sets a pixel. Does nothing outside the canvas.
      Parameters:
      x - the column
      y - the row
      pixel - the pixel
      Since:
      0.1.0
    • batch

      void batch(Consumer<? super MapCanvas> edits)
      Runs several changes at once: other threads, and viewers, see either none or all of them.
      Parameters:
      edits - the changes, made on this canvas
      Since:
      0.1.0
    • pixels

      byte[] pixels()
      Returns a copy of every pixel, row by row.
      Returns:
      a copy of every pixel, row by row
      Since:
      0.1.0
    • pixels

      void pixels(byte[] pixels)
      Replaces every pixel.
      Parameters:
      pixels - 128×128 pixels, row by row
      Since:
      0.1.0
    • fill

      void fill(byte pixel)
      Fills the whole canvas.
      Parameters:
      pixel - the pixel, MapPalette.TRANSPARENT to clear
      Since:
      0.1.0
    • fill

      void fill(int x, int y, int width, int height, byte pixel)
      Fills a rectangle.
      Parameters:
      x - the left column
      y - the top row
      width - the width
      height - the height
      pixel - the pixel
      Since:
      0.1.0
    • rectangle

      void rectangle(int x, int y, int width, int height, byte pixel)
      Draws the outline of a rectangle, one pixel thick.
      Parameters:
      x - the left column
      y - the top row
      width - the width
      height - the height
      pixel - the pixel
      Since:
      0.1.0
    • line

      void line(int x1, int y1, int x2, int y2, byte pixel)
      Draws a straight line, both ends included.
      Parameters:
      x1 - the column of the start
      y1 - the row of the start
      x2 - the column of the end
      y2 - the row of the end
      pixel - the pixel
      Since:
      0.1.0
    • draw

      void draw(MapImage image, int x, int y)
      Draws an image. Transparent pixels of the image leave the canvas unchanged.
      Parameters:
      image - the image
      x - the column of the left edge of the image
      y - the row of its top edge
      Since:
      0.1.0
    • copy

      void copy(MapCanvas source)
      Copies every pixel of another canvas, transparent ones included.
      Parameters:
      source - the canvas to copy
      Since:
      0.1.0
    • text

      int text(int x, int y, String text, byte pixel)
      Writes text in one color, with the standard font.
      Parameters:
      x - the column where lines start
      y - the row of the top of the first line
      text - the text; \n starts a new line
      pixel - the color of the text
      Returns:
      the width of the widest line, in pixels
      Since:
      0.1.0
    • text

      int text(int x, int y, ComponentLike text, MapFont font, byte pixel, boolean shadow)
      Writes text.

      Each part of the text takes the map color closest to its color; parts without a color take pixel. Bold parts are drawn one pixel wider. Other decorations are ignored. Translatable parts show their fallback, or their key.

      Parameters:
      x - the column where lines start
      y - the row of the top of the first line
      text - the text; \n starts a new line
      font - the font
      pixel - the color of uncolored parts
      shadow - whether to draw a darker copy one pixel down and right first, like chat does
      Returns:
      the width of the widest line, in pixels
      Since:
      0.1.0