Fix Imgur Redirecting

This commit is contained in:
Kam committed 2024-03-08 05:16:48 -05:00
1 parent 5ed21bdf15
commit d25dcc9f6a
4 files changed
+39 -12

No files matched your search

@@ -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");
@@ -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;
}
}
}