From 34d002191e6ff8e3089829c94538e792f7ea2af4 Mon Sep 17 00:00:00 2001 From: "Luis C.M." <42545778+c0508383@users.noreply.github.com> Date: Thu, 23 Jan 2025 00:35:25 -0600 Subject: [PATCH] Animation fixes, temporarily removed caching. --- .../java/noppes/npcs/ServerEventsHandler.java | 26 +++++++++++++++---- .../npcs/client/PacketHandlerClient.java | 13 +++------- .../npcs/controllers/data/AnimationData.java | 13 +++------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/main/java/noppes/npcs/ServerEventsHandler.java b/src/main/java/noppes/npcs/ServerEventsHandler.java index e4c8b9ff6..a9ae6a84a 100644 --- a/src/main/java/noppes/npcs/ServerEventsHandler.java +++ b/src/main/java/noppes/npcs/ServerEventsHandler.java @@ -491,12 +491,28 @@ public class ServerEventsHandler { @SubscribeEvent public void playerTracking(PlayerEvent.StartTracking event){ - if(!(event.target instanceof EntityNPCInterface) || event.target.worldObj.isRemote) + if(!(event.target instanceof EntityPlayerMP || event.target instanceof EntityNPCInterface) || event.target.worldObj.isRemote) return; - MarkData data = MarkData.get((EntityNPCInterface) event.target); - if(data.marks.isEmpty()) - return; - Server.sendData((EntityPlayerMP)event.entityPlayer, EnumPacketClient.MARK_DATA, event.target.getEntityId(), data.getNBT()); + AnimationData animationData = AnimationData.getData(event.target); + if (animationData.isClientAnimating()) { + AnimationData playerAnimData = AnimationData.getData(event.entityPlayer); + Animation currentAnimation = animationData.currentClientAnimation; + NBTTagCompound compound = currentAnimation.writeToNBT(); + + if (playerAnimData.viewAnimation(currentAnimation, animationData, compound, + animationData.isClientAnimating(), currentAnimation.currentFrame, currentAnimation.currentFrameTime)) { + synchronized (CommonProxy.serverPlayingAnimations) { + CommonProxy.serverPlayingAnimations.add(animationData); + } + } + } + + if (event.target instanceof EntityNPCInterface) { + MarkData data = MarkData.get((EntityNPCInterface) event.target); + if (data.marks.isEmpty()) + return; + Server.sendData((EntityPlayerMP) event.entityPlayer, EnumPacketClient.MARK_DATA, event.target.getEntityId(), data.getNBT()); + } } } diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index 07f025119..f9aa7dc8e 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -368,19 +368,14 @@ public class PacketHandlerClient extends PacketHandlerServer{ } if (animationData != null) { - int animationId; - if (compound.hasKey("AnimationID")) { - animationId = compound.getInteger("AnimationID"); - } else { + if (compound.hasKey("Animation")) { Animation animation = new Animation(); animation.readFromNBT(compound.getCompoundTag("Animation")); - ClientCacheHandler.animationCache.put(animation.getID(), animation); - animationId = animation.getID(); + animationData.setAnimation(animation); + } else { + animationData.setAnimation(null); } - - animationData.setAnimation(ClientCacheHandler.animationCache.get(animationId)); animationData.readFromNBT(compound); - Client.sendData(EnumPacketServer.CacheAnimation, animationId); } } else if(type == EnumPacketClient.DISABLE_MOUSE_INPUT) { diff --git a/src/main/java/noppes/npcs/controllers/data/AnimationData.java b/src/main/java/noppes/npcs/controllers/data/AnimationData.java index 8ddf852ce..71818a669 100644 --- a/src/main/java/noppes/npcs/controllers/data/AnimationData.java +++ b/src/main/java/noppes/npcs/controllers/data/AnimationData.java @@ -120,12 +120,9 @@ public class AnimationData implements IAnimationData { entities.removeIf(player -> Arrays.stream(excludedPlayers).anyMatch(exp -> player == exp)); - NBTTagCompound animationNBT = null; for (EntityPlayer player : entities) { AnimationData animationData = PlayerDataController.Instance.getPlayerData(player).animationData; - if (animationNBT == null && this.animation != null && !animationData.isCached(this.animation.getID())) { - animationNBT = this.animation.writeToNBT(); - } + NBTTagCompound animationNBT = this.animation != null ? this.animation.writeToNBT() : null; animationData.viewAnimation(this.animation, this, animationNBT); } } @@ -221,12 +218,8 @@ public class AnimationData implements IAnimationData { data.setInteger("Time", time); } - if (animation != null) { - if (this.cachedAnimationIDs.contains(animation.getID()) && !data.hasKey("Frame")) { - data.setInteger("AnimationID", animation.getID()); - } else { - data.setTag("Animation", animationNBT); - } + if (animationNBT != null) { + data.setTag("Animation", animationNBT); } IAnimatable animatable = animationData.getEntity();