Files
CustomNPC-Plus/src/main/java/noppes/npcs/client/renderer/ImageBufferDownloadAlt.java
T

84 lines
2.9 KiB
Java
Raw Normal View History

2018-09-13 12:03:28 -04:00
package noppes.npcs.client.renderer;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
2021-04-29 01:10:15 -04:00
import java.awt.image.ImageObserver;
2018-09-13 12:03:28 -04:00
import net.minecraft.client.renderer.ImageBufferDownload;
2021-04-30 00:30:56 -04:00
public class ImageBufferDownloadAlt extends ImageBufferDownload {
2018-09-13 12:03:28 -04:00
private int imageData[];
private int imageWidth;
private int imageHeight;
2021-05-06 01:27:24 -04:00
private boolean version;
// If Version == true, use 64 Loader
public ImageBufferDownloadAlt(boolean ver){
this.version = ver;
}
2018-09-13 12:03:28 -04:00
@Override
2021-04-30 00:30:56 -04:00
public BufferedImage parseUserSkin(BufferedImage bufferedimage) {
2021-04-29 01:10:15 -04:00
2021-05-06 01:27:24 -04:00
if(this.version){
imageWidth = bufferedimage.getWidth(null);
imageHeight = bufferedimage.getHeight(null);
2021-05-07 19:46:26 -04:00
2021-05-06 01:27:24 -04:00
BufferedImage bufferedimage1 = new BufferedImage(imageWidth, imageWidth, 2);
Graphics g = bufferedimage1.getGraphics();
g.drawImage(bufferedimage, 0, 0, null);
g.dispose();
2021-05-07 19:46:26 -04:00
imageData = ((DataBufferInt) bufferedimage1.getRaster().getDataBuffer()).getData();
2021-05-06 01:27:24 -04:00
setAreaTransparent(imageWidth / 2, 0, imageWidth, imageHeight / 4);
return bufferedimage1;
}
2021-05-07 19:46:26 -04:00
else{
imageWidth = bufferedimage.getWidth(null);
imageHeight = imageWidth / 2;
2021-04-29 06:37:35 -04:00
2021-05-07 19:46:26 -04:00
BufferedImage bufferedimage1 = new BufferedImage(imageWidth, imageHeight, 2);
Graphics g = bufferedimage1.getGraphics();
g.drawImage(bufferedimage, 0, 0, null);
g.dispose();
imageData = ((DataBufferInt)bufferedimage1.getRaster().getDataBuffer()).getData();
2021-04-29 01:10:15 -04:00
2021-05-07 19:46:26 -04:00
setAreaTransparent(imageWidth / 2, 0, imageWidth, imageHeight / 2);
return bufferedimage1;
}
2018-09-13 12:03:28 -04:00
}
2021-04-29 01:10:15 -04:00
2018-09-13 12:03:28 -04:00
/**
* Makes the given area of the image transparent if it was previously completely opaque (used to remove the outer
* layer of a skin around the head if it was saved all opaque; this would be redundant so it's assumed that the skin
* maker is just using an image editor without an alpha channel)
*/
2021-04-30 00:30:56 -04:00
private void setAreaTransparent(int par1, int par2, int par3, int par4) {
if (!this.hasTransparency(par1, par2, par3, par4)) {
for (int i1 = par1; i1 < par3; ++i1) {
for (int j1 = par2; j1 < par4; ++j1) {
2018-09-13 12:03:28 -04:00
this.imageData[i1 + j1 * this.imageWidth] &= 16777215;
}
}
}
}
/**
* Returns true if the given area of the image contains transparent pixels
*/
2021-04-30 00:30:56 -04:00
private boolean hasTransparency(int par1, int par2, int par3, int par4) {
for (int i1 = par1; i1 < par3; ++i1) {
for (int j1 = par2; j1 < par4; ++j1) {
2018-09-13 12:03:28 -04:00
int k1 = this.imageData[i1 + j1 * this.imageWidth];
2021-04-30 00:30:56 -04:00
if ((k1 >> 24 & 255) < 128) {
2018-09-13 12:03:28 -04:00
return true;
}
}
}
return false;
}
2021-04-30 00:30:56 -04:00
}