mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 01:05:12 +00:00
Fixed animations not ticking correctly sometimes.
This commit is contained in:
1 parent
a07a33c068
commit
ae2edfd79f
3 files changed
+55
-37
No files matched your search
@@ -19,6 +19,7 @@ import noppes.npcs.blocks.tiles.TileNpcContainer;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
import noppes.npcs.containers.*;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.controllers.data.AnimationData;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.util.MillisTimer;
|
||||
@@ -26,8 +27,8 @@ import noppes.npcs.util.MillisTimer;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class CommonProxy implements IGuiHandler {
|
||||
public final static HashSet<Animation> clientPlayingAnimations = new HashSet<>();
|
||||
public final static HashSet<Animation> serverPlayingAnimations = new HashSet<>();
|
||||
public final static HashSet<AnimationData> clientPlayingAnimations = new HashSet<>();
|
||||
public final static HashSet<AnimationData> serverPlayingAnimations = new HashSet<>();
|
||||
protected MillisTimer animationTimer = new MillisTimer(1000);
|
||||
protected static long totalServerTicks;
|
||||
protected static long totalClientTicks;
|
||||
@@ -48,18 +49,22 @@ public class CommonProxy implements IGuiHandler {
|
||||
}
|
||||
|
||||
for (int i = 0; i < animationTimer.elapsedTicks; ++i) {
|
||||
for (Animation animation : clientPlayingAnimations) {
|
||||
int tickDuration = animation.currentFrame().tickDuration();
|
||||
if (updateAnimation(animation) && totalClientTicks % tickDuration == 0) {
|
||||
animation.increaseTime();
|
||||
for (AnimationData data : clientPlayingAnimations) {
|
||||
if (data.animation != null) {
|
||||
int tickDuration = data.animation.currentFrame().tickDuration();
|
||||
if (totalClientTicks % tickDuration == 0) {
|
||||
data.increaseTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
totalClientTicks++;
|
||||
|
||||
for (Animation animation : serverPlayingAnimations) {
|
||||
int tickDuration = animation.currentFrame().tickDuration();
|
||||
if (updateAnimation(animation) && totalServerTicks % tickDuration == 0) {
|
||||
animation.increaseTime();
|
||||
for (AnimationData data : serverPlayingAnimations) {
|
||||
if (data.animation != null) {
|
||||
int tickDuration = data.animation.currentFrame().tickDuration();
|
||||
if (totalServerTicks % tickDuration == 0) {
|
||||
data.increaseTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
totalServerTicks++;
|
||||
@@ -83,44 +88,33 @@ public class CommonProxy implements IGuiHandler {
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private boolean updateAnimation(Animation animation) {
|
||||
return animation.parent.isActive()
|
||||
|| animation.parent.animation == null
|
||||
&& animation.parent.isActive(animation.parent.currentClientAnimation);
|
||||
}
|
||||
|
||||
private boolean removeAnimation(Animation animation) {
|
||||
if (animation.currentFrame() == null || animation.parent == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean removeAnimation(AnimationData data) {
|
||||
Entity entity = null;
|
||||
if (animation.parent.parent instanceof DataDisplay) {
|
||||
entity = ((DataDisplay)animation.parent.parent).npc;
|
||||
if (data.parent instanceof DataDisplay) {
|
||||
entity = ((DataDisplay)data.parent).npc;
|
||||
} else {
|
||||
if (animation.parent.parent instanceof PlayerData) {
|
||||
entity = ((PlayerData) animation.parent.parent).player;
|
||||
} else if (animation.parent.parent instanceof EntityPlayer) {
|
||||
entity = (EntityPlayer) animation.parent.parent;
|
||||
if (data.parent instanceof PlayerData) {
|
||||
entity = ((PlayerData) data.parent).player;
|
||||
} else if (data.parent instanceof EntityPlayer) {
|
||||
entity = (EntityPlayer) data.parent;
|
||||
}
|
||||
}
|
||||
|
||||
if (entity == null) return true;
|
||||
|
||||
if (entity.worldObj != null && entity.worldObj.isRemote) {
|
||||
return animation.parent.animation != animation || clientRemoveAnimation(entity);
|
||||
return clientRemoveAnimation(entity);
|
||||
} else {
|
||||
return !animation.parent.isClientAnimating()
|
||||
|| animation.parent.animation != animation && animation.parent.currentClientAnimation != animation
|
||||
|| entity.worldObj == null || !entity.worldObj.loadedEntityList.contains(entity)
|
||||
return entity.worldObj == null || !entity.worldObj.loadedEntityList.contains(entity)
|
||||
|| CustomNpcs.getServer().isServerStopped();
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private boolean clientRemoveAnimation(Entity entity) {
|
||||
return Minecraft.getMinecraft().theWorld == null
|
||||
|| Minecraft.getMinecraft().currentScreen == null && !Minecraft.getMinecraft().theWorld.loadedEntityList.contains(entity);
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
return mc.theWorld == null
|
||||
|| mc.currentScreen == null && entity != mc.thePlayer && !mc.theWorld.loadedEntityList.contains(entity);
|
||||
}
|
||||
|
||||
public PlayerData getPlayerData(EntityPlayer player) {
|
||||
|
||||
@@ -179,6 +179,14 @@ public class Animation implements IAnimation {
|
||||
id = newID;
|
||||
}
|
||||
|
||||
public long getTotalTime() {
|
||||
long time = 0;
|
||||
for (Frame frame : this.frames) {
|
||||
time += (long) frame.duration * (frame.customized ? frame.tickDuration : this.tickDuration);
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound){
|
||||
if(compound.hasKey("ID")){
|
||||
id = compound.getInteger("ID");
|
||||
|
||||
@@ -32,6 +32,7 @@ public class AnimationData implements IAnimationData {
|
||||
|
||||
public Animation animation;
|
||||
public boolean allowAnimation = false;
|
||||
public long animatingTime = 0;
|
||||
|
||||
public Animation currentClientAnimation;
|
||||
private boolean isClientAnimating;
|
||||
@@ -93,6 +94,7 @@ public class AnimationData implements IAnimationData {
|
||||
EventHooks.onAnimationEnded(this.currentClientAnimation);
|
||||
}
|
||||
if (this.isClientAnimating) {
|
||||
this.animatingTime = 0;
|
||||
this.currentClientAnimation = this.animation;
|
||||
}
|
||||
|
||||
@@ -105,7 +107,7 @@ public class AnimationData implements IAnimationData {
|
||||
synchronized (CommonProxy.serverPlayingAnimations) {
|
||||
if (this.isClientAnimating && this.getMCEntity() != null &&
|
||||
!this.getMCEntity().worldObj.isRemote && this.animation != null) {
|
||||
CommonProxy.serverPlayingAnimations.add(this.animation);
|
||||
CommonProxy.serverPlayingAnimations.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,6 +162,14 @@ public class AnimationData implements IAnimationData {
|
||||
}
|
||||
}
|
||||
|
||||
public void increaseTime() {
|
||||
if (this.isActive()) {
|
||||
this.animation.increaseTime();
|
||||
} else if (this.isActive(animation.parent.currentClientAnimation)) {
|
||||
this.currentClientAnimation.increaseTime();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCached(int id) {
|
||||
return this.cachedAnimationIDs.contains(id);
|
||||
}
|
||||
@@ -259,9 +269,11 @@ public class AnimationData implements IAnimationData {
|
||||
newAnim.parent = this;
|
||||
}
|
||||
|
||||
synchronized (CommonProxy.clientPlayingAnimations) {
|
||||
if (this.getMCEntity() != null && this.getMCEntity().worldObj.isRemote && newAnim != null) {
|
||||
CommonProxy.clientPlayingAnimations.add(newAnim);
|
||||
|
||||
if (this.getMCEntity() != null && this.getMCEntity().worldObj.isRemote && newAnim != null) {
|
||||
this.animatingTime = 0;
|
||||
synchronized (CommonProxy.clientPlayingAnimations) {
|
||||
CommonProxy.clientPlayingAnimations.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,4 +302,8 @@ public class AnimationData implements IAnimationData {
|
||||
public IAnimation getAnimation() {
|
||||
return animation;
|
||||
}
|
||||
|
||||
public long getAnimatingTime() {
|
||||
return this.animatingTime;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user