From df6b631549039791f0df1a9e214a5d1d83ab2ae5 Mon Sep 17 00:00:00 2001 From: KAMKEEL Date: Thu, 6 May 2021 01:27:24 -0400 Subject: [PATCH] ITS WORKING!!!!! Redesigned Steve 32 Model. Now USERNAMES work. Finally figured out the issue SkinUrls and it was becaused 64s overwrite the 64x32 versions. Needed to store 64x64 in separate folder. --- src/main/java/noppes/npcs/DataDisplay.java | 5 +- .../noppes/npcs/client/ImageDownloadAlt.java | 4 +- .../npcs/client/ImageDownloadAlt32.java | 175 ------------------ .../client/gui/mainmenu/GuiNpcDisplay.java | 13 +- .../renderer/ImageBufferDownload32.java | 63 ------- .../renderer/ImageBufferDownloadAlt.java | 28 ++- .../client/renderer/RenderNPCInterface.java | 47 ++--- .../assets/customnpcs/lang/de_DE.lang | 1 + .../assets/customnpcs/lang/en_US.lang | 1 + 9 files changed, 49 insertions(+), 288 deletions(-) delete mode 100644 src/main/java/noppes/npcs/client/ImageDownloadAlt32.java delete mode 100644 src/main/java/noppes/npcs/client/renderer/ImageBufferDownload32.java diff --git a/src/main/java/noppes/npcs/DataDisplay.java b/src/main/java/noppes/npcs/DataDisplay.java index b020de2b5..53aac453b 100644 --- a/src/main/java/noppes/npcs/DataDisplay.java +++ b/src/main/java/noppes/npcs/DataDisplay.java @@ -20,7 +20,9 @@ public class DataDisplay { public String title = ""; public byte skinType = 0; //0:normal, 1:player, 2:url, 3:url64 + public String url = ""; + public GameProfile playerProfile; public String texture = "customnpcs:textures/entity/humanmale/Steve.png";; public String cloakTexture = ""; @@ -97,7 +99,8 @@ public class DataDisplay { title = nbttagcompound.getString("Title"); url = nbttagcompound.getString("SkinUrl"); - int prevSkinType = skinType; + + int prevSkinType = skinType; skinType = nbttagcompound.getByte("UsingSkinUrl"); this.playerProfile = null; diff --git a/src/main/java/noppes/npcs/client/ImageDownloadAlt.java b/src/main/java/noppes/npcs/client/ImageDownloadAlt.java index 7db25132e..f32e81c3b 100644 --- a/src/main/java/noppes/npcs/client/ImageDownloadAlt.java +++ b/src/main/java/noppes/npcs/client/ImageDownloadAlt.java @@ -24,7 +24,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) -public class ImageDownloadAlt32 extends SimpleTexture +public class ImageDownloadAlt extends SimpleTexture { private static final Logger logger = LogManager.getLogger(); private static final AtomicInteger threadDownloadCounter = new AtomicInteger(0); @@ -35,7 +35,7 @@ public class ImageDownloadAlt32 extends SimpleTexture private Thread imageThread; private boolean textureUploaded; - public ImageDownloadAlt32(File file, String url, ResourceLocation resource, IImageBuffer buffer) + public ImageDownloadAlt(File file, String url, ResourceLocation resource, IImageBuffer buffer) { super(resource); this.cacheFile = file; diff --git a/src/main/java/noppes/npcs/client/ImageDownloadAlt32.java b/src/main/java/noppes/npcs/client/ImageDownloadAlt32.java deleted file mode 100644 index f32e81c3b..000000000 --- a/src/main/java/noppes/npcs/client/ImageDownloadAlt32.java +++ /dev/null @@ -1,175 +0,0 @@ -package noppes.npcs.client; - -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.concurrent.atomic.AtomicInteger; - -import javax.imageio.ImageIO; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.IImageBuffer; -import net.minecraft.client.renderer.texture.SimpleTexture; -import net.minecraft.client.renderer.texture.TextureUtil; -import net.minecraft.client.resources.IResourceManager; -import net.minecraft.util.ResourceLocation; - -import org.apache.commons.io.FileUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -@SideOnly(Side.CLIENT) -public class ImageDownloadAlt extends SimpleTexture -{ - private static final Logger logger = LogManager.getLogger(); - private static final AtomicInteger threadDownloadCounter = new AtomicInteger(0); - private final File cacheFile; - private final String imageUrl; - private final IImageBuffer imageBuffer; - private BufferedImage bufferedImage; - private Thread imageThread; - private boolean textureUploaded; - - public ImageDownloadAlt(File file, String url, ResourceLocation resource, IImageBuffer buffer) - { - super(resource); - this.cacheFile = file; - this.imageUrl = url; - this.imageBuffer = buffer; - } - - private void checkTextureUploaded() - { - if (!this.textureUploaded) - { - if (this.bufferedImage != null) - { - if (this.textureLocation != null) - { - this.deleteGlTexture(); - } - - TextureUtil.uploadTextureImage(super.getGlTextureId(), this.bufferedImage); - this.textureUploaded = true; - } - } - } - - public int getGlTextureId() - { - this.checkTextureUploaded(); - return super.getGlTextureId(); - } - - public void setBufferedImage(BufferedImage p_147641_1_) - { - this.bufferedImage = p_147641_1_; - - if (this.imageBuffer != null) - { - this.imageBuffer.func_152634_a(); - } - } - - public void loadTexture(IResourceManager resourceManager) throws IOException - { - if (this.bufferedImage == null && this.textureLocation != null) - { - super.loadTexture(resourceManager); - } - - if (this.imageThread == null) - { - if (this.cacheFile != null && this.cacheFile.isFile()) - { - logger.debug("Loading http texture from local cache ({})", new Object[] {this.cacheFile}); - - try - { - this.bufferedImage = ImageIO.read(this.cacheFile); - - if (this.imageBuffer != null) - { - this.setBufferedImage(this.imageBuffer.parseUserSkin(this.bufferedImage)); - } - } - catch (IOException ioexception) - { - logger.error("Couldn\'t load skin " + this.cacheFile, ioexception); - this.loadTextureFromServer(); - } - } - else - { - this.loadTextureFromServer(); - } - } - } - - protected void loadTextureFromServer() - { - this.imageThread = new Thread("Texture Downloader #" + threadDownloadCounter.incrementAndGet()) - { - private static final String __OBFID = "CL_00001050"; - public void run() - { - HttpURLConnection connection = null; - ImageDownloadAlt.logger.debug("Downloading http texture from {} to {}", new Object[] {ImageDownloadAlt.this.imageUrl, ImageDownloadAlt.this.cacheFile}); - - try - { - connection = (HttpURLConnection)(new URL(ImageDownloadAlt.this.imageUrl)).openConnection(Minecraft.getMinecraft().getProxy()); - connection.setDoInput(true); - connection.setDoOutput(false); - connection.setRequestProperty("Content-Type", "image/png"); - connection.setRequestProperty("Expect", "100-continue"); - //connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:19.0) Gecko/20100101 Firefox/19.0"); - connection.setRequestProperty("User-Agent", "Mozilla/5.0"); - connection.connect(); - - if (connection.getResponseCode() / 100 != 2) - { - return; - } - - BufferedImage bufferedimage; - - if (ImageDownloadAlt.this.cacheFile != null) - { - FileUtils.copyInputStreamToFile(connection.getInputStream(), ImageDownloadAlt.this.cacheFile); - bufferedimage = ImageIO.read(ImageDownloadAlt.this.cacheFile); - } - else - { - bufferedimage = ImageIO.read(connection.getInputStream()); - } - - if (ImageDownloadAlt.this.imageBuffer != null) - { - bufferedimage = ImageDownloadAlt.this.imageBuffer.parseUserSkin(bufferedimage); - } - - ImageDownloadAlt.this.setBufferedImage(bufferedimage); - } - catch (Exception exception) - { - ImageDownloadAlt.logger.error("Couldn\'t download http texture", exception); - } - finally - { - if (connection != null) - { - connection.disconnect(); - } - } - } - }; - this.imageThread.setDaemon(true); - this.imageThread.start(); - } -} diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java index 53a766190..ab7fdc5be 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java @@ -56,7 +56,7 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene addLabel(new GuiNpcLabel(4,"display.texture", guiLeft + 5, y + 5)); addTextField(new GuiNpcTextField(3,this, fontRendererObj, guiLeft + 80, y, 200, 20, display.skinType == 0?display.texture:display.url)); this.addButton(new GuiNpcButton(3, guiLeft + 325, y, 38, 20, "mco.template.button.select")); - this.addButton(new GuiNpcButton(2, guiLeft + 283, y, 40, 20, new String[]{"display.texture","display.player", "display.url", "display.url64"},display.skinType)); + this.addButton(new GuiNpcButton(2, guiLeft + 283, y, 40, 20, new String[]{"display.texture","display.player", "display.url", "display.urlSix"},display.skinType)); getButton(3).setEnabled(display.skinType == 0); if(display.skinType == 1 && display.playerProfile != null) getTextField(3).setText(display.playerProfile.getName()); @@ -75,10 +75,6 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene addLabel(new GuiNpcLabel(5,"display.livingAnimation", guiLeft + 5, y + 5)); this.addButton(new GuiNpcButton(5, guiLeft + 120, y, 50, 20, new String[]{"gui.yes","gui.no"}, display.disableLivingAnimation?1:0)); - // Square Texture Button - // addLabel(new GuiNpcLabel(300,"display.squareTexture", guiLeft + 230, y + 5)); - // this.addButton(new GuiNpcButton(300, guiLeft + 313, y, 50, 20, new String[]{"gui.no","gui.yes"}, display.squareTexture)); - y+=23; addLabel(new GuiNpcLabel(7,"display.visible", guiLeft + 5, y + 5)); this.addButton(new GuiNpcButton(7, guiLeft + 120, y, 50, 20, new String[]{"gui.yes","gui.no","gui.partly"}, display.visible)); @@ -87,8 +83,7 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene addLabel(new GuiNpcLabel(10,"display.bossbar", guiLeft + 5, y + 5)); this.addButton(new GuiNpcButton(10, guiLeft + 120, y, 110, 20, new String[]{"display.hide","display.show","display.showAttacking"}, display.showBossBar)); - //addExtra(new GuiHoverText(0, "testing", guiLeft, guiTop)); - } + } @Override public void unFocused(GuiNpcTextField textfield){ @@ -103,8 +98,9 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene } else if(textfield.id == 3){ // SKIN CHANGE - if(display.skinType == 2 || display.skinType == 3) + if(display.skinType == 2 || display.skinType == 3){ display.url = textfield.getText(); + } else if(display.skinType == 1){ if(!textfield.isEmpty()){ display.playerProfile = new GameProfile(null, textfield.getText()); @@ -138,6 +134,7 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene } if(button.id == 2){ display.skinType = (byte) button.getValue(); + System.out.println("Skin Type set to:" + display.skinType); // SKIN CHANGE if (display.skinType != 3){ display.url = ""; diff --git a/src/main/java/noppes/npcs/client/renderer/ImageBufferDownload32.java b/src/main/java/noppes/npcs/client/renderer/ImageBufferDownload32.java deleted file mode 100644 index c8765baee..000000000 --- a/src/main/java/noppes/npcs/client/renderer/ImageBufferDownload32.java +++ /dev/null @@ -1,63 +0,0 @@ -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; - } -} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/client/renderer/ImageBufferDownloadAlt.java b/src/main/java/noppes/npcs/client/renderer/ImageBufferDownloadAlt.java index 4551a0c59..6170e9938 100644 --- a/src/main/java/noppes/npcs/client/renderer/ImageBufferDownloadAlt.java +++ b/src/main/java/noppes/npcs/client/renderer/ImageBufferDownloadAlt.java @@ -11,20 +11,40 @@ public class ImageBufferDownloadAlt extends ImageBufferDownload { private int imageData[]; private int imageWidth; private int imageHeight; + private boolean version; + + // If Version == true, use 64 Loader + public ImageBufferDownloadAlt(boolean ver){ + this.version = ver; + } @Override public BufferedImage parseUserSkin(BufferedImage bufferedimage) { - imageWidth = bufferedimage.getWidth(null); - imageHeight = bufferedimage.getHeight(null); + if(this.version){ + imageWidth = bufferedimage.getWidth(null); + imageHeight = imageWidth / 2; + imageHeight = bufferedimage.getHeight(null); + BufferedImage bufferedimage1 = new BufferedImage(imageWidth, imageWidth, 2); + Graphics g = bufferedimage1.getGraphics(); + g.drawImage(bufferedimage, 0, 0, null); + g.dispose(); + imageData = ((DataBufferInt) bufferedimage1.getRaster().getDataBuffer()).getData(); - BufferedImage bufferedimage1 = new BufferedImage(imageWidth, imageWidth, 2); + setAreaTransparent(imageWidth / 2, 0, imageWidth, imageHeight / 4); + return bufferedimage1; + } + + 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 / 4); + setAreaTransparent(imageWidth / 2, 0, imageWidth, imageHeight / 2); return bufferedimage1; } diff --git a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java index 73a73db52..07242d2ca 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java @@ -20,7 +20,6 @@ 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; @@ -281,7 +280,7 @@ public class RenderNPCInterface extends RenderLiving{ } LastTextureTick = 0; } - else if(npc.display.skinType == 2){ + else if(npc.display.skinType == 2 || npc.display.skinType == 3){ try{ MessageDigest digest = MessageDigest.getInstance("MD5"); byte[] hash = digest.digest(npc.display.url.getBytes("UTF-8")); @@ -289,30 +288,15 @@ public class RenderNPCInterface extends RenderLiving{ for(byte b : hash){ 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)); + // SKIN CHANGE + if(npc.display.skinType == 2){ + npc.textureLocation = new ResourceLocation("skins/" + sb.toString()); + loadSkin(null, npc.textureLocation, npc.display.url, false); + } + else{ + npc.textureLocation = new ResourceLocation("skins64/" + sb.toString()); + loadSkin(null, npc.textureLocation, npc.display.url, true); } - npc.textureLocation = new ResourceLocation("skins/" + sb.toString()); - - loadSkin(null, npc.textureLocation, npc.display.url); - LastTextureTick = 0; } catch(Exception ex){ @@ -325,18 +309,11 @@ public class RenderNPCInterface extends RenderLiving{ return npc.textureLocation; } - // 64x64 Skin - private void loadSkin(File file, ResourceLocation resource, String par1Str){ + // 64x64 Skin is True + private void loadSkin(File file, ResourceLocation resource, String par1Str, boolean version){ TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); - ITextureObject object = new ImageDownloadAlt(file, par1Str, SkinManager.field_152793_a, new ImageBufferDownloadAlt()); + ITextureObject object = new ImageDownloadAlt(file, par1Str, SkinManager.field_152793_a, new ImageBufferDownloadAlt(version)); 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); - } - } diff --git a/src/main/resources/assets/customnpcs/lang/de_DE.lang b/src/main/resources/assets/customnpcs/lang/de_DE.lang index 5efa87a55..90b5fa899 100644 --- a/src/main/resources/assets/customnpcs/lang/de_DE.lang +++ b/src/main/resources/assets/customnpcs/lang/de_DE.lang @@ -166,6 +166,7 @@ display.livingAnimation=Lebende Animation display.visible=Sichtbar display.bossbar=Boss-Lebensanzeige display.url=Url +display.urlSix=Url64 inv.minExp=Min. Xp inv.maxExp=Max. Xp diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 7704c581d..d89d9763b 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -175,6 +175,7 @@ display.visible=Visible display.bossbar=BossBar display.squareTexture=Square Texture display.url=Url +display.urlSix=Url64 inv.minExp=Min Exp inv.maxExp=Max Exp