mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-21 08:02:20 +00:00
If the animation data is disabled for players, their last frame of animation will gradually interpolate back to the player's vanilla animations.
This commit is contained in:
1 parent
a67604e22d
commit
bc089a4e14
4 files changed
+69
-17
No files matched your search
@@ -2,6 +2,7 @@ package noppes.npcs.controllers.data;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.api.handler.data.IAnimation;
|
||||
@@ -13,7 +14,7 @@ import java.util.ArrayList;
|
||||
|
||||
|
||||
public class Animation implements IAnimation {
|
||||
|
||||
public AnimationData parent; //Client-sided only
|
||||
public int id = -1; // Only for internal usage
|
||||
|
||||
public ArrayList<Frame> frames = new ArrayList<>();
|
||||
@@ -229,6 +230,10 @@ public class Animation implements IAnimation {
|
||||
if (paused)
|
||||
return;
|
||||
|
||||
if (this.parent != null && this.currentFrame < this.frames.size()) {
|
||||
this.parent.finishedFrame = this.currentFrame;
|
||||
}
|
||||
|
||||
this.currentFrameTime++;
|
||||
if (this.currentFrameTime == this.currentFrame().getDuration()) {
|
||||
Frame prevFrame = (Frame) this.currentFrame();
|
||||
@@ -247,6 +252,8 @@ public class Animation implements IAnimation {
|
||||
nextFrame.frameParts.get(part).prevPivots = prevFrame.frameParts.get(part).prevPivots;
|
||||
}
|
||||
}
|
||||
} else if (this.parent != null && this.currentFrame > this.loop) {
|
||||
this.parent.finishedTime = this.parent.animationEntity.getAge();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
@@ -27,11 +28,25 @@ public class AnimationData implements IAnimationData {
|
||||
|
||||
private final HashSet<Integer> cachedAnimationIDs = new HashSet<>();
|
||||
|
||||
//Client-side values
|
||||
public EntityLivingBase animationEntity;
|
||||
public int finishedTime = -1;
|
||||
public int finishedFrame = -1;
|
||||
|
||||
public AnimationData(Object parent){
|
||||
this.parent = parent;
|
||||
if (parent instanceof DataDisplay) {
|
||||
this.animationEntity = ((DataDisplay) parent).npc;
|
||||
} else if (parent instanceof EntityPlayer) {
|
||||
this.animationEntity = (EntityLivingBase) parent;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateClient() {
|
||||
this.updateClient(new EntityPlayer[0]);
|
||||
}
|
||||
|
||||
public void updateClient(EntityPlayer... excludedPlayers) {
|
||||
EntityLivingBase sendingEntity = parent instanceof PlayerData ? ((PlayerData) parent).player : parent instanceof DataDisplay ? ((DataDisplay) parent).npc : null;
|
||||
float range = parent instanceof PlayerData ? 160 : 60;
|
||||
if (sendingEntity != null) {
|
||||
@@ -40,6 +55,8 @@ public class AnimationData implements IAnimationData {
|
||||
sendingEntity.posX - range, sendingEntity.posY - range, sendingEntity.posZ - range,
|
||||
sendingEntity.posX + range, sendingEntity.posY + range, sendingEntity.posZ + range));
|
||||
|
||||
entities.removeIf(player -> Arrays.stream(excludedPlayers).anyMatch(exp -> player == exp));
|
||||
|
||||
NBTTagCompound animationNBT = null;
|
||||
for (EntityPlayer player : entities) {
|
||||
AnimationData animationData = PlayerDataController.Instance.getPlayerData(player).animationData;
|
||||
@@ -110,11 +127,16 @@ public class AnimationData implements IAnimationData {
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
this.allowAnimation = compound.getBoolean("AllowAnimation");
|
||||
this.setEnabled(compound.getBoolean("AllowAnimation"));
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.allowAnimation = enabled;
|
||||
if (this.allowAnimation != enabled) {
|
||||
this.allowAnimation = enabled;
|
||||
if (this.parent instanceof EntityPlayer) {
|
||||
this.finishedTime = enabled ? -1 : ((EntityPlayer) this.parent).getAge();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean enabled() {
|
||||
|
||||
Reference in new issue
Block a user