private final static HashMap<byte[], ResourceLocation> imgcache = new HashMap<byte[], ResourceLocation>();
public static ResourceLocation getResourceLocation(byte[] bytes) {
NativeImage nativeImage;
if (imgcache.containsKey(bytes))
return imgcache.get(bytes);
else {
try {
nativeImage = NativeImage.read(new ByteArrayInputStream(bytes));
} catch (IOException e) {
throw new RuntimeException(e);
}
TextureManager textureManager = Minecraft.getInstance().getTextureManager();
DynamicTexture dynamicTexture = new DynamicTexture(nativeImage);
ResourceLocation res = textureManager.getDynamicTextureLocation("lol", dynamicTexture);
imgcache.put(bytes, res);
return res;
}
}
public static void drawImage(MediaInfo mediaInfo, float x, float y, float width, float height) {
ResourceLocation tex = getResourceLocation(mediaInfo.getArtworkPng());
if (tex == null) return;
mc.getTextureManager().bindTexture(tex);
GlStateManager.enableBlend();
allocTextureRectangle(x, y, width, height);
GlStateManager.disableBlend();
}
держи