Class MapImage
java.lang.Object
studio.magemonkey.codex.mccore.gui.MapImage
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 -
Constructor Summary
ConstructorsConstructorDescriptionMapImage()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.Initializes a new MapImage from a file, converting it to a format that works better with the map canvasInitializes a new MapImage from an external URL, converting it to a format that works better with the map canvas. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the imageintdrawColorString(MapFont font, byte color, String str, int x, int y, char token) Draws a string to the imagevoidDraws an image onto this imageintdrawString(MapFont font, byte color, String str, int x, int y) Draws a string to the imagevoiddrawTo(org.bukkit.map.MapCanvas canvas, int x, int y) Draws the image to the canvas.voidfill(byte color) Fills the image with the given colorstatic ColorgetColor(byte id) Retrieves a color by a given Map Palette IDbyte[]getData()Retrieves the byte data of the imageintRetrieves the height of the imageintgetWidth()Retrieves the width of the imagestatic voidinit()static bytematchColor(Color color) Gets the closest color to the provided one that is available for the map canvas.
-
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 imageheight- 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
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
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
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
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
Draws an image onto this image- Parameters:
img- image to drawx- horizontal positiony- vertical position
-
drawString
Draws a string to the image- Parameters:
font- font to usecolor- color of the textstr- string to drawx- starting horizontal positiony- baseline position of the text- Returns:
- x-coordinate at the end of the render
-
drawColorString
Draws a string to the image- Parameters:
font- font to usecolor- starting color of the textstr- string to drawx- starting horizontal positiony- 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
-