mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 04:54:51 +00:00
Client-side cache is now cleared when leaving or joining worlds
This commit is contained in:
1 parent
54b46129a9
commit
6470c8317b
9 files changed
+56
-43
No files matched your search
@@ -3,23 +3,13 @@ package noppes.npcs.client;
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import noppes.npcs.AnimationData;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.client.gui.OverlayQuestTracking;
|
||||
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
|
||||
import noppes.npcs.constants.EnumPacketServer;
|
||||
import noppes.npcs.controllers.data.SkinOverlay;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Client {
|
||||
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<>();
|
||||
|
||||
public static void sendData(final EnumPacketServer enu, final Object... obs) {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
|
||||
@@ -1,12 +1,23 @@
|
||||
package noppes.npcs.client;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.AnimationData;
|
||||
import noppes.npcs.client.gui.OverlayQuestTracking;
|
||||
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
|
||||
import noppes.npcs.client.renderer.ImageData;
|
||||
import noppes.npcs.config.ConfigClient;
|
||||
import noppes.npcs.controllers.data.SkinOverlay;
|
||||
import noppes.npcs.util.CacheHashMap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ClientCacheHandler {
|
||||
private static final CacheHashMap<String, CacheHashMap.CachedObject<ImageData>> imageDataCache = new CacheHashMap<>((long) ConfigClient.CacheLife * 60 * 1000);
|
||||
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<>();
|
||||
|
||||
public static ImageData getImageData(String directory) {
|
||||
synchronized (imageDataCache) {
|
||||
@@ -25,4 +36,12 @@ public class ClientCacheHandler {
|
||||
return imageDataCache.get(resource.getResourcePath()).getObject();
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearCache() {
|
||||
ClientCacheHandler.imageDataCache.clear();
|
||||
ClientCacheHandler.questTrackingOverlay = null;
|
||||
ClientCacheHandler.customOverlays.clear();
|
||||
ClientCacheHandler.skinOverlays.clear();
|
||||
ClientCacheHandler.playerAnimations.clear();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package noppes.npcs.client;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
@@ -65,12 +66,12 @@ public class ClientEventHandler {
|
||||
@SubscribeEvent
|
||||
public void onOverlayRender(RenderGameOverlayEvent.Post event){
|
||||
if(event.type == RenderGameOverlayEvent.ElementType.ALL) {
|
||||
for (OverlayCustom overlayCustom : Client.customOverlays.values()) {
|
||||
for (OverlayCustom overlayCustom : ClientCacheHandler.customOverlays.values()) {
|
||||
overlayCustom.renderGameOverlay(event.partialTicks);
|
||||
}
|
||||
|
||||
if (Client.questTrackingOverlay != null) {
|
||||
Client.questTrackingOverlay.renderGameOverlay(event.partialTicks);
|
||||
if (ClientCacheHandler.questTrackingOverlay != null) {
|
||||
ClientCacheHandler.questTrackingOverlay.renderGameOverlay(event.partialTicks);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,8 +91,8 @@ public class ClientEventHandler {
|
||||
if (event.entity instanceof EntityNPCInterface) {
|
||||
data = ClientEventHandler.renderingNpc.display.animationData;
|
||||
} else if (event.entity instanceof EntityPlayer) {
|
||||
if (Client.playerAnimations.containsKey(event.entity.getUniqueID())) {
|
||||
data = Client.playerAnimations.get(event.entity.getUniqueID());
|
||||
if (ClientCacheHandler.playerAnimations.containsKey(event.entity.getUniqueID())) {
|
||||
data = ClientCacheHandler.playerAnimations.get(event.entity.getUniqueID());
|
||||
}
|
||||
|
||||
for (Map.Entry<ModelRenderer,FramePart> entry : ClientEventHandler.originalValues.entrySet()) {
|
||||
@@ -123,8 +124,8 @@ public class ClientEventHandler {
|
||||
AnimationData data = null;
|
||||
if (event.entity instanceof EntityNPCInterface) {
|
||||
data = ((EntityNPCInterface) event.entity).display.animationData;
|
||||
} else if (event.entity instanceof EntityPlayer && Client.playerAnimations.containsKey(event.entity.getUniqueID())) {
|
||||
data = Client.playerAnimations.get(event.entity.getUniqueID());
|
||||
} else if (event.entity instanceof EntityPlayer && ClientCacheHandler.playerAnimations.containsKey(event.entity.getUniqueID())) {
|
||||
data = ClientCacheHandler.playerAnimations.get(event.entity.getUniqueID());
|
||||
}
|
||||
|
||||
if (data != null && data.isActive()) {
|
||||
@@ -199,6 +200,6 @@ public class ClientEventHandler {
|
||||
}
|
||||
|
||||
public static boolean hasOverlays(EntityPlayer player) {
|
||||
return Client.skinOverlays.containsKey(player.getUniqueID()) && Client.skinOverlays.get(player.getUniqueID()).values().size() > 0;
|
||||
return ClientCacheHandler.skinOverlays.containsKey(player.getUniqueID()) && ClientCacheHandler.skinOverlays.get(player.getUniqueID()).values().size() > 0;
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,11 @@ package noppes.npcs.client;
|
||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ContainerPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
@@ -30,6 +32,10 @@ public class ClientTickHandler{
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
public void onClientTick(TickEvent.ClientTickEvent event){
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if ((this.prevWorld == null || mc.theWorld == null) && this.prevWorld != mc.theWorld) {
|
||||
ClientCacheHandler.clearCache();
|
||||
this.prevWorld = mc.theWorld;
|
||||
}
|
||||
if(event.phase == Phase.END) {
|
||||
if (mc.thePlayer != null && mc.theWorld != null && !mc.isGamePaused() && ClientEventHandler.hasOverlays(mc.thePlayer)) {
|
||||
renderCNPCPlayer.itemRenderer.updateEquippedItem();
|
||||
|
||||
@@ -12,7 +12,6 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.AnimationData;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.client.fx.CustomFX;
|
||||
@@ -73,8 +72,8 @@ public class NoppesUtil {
|
||||
HashMap<Integer, SkinOverlay> skinOverlays = new HashMap<>();
|
||||
HashMap<Integer, SkinOverlay> oldOverlays = new HashMap<>();
|
||||
NBTTagList skinOverlayList = compound.getTagList("SkinOverlayData",10);
|
||||
if (Client.skinOverlays.containsKey(player.getUniqueID())) {
|
||||
oldOverlays = Client.skinOverlays.get(player.getUniqueID());
|
||||
if (ClientCacheHandler.skinOverlays.containsKey(player.getUniqueID())) {
|
||||
oldOverlays = ClientCacheHandler.skinOverlays.get(player.getUniqueID());
|
||||
}
|
||||
|
||||
for (int i = 0; i < skinOverlayList.tagCount(); i++) {
|
||||
@@ -85,7 +84,7 @@ public class NoppesUtil {
|
||||
}
|
||||
skinOverlays.put(tagID,overlay);
|
||||
}
|
||||
Client.skinOverlays.put(player.getUniqueID(), skinOverlays);
|
||||
ClientCacheHandler.skinOverlays.put(player.getUniqueID(), skinOverlays);
|
||||
}
|
||||
|
||||
public static void spawnScriptedParticle(EntityPlayer player, ByteBuf buffer){
|
||||
|
||||
@@ -265,19 +265,19 @@ public class PacketHandlerClient extends PacketHandlerServer{
|
||||
OverlayCustom overlayCustom = new OverlayCustom(Minecraft.getMinecraft());
|
||||
overlayCustom.setOverlayData(Server.readNBT(buffer));
|
||||
|
||||
Client.customOverlays.put(overlayCustom.overlay.getID(),overlayCustom);
|
||||
ClientCacheHandler.customOverlays.put(overlayCustom.overlay.getID(),overlayCustom);
|
||||
}
|
||||
else if(type == EnumPacketClient.SCRIPT_OVERLAY_CLOSE){
|
||||
int id = buffer.readInt();
|
||||
Client.customOverlays.remove(id);
|
||||
ClientCacheHandler.customOverlays.remove(id);
|
||||
}
|
||||
else if(type == EnumPacketClient.OVERLAY_QUEST_TRACKING){
|
||||
try {
|
||||
NBTTagCompound compound = Server.readNBT(buffer);
|
||||
Client.questTrackingOverlay = new OverlayQuestTracking(Minecraft.getMinecraft());
|
||||
Client.questTrackingOverlay.setOverlayData(compound);
|
||||
ClientCacheHandler.questTrackingOverlay = new OverlayQuestTracking(Minecraft.getMinecraft());
|
||||
ClientCacheHandler.questTrackingOverlay.setOverlayData(compound);
|
||||
} catch (IOException e) {
|
||||
Client.questTrackingOverlay = null;
|
||||
ClientCacheHandler.questTrackingOverlay = null;
|
||||
}
|
||||
}
|
||||
else if(type == EnumPacketClient.SWING_PLAYER_ARM){
|
||||
@@ -307,7 +307,7 @@ public class PacketHandlerClient extends PacketHandlerServer{
|
||||
data.readFromNBT(compound);
|
||||
data.animation = new Animation();
|
||||
data.animation.readFromNBT(compound.getCompoundTag("Animation"));
|
||||
Client.playerAnimations.put(sendingPlayer.getUniqueID(), data);
|
||||
ClientCacheHandler.playerAnimations.put(sendingPlayer.getUniqueID(), data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.RenderPlayerEvent;
|
||||
import noppes.npcs.client.Client;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.controllers.data.SkinOverlay;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.util.glu.Project;
|
||||
@@ -106,8 +106,8 @@ public class RenderCNPCPlayer extends RenderPlayer {
|
||||
|
||||
if (!p_77036_1_.isInvisible())
|
||||
{
|
||||
if (Client.skinOverlays.containsKey(player.getUniqueID())) {
|
||||
for (SkinOverlay overlayData : Client.skinOverlays.get(player.getUniqueID()).values()) {
|
||||
if (ClientCacheHandler.skinOverlays.containsKey(player.getUniqueID())) {
|
||||
for (SkinOverlay overlayData : ClientCacheHandler.skinOverlays.get(player.getUniqueID()).values()) {
|
||||
if (overlayData.texture.isEmpty())
|
||||
continue;
|
||||
|
||||
@@ -271,8 +271,8 @@ public class RenderCNPCPlayer extends RenderPlayer {
|
||||
gender = (float) RenderPlayerJBRA.getMethod("genGet").invoke(null);
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
if (Client.skinOverlays.containsKey(player.getUniqueID())) {
|
||||
for (SkinOverlay overlayData : Client.skinOverlays.get(player.getUniqueID()).values()) {
|
||||
if (ClientCacheHandler.skinOverlays.containsKey(player.getUniqueID())) {
|
||||
for (SkinOverlay overlayData : ClientCacheHandler.skinOverlays.get(player.getUniqueID()).values()) {
|
||||
if (overlayData.texture.isEmpty())
|
||||
continue;
|
||||
|
||||
@@ -398,8 +398,8 @@ public class RenderCNPCPlayer extends RenderPlayer {
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
try {
|
||||
if (Client.skinOverlays.containsKey(player.getUniqueID())) {
|
||||
for (SkinOverlay overlayData : Client.skinOverlays.get(player.getUniqueID()).values()) {
|
||||
if (ClientCacheHandler.skinOverlays.containsKey(player.getUniqueID())) {
|
||||
for (SkinOverlay overlayData : ClientCacheHandler.skinOverlays.get(player.getUniqueID()).values()) {
|
||||
if (overlayData.texture.isEmpty())
|
||||
continue;
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package noppes.npcs.mixin;
|
||||
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.model.ModelBiped;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
import noppes.npcs.AnimationData;
|
||||
import noppes.npcs.client.Client;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.client.ClientEventHandler;
|
||||
import noppes.npcs.constants.EnumAnimationPart;
|
||||
import noppes.npcs.controllers.data.Frame;
|
||||
@@ -110,8 +109,8 @@ public abstract class MixinModelRenderer {
|
||||
if (ClientEventHandler.renderingPlayer != null) {
|
||||
ClientEventHandler.playerModel = ((ModelRenderer) (Object) this).baseModel;
|
||||
}
|
||||
if (ClientEventHandler.renderingPlayer != null && Client.playerAnimations.containsKey(ClientEventHandler.renderingPlayer.getUniqueID())) {
|
||||
animData = Client.playerAnimations.get(ClientEventHandler.renderingPlayer.getUniqueID());
|
||||
if (ClientEventHandler.renderingPlayer != null && ClientCacheHandler.playerAnimations.containsKey(ClientEventHandler.renderingPlayer.getUniqueID())) {
|
||||
animData = ClientCacheHandler.playerAnimations.get(ClientEventHandler.renderingPlayer.getUniqueID());
|
||||
|
||||
EnumAnimationPart mainPartType = null;
|
||||
try{
|
||||
|
||||
@@ -5,8 +5,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||
import net.minecraft.client.renderer.entity.RenderPlayer;
|
||||
import noppes.npcs.AnimationData;
|
||||
import noppes.npcs.client.Client;
|
||||
import noppes.npcs.client.ClientEventHandler;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.constants.EnumAnimationPart;
|
||||
import noppes.npcs.controllers.data.Frame;
|
||||
import noppes.npcs.controllers.data.FramePart;
|
||||
@@ -23,8 +22,8 @@ public class MixinRenderPlayer {
|
||||
@Inject(method = "renderLivingAt", at = @At(value = "TAIL"))
|
||||
protected void modelDataRotations(AbstractClientPlayer p_77039_1_, double p_77039_2_, double p_77039_4_, double p_77039_6_, CallbackInfo callbackInfo)
|
||||
{
|
||||
if (Client.playerAnimations.containsKey(p_77039_1_.getUniqueID())) {
|
||||
AnimationData animData = Client.playerAnimations.get(p_77039_1_.getUniqueID());
|
||||
if (ClientCacheHandler.playerAnimations.containsKey(p_77039_1_.getUniqueID())) {
|
||||
AnimationData animData = ClientCacheHandler.playerAnimations.get(p_77039_1_.getUniqueID());
|
||||
if (animData != null && animData.isActive()) {
|
||||
Frame frame = (Frame) animData.animation.currentFrame();
|
||||
if (frame.frameParts.containsKey(EnumAnimationPart.FULL_MODEL)) {
|
||||
|
||||
Reference in new issue
Block a user