Files
CustomNPC-Plus/src/main/java/noppes/npcs/client/ClientCacheHandler.java
T

78 lines
3.1 KiB
Java
Raw Normal View History

2023-05-30 23:41:37 -05:00
package noppes.npcs.client;
2023-06-02 04:22:00 -04:00
import net.minecraft.util.ResourceLocation;
2025-02-22 23:58:56 -05:00
import noppes.npcs.client.gui.hud.OverlayQuestTracking;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
2025-02-18 04:57:22 -05:00
import noppes.npcs.client.gui.select.GuiSoundSelection;
import noppes.npcs.client.gui.select.GuiTextureSelection;
import noppes.npcs.client.renderer.ImageData;
2023-06-03 17:23:40 -04:00
import noppes.npcs.config.ConfigClient;
2025-02-20 21:40:39 -05:00
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.controllers.data.Party;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.controllers.data.SkinOverlay;
2023-05-30 23:41:37 -05:00
import noppes.npcs.util.CacheHashMap;
import java.util.HashMap;
import java.util.UUID;
public class ClientCacheHandler {
2023-06-03 17:23:40 -04:00
private static final CacheHashMap<String, CacheHashMap.CachedObject<ImageData>> imageDataCache = new CacheHashMap<>((long) ConfigClient.CacheLife * 60 * 1000);
2024-03-13 13:47:33 -04:00
public static PlayerData playerData = new PlayerData();
public static OverlayQuestTracking questTrackingOverlay = null;
public static HashMap<Integer, OverlayCustom> customOverlays = new HashMap<>();
public static HashMap<UUID, HashMap<Integer, SkinOverlay>> skinOverlays = new HashMap<>();
public static HashMap<UUID, AnimationData> playerAnimations = new HashMap<>();
2023-05-30 23:41:37 -05:00
public static Party party;
2025-02-18 22:22:40 -05:00
public static boolean allowProfiles = true;
public static boolean allowParties = true;
2023-05-30 23:41:37 -05:00
public static ImageData getImageData(String directory) {
synchronized (imageDataCache) {
if (!imageDataCache.containsKey(directory)) {
imageDataCache.put(directory, new CacheHashMap.CachedObject<>(new ImageData(directory)));
}
return imageDataCache.get(directory).getObject();
2023-05-30 23:41:37 -05:00
}
}
2023-06-02 04:22:00 -04:00
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();
}
}
2024-02-28 23:47:24 -05:00
public static boolean isCachedNPC(ResourceLocation resource) {
synchronized (imageDataCache) {
return imageDataCache.containsKey(resource.getResourcePath());
}
}
public static void clearCache() {
ClientCacheHandler.imageDataCache.clear();
ClientCacheHandler.questTrackingOverlay = null;
ClientCacheHandler.customOverlays.clear();
ClientCacheHandler.skinOverlays.clear();
ClientCacheHandler.playerAnimations.clear();
2025-02-18 04:57:22 -05:00
// Clear Texture Caches
GuiSoundSelection.cachedDomains.clear();
GuiTextureSelection.cachedTextures.clear();
}
2024-03-15 16:40:43 -04:00
public static void clearSkinCache() {
ClientCacheHandler.imageDataCache.clear();
ClientCacheHandler.customOverlays.clear();
ClientCacheHandler.skinOverlays.clear();
2025-02-18 04:57:22 -05:00
// Clear Texture Caches
GuiSoundSelection.cachedDomains.clear();
GuiTextureSelection.cachedTextures.clear();
2024-03-15 16:40:43 -04:00
}
2023-05-30 23:41:37 -05:00
}