public static void initColors() {
final Minecraft mc = Minecraft.getMinecraft();
TextureManager mgr = mc.getTextureManager();
mgr.bindTexture(TextureMap.locationBlocksTexture);
final int w = GL11.glGetTexLevelParameteri(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH);
final int h = GL11.glGetTexLevelParameteri(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT);
final IntBuffer buf = BufferUtils.createIntBuffer(w * h);
GL11.glGetTexImage(GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, buf);
Thread th = new Thread() {
public void run() {
Map<Block, int[]> colmap = new HashMap<Block, int[]>();
List<ResourceLocation> blocks = new ArrayList<ResourceLocation>();
blocks.addAll(Block.blockRegistry.getKeys());
BlockModelShapes blkShapes = mc.getBlockRendererDispatcher().getBlockModelShapes();
for (ResourceLocation b_loc : blocks) {
Block b = (Block) Block.blockRegistry.getObject(b_loc);
int[] colors = new int[16];
for (int d = 0; d < 16; d++) {
try {
IBlockState state = b.getStateFromMeta(d);
TextureAtlasSprite spt = blkShapes.getTexture(state);
// IIcon ico = b.func_149735_b(1, d);
// IResource res = Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation("minecraft", "textures/blocks/" + ico.getIconName() + ".png"));
// InputStream in = res.getInputStream();
// Bitmap img = Bitmap.load(in);
// in.close();
long rt = 0;
long gt = 0;
long bt = 0;
long div = 0;
int x = spt.getOriginX();
int y = spt.getOriginY();
int sw = spt.getIconWidth();
int sh = spt.getIconHeight();
for (int yy = 0; yy < sh; yy++) {
for (int xx = 0; xx < sw; xx++) {
int color = buf.get((xx + x) + (yy + y) * w);
int a = color >>> 24;
if (a != 0) {
rt += (color >> 16) & 0xFF;
gt += (color >> 8) & 0xFF;
bt += color & 0xFF;
div++;
}
}
}
rt /= div;
gt /= div;
bt /= div;
colors[d] = 0xFF000000 | ((int)rt & 0xFF) << 16 | ((int)gt & 0xFF) << 8 | ((int)bt & 0xFF);
} catch (Exception e) {
colors[d] = 0xFF000000;
}
}
colmap.put(b, colors);
}
colorMap = colmap;
}
};
th.start();
}
Minimap.java 文件源码
java
阅读 22
收藏 0
点赞 0
评论 0
项目:HeroMod
作者:
评论列表
文章目录