下面列出了怎么用org.bukkit.map.MapPalette的API类实例代码及写法,或者点击链接到github查看源代码。
public void drawImage(int x, int y, Image image) {
byte[] bytes = MapPalette.imageToBytes(image);
for (int x2 = 0; x2 < image.getWidth(null); ++x2) {
for (int y2 = 0; y2 < image.getHeight(null); ++y2) {
setPixel(x + x2, y + y2, bytes[y2 * image.getWidth(null) + x2]);
}
}
}
public void drawText(int x, int y, MapFont font, String text) {
int xStart = x;
byte color = MapPalette.DARK_GRAY;
if (!font.isValid(text)) {
throw new IllegalArgumentException("text contains invalid characters");
}
for (int i = 0; i < text.length(); ++i) {
char ch = text.charAt(i);
if (ch == '\n') {
x = xStart;
y += font.getHeight() + 1;
continue;
} else if (ch == '\u00A7') {
int j = text.indexOf(';', i);
if (j >= 0) {
try {
color = Byte.parseByte(text.substring(i + 1, j));
i = j;
continue;
} catch (NumberFormatException ex) {
}
}
throw new IllegalArgumentException("Text contains unterminated color string");
}
CharacterSprite sprite = font.getChar(text.charAt(i));
for (int r = 0; r < font.getHeight(); ++r) {
for (int c = 0; c < sprite.getWidth(); ++c) {
if (sprite.get(r, c)) {
setPixel(x + c, y + r, color);
}
}
}
x += sprite.getWidth() + 1;
}
}
public void generate() {
this.clear();
for (int i = 0; i < 256; i++) {
try {
setColor((byte) i, MapPalette.getColor((byte) i));
} catch (Throwable t) {}
}
for (int r = 0; r < 256; r++) {
for (int g = 0; g < 256; g++) {
for (int b = 0; b < 256; b++) {
set(r, g, b, MapPalette.matchColor(r, g, b));
}
}
}
}
@Override
public void render(MapView mapView, MapCanvas mapCanvas, Player player) {
for (int x = 0; x < 128; x++) {
for (int z = 0; z < 128; z++) {
mapCanvas.setPixel(x, z, bitMatrix.get(x, z) ? FILL_COLOR : MapPalette.WHITE);
}
}
}
public void drawImage(int x, int y, Image image) {
byte[] bytes = MapPalette.imageToBytes(image);
for (int x2 = 0; x2 < image.getWidth(null); ++x2) {
for (int y2 = 0; y2 < image.getHeight(null); ++y2) {
setPixel(x + x2, y + y2, bytes[y2 * image.getWidth(null) + x2]);
}
}
}
public void drawText(int x, int y, MapFont font, String text) {
int xStart = x;
byte color = MapPalette.DARK_GRAY;
if (!font.isValid(text)) {
throw new IllegalArgumentException("text contains invalid characters");
}
for (int i = 0; i < text.length(); ++i) {
char ch = text.charAt(i);
if (ch == '\n') {
x = xStart;
y += font.getHeight() + 1;
continue;
} else if (ch == '\u00A7') {
int j = text.indexOf(';', i);
if (j >= 0) {
try {
color = Byte.parseByte(text.substring(i + 1, j));
i = j;
continue;
}
catch (NumberFormatException ex) {}
}
}
CharacterSprite sprite = font.getChar(text.charAt(i));
for (int r = 0; r < font.getHeight(); ++r) {
for (int c = 0; c < sprite.getWidth(); ++c) {
if (sprite.get(r, c)) {
setPixel(x + c, y + r, color);
}
}
}
x += sprite.getWidth() + 1;
}
}