本文整理汇总了Java中org.bukkit.map.MapPalette类的典型用法代码示例。如果您正苦于以下问题:Java MapPalette类的具体用法?Java MapPalette怎么用?Java MapPalette使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MapPalette类属于org.bukkit.map包,在下文中一共展示了MapPalette类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMapPalette
import org.bukkit.map.MapPalette; //导入依赖的package包/类
/**
* Initialize the map palette
*
* @return Map pallete
*/
private static IColorPalette getMapPalette() {
List<Color> result = new ArrayList<Color>();
try {
for (int i = 0; i < 256; i++) {
Color c = MapPalette.getColor((byte)i);
if (c.getAlpha()<128)
{
continue;
}
result.add(c);
}
} catch (Exception ex) {
//Ignore exception
}
return new ColorPalette(result.toArray(new Color[0]));
}
示例2: ImgRenderer
import org.bukkit.map.MapPalette; //导入依赖的package包/类
/**
* Initialize new instance of the class
* @param img The image to draw on the map
*/
public ImgRenderer(BufferedImage img) {
super(false);
int hh = Math.min(img.getHeight(), MAX_SIZE);
int ww = Math.min(img.getWidth(), MAX_SIZE);
BufferedImage lImg;
if (hh != MAX_SIZE || ww != MAX_SIZE) {
lImg = new BufferedImage(MAX_SIZE, MAX_SIZE, BufferedImage.TYPE_4BYTE_ABGR);
Graphics g = lImg.getGraphics();
g.drawImage(img, 0, 0, null);
g.dispose();
} else {
lImg = img;
}
m_isRendered = false;
m_img = MapPalette.imageToBytes(lImg);
}
示例3: drawImage
import org.bukkit.map.MapPalette; //导入依赖的package包/类
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]);
}
}
}
示例4: drawText
import org.bukkit.map.MapPalette; //导入依赖的package包/类
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;
}
}
示例5: fromImage
import org.bukkit.map.MapPalette; //导入依赖的package包/类
/**
* Create a new map from an image
*
* @param image Image
* @return Map
*/
@SuppressWarnings("deprecation")
public static CustomMap fromImage(Image image)
{
CustomMap customMap = new CustomMap(MapUtils.IDS--, image.getWidth(null), image.getHeight(null));
customMap.bytes = MapPalette.imageToBytes(image);
return customMap;
}
示例6: BPMap
import org.bukkit.map.MapPalette; //导入依赖的package包/类
public BPMap(String name, GameType gameType, int minPlayers, int maxPlayers, double fallDamageMultiplier)
{
this.name = name;
this.gameType = gameType;
this.minPlayers = minPlayers;
this.maxPlayers = maxPlayers;
this.fallDamageMultiplier = fallDamageMultiplier;
image = loadImage();
image = MapPalette.resizeImage(image);
}
示例7: renderMap
import org.bukkit.map.MapPalette; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private void renderMap(MapState state, int sectionX, int sectionZ, MapCanvas canvas) {
MapSection section = state.getMapSection(sectionX, sectionZ);
for (int x = 0; x < 128; x++) {
for (int z = 0; z < 128; z++) {
byte pixel = section.getPixel(x, z);
if(pixel != Byte.MAX_VALUE && pixel != MapPalette.TRANSPARENT){
canvas.setPixel(x, z, pixel);
}
}
}
}
示例8: MapSection
import org.bukkit.map.MapPalette; //导入依赖的package包/类
public MapSection(){
mapData = new byte[128][128];
byte min = MapPalette.TRANSPARENT;
for(int index = 0; index < 128; index++){
for(int index2 = 0; index2 < 128; index2++){
mapData[index][index2] = min;
}
}
}
示例9: getPixel
import org.bukkit.map.MapPalette; //导入依赖的package包/类
public synchronized byte getPixel(int x, int z){
if((x > -1 && x < 128 && z > -1 && z < 128)){
return mapData[x][z];
}
Bukkit.getLogger().warning("Invalid Map Get Cordinates: " + x + " " + z);
return MapPalette.TRANSPARENT;
}
示例10: setImage
import org.bukkit.map.MapPalette; //导入依赖的package包/类
public void setImage(Image image) {
this.image = image;
image = MapPalette.resizeImage(image);
this.data = MapPalette.imageToBytes(image);
this.width = image.getWidth(null);
this.height = image.getHeight(null);
this.redraw();
}
示例11: setPixel
import org.bukkit.map.MapPalette; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public void setPixel(int x, int y, byte color) {
if (x < 0 || y < 0 || x > CANVAS_WIDTH || y > CANVAS_HEIGHT) return;
pixels[x + y * CANVAS_WIDTH] = color;
// Map colors in advance.
if (color != MapPalette.TRANSPARENT && !dyeColors.containsKey(color)) {
java.awt.Color mapColor = MapPalette.getColor(color);
Color targetColor = Color.fromRGB(mapColor.getRed(), mapColor.getGreen(), mapColor.getBlue());
// Find best dyeColor
DyeColor bestDyeColor = null;
Double bestDistance = null;
for (DyeColor testDyeColor : DyeColor.values()) {
Color testColor = testDyeColor.getColor();
double testDistance = ColorHD.getDistance(testColor, targetColor);
if (bestDistance == null || testDistance < bestDistance) {
bestDistance = testDistance;
bestDyeColor = testDyeColor;
if (testDistance == 0) break;
}
}
dyeColors.put(color, bestDyeColor);
}
}
示例12: getDyeColor
import org.bukkit.map.MapPalette; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public DyeColor getDyeColor(int x, int y) {
byte color = getPixel(x, y);
if (color == MapPalette.TRANSPARENT) return null;
if (!dyeColors.containsKey(color)) return null;
return dyeColors.get(color);
}
示例13: drawImage
import org.bukkit.map.MapPalette; //导入依赖的package包/类
@SuppressWarnings("deprecation")
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]);
}
}
}
示例14: drawText
import org.bukkit.map.MapPalette; //导入依赖的package包/类
@SuppressWarnings("deprecation")
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;
}
}
示例15: stealColors
import org.bukkit.map.MapPalette; //导入依赖的package包/类
private static Color[] stealColors(){
try{
Field field = MapPalette.class.getDeclaredField("colors");
field.setAccessible(true);
return (Color[]) field.get(null);
}catch (Throwable e){
e.printStackTrace();
return null;
}
}