getNPCTexture for ClientCache

This commit is contained in:
Kam committed 2023-06-02 04:22:00 -04:00
1 parent 6bc55e101f
commit 189692a090
3 files changed
+24 -9

No files matched your search

@@ -1,5 +1,6 @@
package noppes.npcs.client;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.renderer.ImageData;
import noppes.npcs.util.CacheHashMap;
@@ -14,4 +15,13 @@ public class ClientCacheHandler {
return imageDataCache.get(directory).getObject();
}
}
public static ImageData getNPCTexture(String directory, boolean x64, ResourceLocation resource) {
synchronized (imageDataCache) {
if (!imageDataCache.containsKey(resource.getResourcePath())) {
imageDataCache.put(resource.getResourcePath(), new CacheHashMap.CachedObject<>(new ImageData(directory, x64, resource)));
}
return imageDataCache.get(resource.getResourcePath()).getObject();
}
}
}
@@ -1,8 +1,10 @@
package noppes.npcs.client.renderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.SkinManager;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.ImageDownloadAlt;
import noppes.npcs.client.renderer.ImageBufferDownloadAlt;
@@ -35,6 +37,15 @@ public class ImageData {
}
}
// For NPC Skins Only
public ImageData(String directory, boolean x64, ResourceLocation resource) {
this.location = resource;
this.isUrl = true;
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
this.imageDownloadAlt = new ImageDownloadAlt(null, directory, SkinManager.field_152793_a, new ImageBufferDownloadAlt(x64));
texturemanager.loadTexture(this.location, this.imageDownloadAlt);
}
public boolean imageLoaded() {
if (!this.gotWidthHeight) {
try {
@@ -20,6 +20,7 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.boss.BossStatus;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.api.ISkinOverlay;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.ImageDownloadAlt;
import noppes.npcs.client.model.ModelMPM;
import noppes.npcs.constants.EnumAnimation;
@@ -343,10 +344,10 @@ public class RenderNPCInterface extends RenderLiving{
}
if (npc.display.skinType == 2) {
npc.textureLocation = new ResourceLocation("skins/" + sb.toString());
loadSkin(null, npc.textureLocation, npc.display.url, false);
ClientCacheHandler.getNPCTexture(npc.display.url, false, npc.textureLocation);
} else {
npc.textureLocation = new ResourceLocation("skins64/" + sb.toString());
loadSkin(null, npc.textureLocation, npc.display.url, true);
ClientCacheHandler.getNPCTexture(npc.display.url, true, npc.textureLocation);
}
LastTextureTick = 0;
} catch(Exception ignored){}
@@ -401,11 +402,4 @@ public class RenderNPCInterface extends RenderLiving{
}
}
// 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(version));
texturemanager.loadTexture(resource, object);
}
}