Updating Texture Sizes

Attempting to implement a selective renderer to allow for 64x64 Skin Url type for mobs.
This commit is contained in:
KAMKEEL committed 2021-05-04 03:52:44 -04:00
1 parent 8a4be0bc1e
commit 66270715ac
41 files changed
+487 -18

No files matched your search

@@ -0,0 +1,63 @@
package noppes.npcs.client.renderer;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.awt.image.ImageObserver;
import net.minecraft.client.renderer.ImageBufferDownload;
public class ImageBufferDownload32 extends ImageBufferDownload {
private int imageData[];
private int imageWidth;
private int imageHeight;
@Override
public BufferedImage parseUserSkin(BufferedImage bufferedimage) {
imageWidth = bufferedimage.getWidth(null);
imageHeight = imageWidth/2;
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();
setAreaTransparent(imageWidth / 2, 0, imageWidth, imageHeight / 2);
return bufferedimage1;
}
/**
* 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)
*/
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) {
this.imageData[i1 + j1 * this.imageWidth] &= 16777215;
}
}
}
}
/**
* Returns true if the given area of the image contains transparent pixels
*/
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) {
int k1 = this.imageData[i1 + j1 * this.imageWidth];
if ((k1 >> 24 & 255) < 128) {
return true;
}
}
}
return false;
}
}
@@ -29,7 +29,7 @@ public class RenderCustomNpc extends RenderNPCHumanMale{
// Default Renderer
public RenderCustomNpc() {
super(new ModelMPM(0, false, false), new ModelMPM(1,false, false), new ModelMPM(0.5f, false, false));
super(new ModelMPM(0), new ModelMPM(1), new ModelMPM(0.5f));
}
@Override
@@ -38,8 +38,8 @@ public class RenderNPCHumanMale extends RenderNPCInterface
protected ModelNPCMale modelArmorChestplate;
protected ModelNPCMale modelArmor;
protected final ModelNPCMale OGmodelArmorChestplate = new ModelMPM(1, false, false);
protected final ModelNPCMale OGmodelArmor = new ModelMPM(0.5f, false, false);
protected final ModelNPCMale OGmodelArmorChestplate = new ModelMPM(1);
protected final ModelNPCMale OGmodelArmor = new ModelMPM(0.5f);
protected final ModelMPM steve = new ModelMPM(0, true, false);
protected final ModelMPM steveArmorChestplate = new ModelMPM(1, true, false);
@@ -20,6 +20,7 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.boss.BossStatus;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.ImageDownloadAlt;
import noppes.npcs.client.ImageDownloadAlt32;
import noppes.npcs.client.model.ModelMPM;
import noppes.npcs.constants.EnumAnimation;
import noppes.npcs.constants.EnumStandingType;
@@ -289,7 +290,29 @@ public class RenderNPCInterface extends RenderLiving{
sb.append(String.format("%02x", b&0xff));
}
npc.textureLocation = new ResourceLocation("skins/" + sb.toString());
loadSkin32(null, npc.textureLocation, npc.display.url);
LastTextureTick = 0;
}
catch(Exception ex){
}
}
// SKIN CHANGE
// For 64 x 64 Textures
else if(npc.display.skinType == 3){
try{
MessageDigest digestion = MessageDigest.getInstance("MD5");
byte[] hash = digestion.digest(npc.display.url.getBytes("UTF-8"));
StringBuilder sb = new StringBuilder(2*hash.length);
for(byte b : hash){
sb.append(String.format("%02x", b&0xff));
}
npc.textureLocation = new ResourceLocation("skins/" + sb.toString());
loadSkin(null, npc.textureLocation, npc.display.url);
LastTextureTick = 0;
}
catch(Exception ex){
@@ -302,11 +325,18 @@ public class RenderNPCInterface extends RenderLiving{
return npc.textureLocation;
}
// True = 64x64 Skin
// 64x64 Skin
private void loadSkin(File file, ResourceLocation resource, String par1Str){
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
ITextureObject object = new ImageDownloadAlt(file, par1Str, SkinManager.field_152793_a, new ImageBufferDownloadAlt());
texturemanager.loadTexture(resource, object);
}
// SORT OF WORKS
private void loadSkin32(File file, ResourceLocation resource, String par1Str){
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
ITextureObject object = new ImageDownloadAlt32(file, par1Str, SkinManager.field_152793_a, new ImageBufferDownload32());
texturemanager.loadTexture(resource, object);
}
}