From d25dcc9f6a333e2fbbbc0ea733b3306406527065 Mon Sep 17 00:00:00 2001 From: Kam Date: Fri, 8 Mar 2024 05:16:48 -0500 Subject: [PATCH] Fix Imgur Redirecting --- .../noppes/npcs/client/ImageDownloadAlt.java | 12 +++--- .../client/renderer/RenderNPCInterface.java | 39 +++++++++++++++--- .../entity/64-Textures/humanfemale/Alex.png | Bin 0 -> 1175 bytes .../entity/64-Textures/humanmale/steve64.png | Bin 0 -> 958 bytes 4 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 src/main/resources/assets/customnpcs/textures/entity/64-Textures/humanfemale/Alex.png create mode 100644 src/main/resources/assets/customnpcs/textures/entity/64-Textures/humanmale/steve64.png diff --git a/src/main/java/noppes/npcs/client/ImageDownloadAlt.java b/src/main/java/noppes/npcs/client/ImageDownloadAlt.java index 2274682e8..3a5b9ae6f 100644 --- a/src/main/java/noppes/npcs/client/ImageDownloadAlt.java +++ b/src/main/java/noppes/npcs/client/ImageDownloadAlt.java @@ -131,14 +131,13 @@ public class ImageDownloadAlt extends SimpleTexture 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"); - // Set user agent + // Modify Accept Redirect if (isImgurLink(url)) { - connection.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)"); - } - else { - connection.setRequestProperty("User-Agent", "Mozilla/5.0"); + connection.setRequestProperty("Accept", "*/*"); } + connection.connect(); if (connection.getResponseCode() / 100 != 2) @@ -169,7 +168,7 @@ public class ImageDownloadAlt extends SimpleTexture } catch (Exception exception) { - ImageDownloadAlt.logger.error("Couldn\'t download http texture", exception); + ImageDownloadAlt.logger.error("Couldn\'t download http texture", exception); } finally { @@ -184,6 +183,7 @@ public class ImageDownloadAlt extends SimpleTexture this.imageThread.start(); } + // Check if the URL is an Imgur link private static boolean isImgurLink(URL url) { return url.getHost().endsWith("imgur.com"); diff --git a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java index a0f0a6ed1..689b17206 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java @@ -48,6 +48,9 @@ public class RenderNPCInterface extends RenderLiving{ public static RenderManager staticRenderManager; public ModelBase originalModel; + public static ResourceLocation steve64 = new ResourceLocation("customnpcs","textures/entity/64-Textures/humanmale/Steve.png"); + public static ResourceLocation alex = new ResourceLocation("customnpcs","textures/entity/64-Textures/humanfemale/Alex.png"); + public RenderNPCInterface(ModelBase model, float f){ super(model, f); this.originalModel = model; @@ -585,27 +588,39 @@ public class RenderNPCInterface extends RenderLiving{ } LastTextureTick = 0; } else if (npc.display.skinType == 2 || npc.display.skinType == 3) { - ResourceLocation location = new ResourceLocation("skins/" + (npc.display.modelType + npc.display.skinType + npc.display.url).hashCode()); + ResourceLocation location = new ResourceLocation("skins/" + (npc.display.skinType + npc.display.url).hashCode()); // If URL Empty Steve - if(npc.display.url.isEmpty()){ return AbstractClientPlayer.locationStevePng; } + if(npc.display.url.isEmpty()){ + return fallBackSkin(npc); + } // If URL Cached then grab it else if(ClientCacheHandler.isCachedNPC(location)){ try { - npc.textureLocation = ClientCacheHandler.getNPCTexture(npc.display.url, npc.display.modelType > 0 || npc.display.skinType == 3, location).getLocation(); + ResourceLocation loc = ClientCacheHandler.getNPCTexture(npc.display.url, npc.display.skinType == 3, location).getLocation(); + if(loc != null){ + npc.textureLocation = loc; + } else { + return fallBackSkin(npc); + } } catch(Exception ignored){} } // For New URL Requests do not spam it else if(LastTextureTick < 5) { //fixes request flood somewhat - return AbstractClientPlayer.locationStevePng; + return fallBackSkin(npc); } else { try { - npc.textureLocation = ClientCacheHandler.getNPCTexture(npc.display.url, npc.display.modelType > 0 || npc.display.skinType == 3, location).getLocation(); + ResourceLocation loc = ClientCacheHandler.getNPCTexture(npc.display.url, npc.display.skinType == 3, location).getLocation(); + if(loc != null){ + npc.textureLocation = loc; + } else { + return fallBackSkin(npc); + } LastTextureTick = 0; } catch(Exception ignored){} } } else { - return AbstractClientPlayer.locationStevePng; + return fallBackSkin(npc); } } return npc.textureLocation; @@ -653,4 +668,16 @@ public class RenderNPCInterface extends RenderLiving{ } } + + private ResourceLocation fallBackSkin(EntityNPCInterface npcInterface){ + switch (npcInterface.display.modelType){ + case 2: + return alex; + case 1: + return steve64; + default: + return AbstractClientPlayer.locationStevePng; + } + } + } diff --git a/src/main/resources/assets/customnpcs/textures/entity/64-Textures/humanfemale/Alex.png b/src/main/resources/assets/customnpcs/textures/entity/64-Textures/humanfemale/Alex.png new file mode 100644 index 0000000000000000000000000000000000000000..5ef231b1268b8725152d8a05b9104cad53d59249 GIT binary patch literal 1175 zcmV;I1Zew-P)88x`>R8XpFv!kC1Dedr+#0Uf6&#*t(S5 zlRV$XqvXk`eRUF)3fZgvEtmT01q+E@$s`+H-w)jVsz$U0Nz1Zv8_fIuAbA8(~ZdZo@n3-$&! zUWXU-i=d>R+xYz;2yXOEDFCc5)e}Hi9&mem@hm{!=u!Y}3_9^l2~Pn*7zTc~cj&kL z7GqHqV$BFZN6~#vXj{)>L=RXT(c>|TC!+^}-|2SY@3-2$UMHjnKLKE97lVMlCue7I zjObw;G5R=;*(3n2?VjJs#%{+&imtTAF(9Wi7>fZwY6wjkup*#^*nYPFIA-kXN-C5S zgm@b6QG9xNd3y2rA|Iw2*gijRw=$AXkpPI8`smVj0LIu?nASQUCIFu2wfvJ4zlF(L z7%~VW@?x&;0CmT-B0rpTAhgkD0#K{fyvE*M!^5P$vr{JkB|uJ84x-0cGKy==cb$Ao zaO8`C+Wx`8ek})}0sxN5hXrnqDHe%N^w5}x!YYNfgb0Q#_1b#wLs zi>(AUv^GhT#M;RW>h*1}(QG!n?RtIV-MbA`5L7A^_*SauVOVwZYBfpH)Y=gNM)pS$ zuuB>2P5`L>2(1g;oVhlpX_AgcHpMt9WU#ijw%a^9YVKmPzPY*X&Z_?&=EoV#S)4oo zfD)2vz|xksw583X7u2k4y(|Ei+K*#U3|6TW_3!1TFjE)2)WAu-FjE)IvT40A zQy0v#X}yr?0)xwaN*BBUDCh+^J`4$PR~k^%3u9f74J826dV#KEYlqoT5>U_!DS1K{ pfM7?X5`byFkZO`7nY4Kh@E2|l159)+62brg002ovPDHLkV1iMbA#DHv literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/customnpcs/textures/entity/64-Textures/humanmale/steve64.png b/src/main/resources/assets/customnpcs/textures/entity/64-Textures/humanmale/steve64.png new file mode 100644 index 0000000000000000000000000000000000000000..c5426101d179bc9b912bf7058a4417727991560c GIT binary patch literal 958 zcmV;v13~(gKPi)|4J^I1^@s60d!JMQvg8b*k%9#0{2NoK~z}7?UwCYqc9MKYe7lbk_C!Y zSA}fS_5Lq$&zVV-cB>8jyADVvJkHB}1ZGyNC{1H=+GdQhS}Kk0aT4$Xxds4Z9_~fN zUEu)&z~A+NMuTt~!g7FR4x7Fo9aHG0<$zvdu+yl=6*;iXV>3<uPK;6{NPvdVlJ-oi& zLm4OUaFc*02QWI=lQ7;t+@t;u3-7oce?T(d$_~=D+ihCk1|WR6?V_anWmy&oHJk-( zw{80lfISFj0Z5a(?7?S%4FNeGd=f$-A)I(H4BfEb?>qbqP`V0&=b)@bsd|AcOkrH$ zXAR-v1JHc{@Vl>!smihnfmhLCS-#ts>zkW3)Hy&5hXgQpccy>|FVsmOs}%F15&#zG z0XXj<$%s1RhF+|r+(7ty1Yj5>Fkv*p(+MyUP)YKfsxD=c&te}mtqBk0C3LAcno0X4c%t>pbMagfFJ;OI~wj<(b~ABQ5It~FJR%y0%#7MAXeY`?@Hhd}riavgU<( zvt>`>=V%dN-tGx-{!ClX_h3_=oeLItP`KRhpw0_J>ehqK1KQe;=7O&PVySb(UfX#j z%;$oy0A1|&2~b62Lh?Nz09u*{lBDlJ`ab*%IGGo89?*8ezIfRK?XfztKxZ$Cqd~|j zM$B(XhbY@)OiG!~coxz7Zg&I`#tCE+6AbY4jFKuW`9z{$Lz g6=eE!J~;jVzvEwb%VPFUu>b%707*qoM6N<$f^?XsIRF3v literal 0 HcmV?d00001