Loads of changes from the animation branch

This commit is contained in:
Luis C.M. committed 2025-01-22 18:54:00 -06:00
1 parent 990419a411
commit 572077b7e5
13 files changed
+1091 -692

No files matched your search

@@ -4,7 +4,9 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.EventHooks;
import noppes.npcs.api.handler.data.IAnimation;
import noppes.npcs.api.handler.data.IAnimationData;
import noppes.npcs.api.handler.data.IFrame;
import noppes.npcs.constants.EnumAnimationPart;
import noppes.npcs.controllers.AnimationController;
@@ -13,262 +15,300 @@ import java.util.ArrayList;
public class Animation implements IAnimation {
public AnimationData parent; //Client-sided only
public int id = -1; // Only for internal usage
public AnimationData parent; //Client-sided only
public int id = -1; // Only for internal usage
public ArrayList<Frame> frames = new ArrayList<>();
public int currentFrame = 0;
public int currentFrameTime = 0;
public ArrayList<Frame> frames = new ArrayList<>();
public int currentFrame = 0;
public int currentFrameTime = 0;
public String name = "";
public float speed = 1.0F;
public byte smooth = 0;
public int loop = -1; //If greater than 0 and less than the amount of frames, the animation will begin looping when it reaches this frame.
public boolean renderTicks = false; // If true, MC ticks are used. If false, render ticks are used.
public String name = "";
public float speed = 1.0F;
public byte smooth = 0;
public int loop = -1; //If greater than 0 and less than the amount of frames, the animation will begin looping when it reaches this frame.
public int tickDuration = 50;
public boolean whileStanding = true;
public boolean whileAttacking = true;
public boolean whileMoving = true;
public boolean whileStanding = true;
public boolean whileAttacking = true;
public boolean whileMoving = true;
//Client-sided
public boolean paused;
//Client-sided
public boolean paused;
public Animation(){}
public Animation(){}
public Animation(int id, String name){
this.name = name;
this.id = id;
}
public Animation(int id, String name){
this.name = name;
this.id = id;
}
public Animation(int id, String name, float speed, byte smooth){
this.name = name;
this.speed = speed;
this.smooth = smooth;
public Animation(int id, String name, float speed, byte smooth){
this.name = name;
this.speed = speed;
this.smooth = smooth;
this.id = id;
}
this.id = id;
}
public IFrame currentFrame() {
return currentFrame < frames.size() ? frames.get(currentFrame) : null;
}
public IAnimationData getParent() {
return this.parent;
}
public IFrame[] getFrames() {
return frames.toArray(new Frame[0]);
}
public IFrame currentFrame() {
return currentFrame < frames.size() ? frames.get(currentFrame) : null;
}
public IAnimation setFrames(IFrame[] frames) {
this.clearFrames();
for (IFrame frame : frames) {
this.frames.add((Frame) frame);
}
return this;
}
public IFrame[] getFrames() {
return frames.toArray(new Frame[0]);
}
public IAnimation clearFrames() {
this.frames.clear();
return this;
}
public IAnimation setFrames(IFrame[] frames) {
this.clearFrames();
for (IFrame frame : frames) {
this.frames.add((Frame) frame);
}
return this;
}
public IAnimation addFrame(IFrame frame) {
this.frames.add((Frame) frame);
return this;
}
public IAnimation clearFrames() {
this.frames.clear();
return this;
}
public IAnimation addFrame(int index, IFrame frame) {
this.frames.add(index, (Frame) frame);
return this;
}
public IAnimation addFrame(IFrame frame) {
this.frames.add((Frame) frame);
return this;
}
public IAnimation removeFrame(IFrame frame) {
this.frames.remove((Frame) frame);
return this;
}
public IAnimation addFrame(int index, IFrame frame) {
this.frames.add(index, (Frame) frame);
return this;
}
public IAnimation setName(String name) {
this.name = name;
return this;
}
public IAnimation removeFrame(IFrame frame) {
this.frames.remove((Frame) frame);
return this;
}
public String getName() {
return this.name;
}
public IAnimation setName(String name) {
this.name = name;
return this;
}
public IAnimation setSpeed(float speed) {
this.speed = speed;
return this;
}
public String getName() {
return this.name;
}
public float getSpeed() {
return this.speed;
}
public int tickDuration() {
return this.tickDuration;
}
public IAnimation setSmooth(byte smooth) {
this.smooth = smooth;
return this;
}
public IAnimation setTickDuration(int tickDuration) {
this.tickDuration = tickDuration;
return this;
}
public byte isSmooth() {
return this.smooth;
}
public IAnimation setSpeed(float speed) {
this.speed = speed;
return this;
}
public IAnimation useRenderTicks(boolean renderTicks) {
this.renderTicks = renderTicks;
return this;
}
public float getSpeed() {
return this.speed;
}
public boolean useRenderTicks() {
return this.renderTicks;
}
public IAnimation setSmooth(byte smooth) {
this.smooth = smooth;
return this;
}
public IAnimation doWhileStanding(boolean whileStanding) {
this.whileStanding = whileStanding;
return this;
}
public byte isSmooth() {
return this.smooth;
}
public boolean doWhileStanding() {
return this.whileStanding;
}
public IAnimation doWhileStanding(boolean whileStanding) {
this.whileStanding = whileStanding;
return this;
}
public IAnimation doWhileMoving(boolean whileMoving) {
this.whileMoving = whileMoving;
return this;
}
public boolean doWhileStanding() {
return this.whileStanding;
}
public boolean doWhileMoving() {
return this.whileMoving;
}
public IAnimation doWhileMoving(boolean whileMoving) {
this.whileMoving = whileMoving;
return this;
}
public IAnimation doWhileAttacking(boolean whileAttacking) {
this.whileAttacking = whileAttacking;
return this;
}
public boolean doWhileMoving() {
return this.whileMoving;
}
public boolean doWhileAttacking() {
return this.whileAttacking;
}
public IAnimation doWhileAttacking(boolean whileAttacking) {
this.whileAttacking = whileAttacking;
return this;
}
public IAnimation setLoop(int loopAtFrame) {
this.loop = loopAtFrame;
return this;
}
public boolean doWhileAttacking() {
return this.whileAttacking;
}
public int loop() {
return this.loop;
}
public IAnimation setLoop(int loopAtFrame) {
this.loop = loopAtFrame;
return this;
}
public IAnimation save() {
return AnimationController.Instance.saveAnimation(this);
}
public int loop() {
return this.loop;
}
@Override
public int getID() {
return id;
}
public IAnimation save() {
return AnimationController.Instance.saveAnimation(this);
}
@Override
public void setID(int newID) {
id = newID;
}
@Override
public int getID() {
return id;
}
public void readFromNBT(NBTTagCompound compound){
if(compound.hasKey("ID")){
id = compound.getInteger("ID");
}
else if (AnimationController.Instance != null) {
id = AnimationController.Instance.getUnusedId();
}
@Override
public void setID(int newID) {
id = newID;
}
name = compound.getString("Name");
speed = compound.getFloat("Speed");
smooth = compound.getByte("Smooth");
loop = compound.getInteger("Loop");
public long getTotalTime() {
long time = 0;
for (Frame frame : this.frames) {
time += (long) frame.duration * (frame.customized ? frame.tickDuration : this.tickDuration);
}
return time;
}
renderTicks = compound.getBoolean("RenderTicks");
public void readFromNBT(NBTTagCompound compound){
if(compound.hasKey("ID")){
id = compound.getInteger("ID");
}
else if (AnimationController.Instance != null) {
id = AnimationController.Instance.getUnusedId();
}
ArrayList<Frame> frames = new ArrayList<Frame>();
NBTTagList list = compound.getTagList("Frames", 10);
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound item = list.getCompoundTagAt(i);
Frame frame = new Frame();
frame.parent = this;
frame.readFromNBT(item);
frames.add(frame);
}
this.frames = frames;
name = compound.getString("Name");
speed = compound.getFloat("Speed");
smooth = compound.getByte("Smooth");
loop = compound.getInteger("Loop");
this.whileStanding = compound.getBoolean("WhileStanding");
this.whileMoving = compound.getBoolean("WhileWalking");
this.whileAttacking = compound.getBoolean("WhileAttacking");
}
if (compound.hasKey("TickDuration")) {
this.tickDuration = compound.getInteger("TickDuration");
} else if(compound.hasKey("RenderTicks")){
this.tickDuration = compound.getBoolean("RenderTicks") ? 20 : 50;
}
public NBTTagCompound writeToNBT(){
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("ID", id);
compound.setString("Name", name);
compound.setFloat("Speed", speed);
compound.setByte("Smooth", smooth);
compound.setInteger("Loop",loop);
ArrayList<Frame> frames = new ArrayList<Frame>();
NBTTagList list = compound.getTagList("Frames", 10);
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound item = list.getCompoundTagAt(i);
Frame frame = new Frame();
frame.parent = this;
frame.readFromNBT(item);
frames.add(frame);
}
this.frames = frames;
compound.setBoolean("RenderTicks", renderTicks);
this.whileStanding = compound.getBoolean("WhileStanding");
this.whileMoving = compound.getBoolean("WhileWalking");
this.whileAttacking = compound.getBoolean("WhileAttacking");
NBTTagList list = new NBTTagList();
for(Frame frame : frames){
NBTTagCompound item = frame.writeToNBT();
list.appendTag(item);
}
compound.setTag("Frames", list);
this.currentFrame = compound.getInteger("CurrentFrame");
this.currentFrameTime = compound.getInteger("CurrentFrameTime");
}
compound.setBoolean("WhileStanding", whileStanding);
compound.setBoolean("WhileWalking", whileMoving);
compound.setBoolean("WhileAttacking", whileAttacking);
return compound;
}
public NBTTagCompound writeToNBT(){
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("ID", id);
compound.setString("Name", name);
compound.setFloat("Speed", speed);
compound.setByte("Smooth", smooth);
compound.setInteger("Loop",loop);
compound.setInteger("TickDuration", tickDuration);
@SideOnly(Side.CLIENT)
public void increaseTime() {
if (paused)
return;
NBTTagList list = new NBTTagList();
for(Frame frame : frames){
NBTTagCompound item = frame.writeToNBT();
list.appendTag(item);
}
compound.setTag("Frames", list);
if (this.parent != null && this.currentFrame < this.frames.size()) {
this.parent.finishedFrame = this.currentFrame;
}
compound.setBoolean("WhileStanding", whileStanding);
compound.setBoolean("WhileWalking", whileMoving);
compound.setBoolean("WhileAttacking", whileAttacking);
this.currentFrameTime++;
if (this.currentFrameTime == this.currentFrame().getDuration()) {
Frame prevFrame = (Frame) this.currentFrame();
Frame nextFrame = null;
this.currentFrameTime = 0;
this.currentFrame++;
if (this.currentFrame < this.frames.size()) {
nextFrame = this.frames.get(this.currentFrame);
} else if (this.loop >= 0 && this.loop < this.frames.size()) {
this.currentFrame = this.loop;
}
if (nextFrame != null) {
for (EnumAnimationPart part : EnumAnimationPart.values()) {
if (prevFrame.frameParts.containsKey(part) && nextFrame.frameParts.containsKey(part)) {
nextFrame.frameParts.get(part).prevRotations = prevFrame.frameParts.get(part).prevRotations;
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();
}
}
}
compound.setInteger("CurrentFrame", currentFrame);
compound.setInteger("CurrentFrameTime", currentFrameTime);
return compound;
}
@SideOnly(Side.CLIENT)
public void jumpToCurrentFrame() {
this.currentFrameTime = 0;
Frame frame = (Frame) this.currentFrame();
if(frame != null){
for (EnumAnimationPart part : EnumAnimationPart.values()) {
if(part != null){
if (frame.frameParts.containsKey(part)) {
frame.frameParts.get(part).jumpToCurrentFrame();
}
}
}
}
}
public boolean increaseTime() {
if (paused)
return false;
if (this.parent != null && this.currentFrame < this.frames.size()) {
this.parent.finishedFrame = this.currentFrame;
}
this.currentFrameTime++;
if (this.currentFrame() != null && this.currentFrameTime == this.currentFrame().getDuration()) {
EventHooks.onAnimationFrameExited(this, this.currentFrame());
Frame prevFrame = (Frame) this.currentFrame();
Frame nextFrame = null;
this.currentFrameTime = 0;
this.currentFrame++;
if (this.currentFrame < this.frames.size()) {
nextFrame = this.frames.get(this.currentFrame);
} else if (this.loop >= 0 && this.loop < this.frames.size()) {
this.currentFrame = this.loop;
}
if (this.currentFrame() != null) {
EventHooks.onAnimationFrameEntered(this, this.currentFrame());
} else {
EventHooks.onAnimationEnded(this);
}
if (nextFrame != null) {
for (EnumAnimationPart part : EnumAnimationPart.values()) {
if (prevFrame.frameParts.containsKey(part) && nextFrame.frameParts.containsKey(part)) {
nextFrame.frameParts.get(part).prevRotations = prevFrame.frameParts.get(part).prevRotations;
nextFrame.frameParts.get(part).prevPivots = prevFrame.frameParts.get(part).prevPivots;
}
}
} else if (this.parent != null && this.currentFrame > this.loop) {
this.parent.finishedTime = this.parent.getMCEntity().getAge();
}
}
return true;
}
@SideOnly(Side.CLIENT)
public void jumpToCurrentFrame() {
this.jumpToFrameAtTime(this.currentFrame, 0);
}
@SideOnly(Side.CLIENT)
public void jumpToFrameAtTime(int frameIndex, int time) {
this.currentFrame = frameIndex;
this.currentFrameTime = time;
Frame frame = (Frame) this.currentFrame();
if(frame != null){
for (EnumAnimationPart part : EnumAnimationPart.values()) {
if(part != null){
if (frame.frameParts.containsKey(part)) {
frame.frameParts.get(part).jumpToCurrentFrame();
}
}
}
}
}
}
@@ -3,19 +3,25 @@ package noppes.npcs.controllers.data;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import noppes.npcs.CommonProxy;
import noppes.npcs.DataDisplay;
import noppes.npcs.EventHooks;
import noppes.npcs.Server;
import noppes.npcs.api.entity.IAnimatable;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.handler.data.IAnimation;
import noppes.npcs.api.handler.data.IAnimationData;
import noppes.npcs.constants.EnumAnimationPart;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.NpcAPI;
import java.util.Arrays;
import java.util.HashSet;
@@ -29,20 +35,47 @@ public class AnimationData implements IAnimationData {
public Animation animation;
public boolean allowAnimation = false;
public long animatingTime = 0;
public Animation currentClientAnimation;
private boolean isClientAnimating;
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 static AnimationData getData(Entity entity) {
if (entity instanceof EntityPlayerMP) {
return PlayerData.get((EntityPlayer) entity).animationData;
} else if (entity instanceof EntityNPCInterface) {
return ((EntityNPCInterface)entity).display.animationData;
} else {
return null;
}
}
public IAnimatable getEntity() {
IEntity<?> entity = NpcAPI.Instance().getIEntity(this.getMCEntity());
if (entity instanceof IAnimatable) {
return (IAnimatable) entity;
}
return null;
}
public EntityLivingBase getMCEntity() {
if (this.parent instanceof DataDisplay) {
return ((DataDisplay) this.parent).npc;
} else {
if (this.parent instanceof PlayerData) {
return ((PlayerData) this.parent).player;
} else {
return (EntityPlayer) this.parent;
}
}
}
@@ -57,6 +90,30 @@ public class AnimationData implements IAnimationData {
if(sendingEntity.dimension != sendingEntity.worldObj.provider.dimensionId)
sendingEntity.dimension = sendingEntity.worldObj.provider.dimensionId;
this.animatingTime = 0;
boolean prevIsClientAnimating = this.isClientAnimating && this.currentClientAnimation.currentFrame() != null;
this.isClientAnimating = this.allowAnimation && this.animation != null;
if (prevIsClientAnimating && (!this.isClientAnimating || this.animation != this.currentClientAnimation)) {
EventHooks.onAnimationEnded(this.currentClientAnimation);
}
if (this.isClientAnimating) {
this.currentClientAnimation = this.animation;
}
if (this.animation != null && this.allowAnimation) {
if (EventHooks.onAnimationStarted(this.animation))
return;
EventHooks.onAnimationFrameEntered(this.animation, this.animation.currentFrame());
}
synchronized (CommonProxy.serverPlayingAnimations) {
if (this.isClientAnimating && this.getMCEntity() != null &&
!this.getMCEntity().worldObj.isRemote && this.animation != null) {
CommonProxy.serverPlayingAnimations.add(this);
}
}
List<EntityPlayer> entities = sendingEntity.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(
sendingEntity.posX - range, sendingEntity.posY - range, sendingEntity.posZ - range,
sendingEntity.posX + range, sendingEntity.posY + range, sendingEntity.posZ + range));
@@ -69,13 +126,21 @@ public class AnimationData implements IAnimationData {
if (animationNBT == null && this.animation != null && !animationData.isCached(this.animation.getID())) {
animationNBT = this.animation.writeToNBT();
}
animationData.viewAnimation(this.animation, sendingEntity, this, animationNBT);
animationData.viewAnimation(this.animation, this, animationNBT);
}
}
}
public boolean isClientAnimating() {
return this.isClientAnimating;
}
public boolean isActive() {
if (!this.allowAnimation || this.animation == null || this.animation.currentFrame == this.animation.frames.size() || animation.currentFrame() == null)
return this.isActive(this.animation);
}
public boolean isActive(Animation animation) {
if (!this.allowAnimation || animation == null || animation.currentFrame == animation.frames.size() || animation.currentFrame() == null)
return false;
if (this.parent instanceof DataDisplay) {
@@ -100,6 +165,25 @@ public class AnimationData implements IAnimationData {
}
}
public void increaseTime() {
Animation updateAnimation = null;
if (this.isActive(animation.parent.currentClientAnimation)) {
updateAnimation = this.currentClientAnimation;
} else {
this.isClientAnimating = false;
if (this.isActive()) {
updateAnimation = this.animation;
}
}
if (updateAnimation != null && updateAnimation.increaseTime()) {
Frame frame = (Frame) updateAnimation.currentFrame();
if (frame != null) {
this.animatingTime += frame.customized ? frame.tickDuration : updateAnimation.tickDuration;
}
}
}
public boolean isCached(int id) {
return this.cachedAnimationIDs.contains(id);
}
@@ -116,27 +200,77 @@ public class AnimationData implements IAnimationData {
this.cachedAnimationIDs.clear();
}
public void viewAnimation(Animation animation, EntityLivingBase entity, AnimationData animationData, NBTTagCompound animationNBT) {
NBTTagCompound data = animationData.writeToNBT(new NBTTagCompound());
public void viewAnimation(Animation animation, AnimationData animationData, NBTTagCompound animationNBT) {
this.viewAnimation(animation, animationData, animationNBT, animationData.allowAnimation, -1, -1);
}
public boolean viewAnimation(Animation animation, AnimationData animationData, NBTTagCompound animationNBT, boolean enabled, int currentFrame, int time) {
if (animation != null
&& (currentFrame >= animation.frames.size()
|| currentFrame >= 0 && animation.frames.get(currentFrame).getDuration() < time)) {
return false;
}
boolean prevEnabled = animationData.allowAnimation;
animationData.allowAnimation = enabled;
NBTTagCompound data = animationData.viewWriteNBT(new NBTTagCompound());
animationData.allowAnimation = prevEnabled;
if (animation != null && currentFrame >= 0 && currentFrame < animation.frames.size()) {
data.setInteger("Frame", currentFrame);
data.setInteger("Time", time);
}
if (animation != null) {
if (this.cachedAnimationIDs.contains(animation.getID())) {
if (this.cachedAnimationIDs.contains(animation.getID()) && !data.hasKey("Frame")) {
data.setInteger("AnimationID", animation.getID());
} else {
data.setTag("Animation", animationNBT);
}
}
IAnimatable animatable = animationData.getEntity();
Entity entity = ((IEntity<?>) animatable).getMCEntity();
if (!(entity instanceof EntityPlayer)) {
data.setInteger("EntityId", entity.getEntityId());
}
Server.sendData((EntityPlayerMP) ((PlayerData) parent).player, EnumPacketClient.UPDATE_ANIMATIONS, data, entity.getCommandSenderName());
return true;
}
public NBTTagCompound viewWriteNBT(NBTTagCompound compound) {
compound.setBoolean("AllowAnimation", allowAnimation);
return compound;
}
public void viewReadFromNBT(NBTTagCompound compound) {
this.setEnabled(compound.getBoolean("AllowAnimation"));
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
if (this.currentClientAnimation != null) {
compound.setBoolean("IsClientAnimating", isClientAnimating);
if (this.isClientAnimating) {
compound.setTag("CurrentAnimation", currentClientAnimation.writeToNBT());
}
}
compound.setBoolean("AllowAnimation", allowAnimation);
return compound;
}
public void readFromNBT(NBTTagCompound compound) {
Entity entity = this.getMCEntity();
boolean isServer = entity != null && !entity.worldObj.isRemote;
if (compound.hasKey("IsClientAnimating") && isServer) {
this.isClientAnimating = compound.getBoolean("IsClientAnimating");
if (this.isClientAnimating) {
this.currentClientAnimation = new Animation();
this.currentClientAnimation.parent = this;
this.currentClientAnimation.readFromNBT(compound.getCompoundTag("CurrentAnimation"));
this.animation = this.currentClientAnimation;
}
}
this.setEnabled(compound.getBoolean("AllowAnimation"));
}
@@ -154,32 +288,41 @@ public class AnimationData implements IAnimationData {
}
public void setAnimation(IAnimation animation) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
this.animation = animation != null ? (Animation) animation : null;
} else {
if (animation != null) {
Animation newAnim = new Animation();
newAnim.readFromNBT(((Animation) animation).writeToNBT());
if (this.isActive() && !newAnim.frames.isEmpty()) {
Frame frame = (Frame) this.animation.currentFrame();
if (frame != null) {
Frame firstFrame = newAnim.frames.get(0);
for (Map.Entry<EnumAnimationPart, FramePart> entry : frame.frameParts.entrySet()) {
if (firstFrame.frameParts.containsKey(entry.getKey())) {
FramePart prevFramePart = entry.getValue();
FramePart newFramePart = firstFrame.frameParts.get(entry.getKey());
for (int i = 0; i < 3; i++) {
newFramePart.prevPivots[i] = prevFramePart.prevPivots[i];
newFramePart.prevRotations[i] = prevFramePart.prevRotations[i];
}
}
Animation newAnim = null;
if (animation != null) {
newAnim = new Animation();
newAnim.readFromNBT(((Animation) animation).writeToNBT());
newAnim.currentFrame = 0;
newAnim.currentFrameTime = 0;
newAnim.parent = this;
}
if (this.getMCEntity() != null && this.getMCEntity().worldObj.isRemote && newAnim != null) {
this.animatingTime = 0;
synchronized (CommonProxy.clientPlayingAnimations) {
CommonProxy.clientPlayingAnimations.add(this);
}
}
Animation prevAnim = this.animation;
this.animation = newAnim;
if (this.getMCEntity() != null && this.getMCEntity().worldObj.isRemote &&
this.isActive() && prevAnim != null && newAnim != null && !newAnim.frames.isEmpty()) {
Frame frame = (Frame) prevAnim.currentFrame();
if (frame != null) {
Frame firstFrame = newAnim.frames.get(0);
for (Map.Entry<EnumAnimationPart, FramePart> entry : frame.frameParts.entrySet()) {
if (firstFrame.frameParts.containsKey(entry.getKey())) {
FramePart prevFramePart = entry.getValue();
FramePart newFramePart = firstFrame.frameParts.get(entry.getKey());
for (int i = 0; i < 3; i++) {
newFramePart.prevPivots[i] = prevFramePart.prevPivots[i];
newFramePart.prevRotations[i] = prevFramePart.prevRotations[i];
}
}
}
this.animation = newAnim;
newAnim.parent = this;
} else {
this.animation = null;
}
}
}
@@ -187,4 +330,8 @@ public class AnimationData implements IAnimationData {
public IAnimation getAnimation() {
return animation;
}
public long getAnimatingTime() {
return this.animatingTime;
}
}
@@ -11,188 +11,206 @@ import java.util.Map;
public class Frame implements IFrame {
public Animation parent;
public HashMap<EnumAnimationPart,FramePart> frameParts = new HashMap<>();
public int duration = 0;
boolean customized = false;
public float speed = 1.0F;
public byte smooth = 0;
public boolean renderTicks = false; // If true, MC ticks are used. If false, render ticks are used.
public Animation parent;
public HashMap<EnumAnimationPart,FramePart> frameParts = new HashMap<>();
public int duration = 0;
public int tickDuration = 50;
private int colorMarker = 0xFFFFFF;
boolean customized = false;
public float speed = 1.0F;
public byte smooth = 0;
public Frame(){}
private int colorMarker = 0xFFFFFF;
private String comment = "";
public Frame(int duration) {
this.duration = duration;
}
public Frame(){}
public Frame(int duration, float speed, byte smooth) {
this.duration = duration;
this.speed = speed;
this.smooth = smooth;
this.customized = true;
}
public Frame(int duration) {
this.duration = duration;
}
public HashMap<EnumAnimationPart,FramePart> getFrameMap() {
return frameParts;
}
public Frame(int duration, float speed, byte smooth) {
this.duration = duration;
this.speed = speed;
this.smooth = smooth;
this.customized = true;
}
public IFramePart[] getParts() {
return frameParts.values().toArray(new IFramePart[0]);
}
public HashMap<EnumAnimationPart,FramePart> getFrameMap() {
return frameParts;
}
public IFrame addPart(IFramePart partConfig) {
this.frameParts.put(((FramePart)partConfig).getPart(),(FramePart) partConfig);
return this;
}
public IFramePart[] getParts() {
return frameParts.values().toArray(new IFramePart[0]);
}
public IFrame removePart(String partName) {
try {
this.frameParts.remove(EnumAnimationPart.valueOf(partName));
} catch (IllegalArgumentException ignored) {}
return this;
}
public IFrame addPart(IFramePart partConfig) {
this.frameParts.put(((FramePart)partConfig).getPart(),(FramePart) partConfig);
return this;
}
public IFrame removePart(int partId) {
for (EnumAnimationPart part : EnumAnimationPart.values()) {
this.frameParts.remove(part);
}
return this;
}
public IFrame removePart(String partName) {
try {
this.frameParts.remove(EnumAnimationPart.valueOf(partName));
} catch (IllegalArgumentException ignored) {}
return this;
}
public IFrame clearParts() {
frameParts.clear();
return this;
}
public IFrame removePart(int partId) {
for (EnumAnimationPart part : EnumAnimationPart.values()) {
this.frameParts.remove(part);
}
return this;
}
public int getDuration() {
return duration;
}
public IFrame clearParts() {
frameParts.clear();
return this;
}
public IFrame setDuration(int duration) {
this.duration = duration;
return this;
}
public int getDuration() {
return duration;
}
public boolean isCustomized() {
return customized;
}
public IFrame setDuration(int duration) {
this.duration = duration;
return this;
}
public IFrame setCustomized(boolean customized) {
this.customized = customized;
return this;
}
public int tickDuration() {
return !this.customized && this.parent != null ? this.parent.tickDuration : this.tickDuration;
}
public float getSpeed() {
return speed;
}
public IFrame setTickDuration(int tickDuration) {
this.tickDuration = tickDuration;
return this;
}
public IFrame setSpeed(float speed) {
this.speed = speed;
return this;
}
public boolean isCustomized() {
return customized;
}
public byte smoothType() {
return smooth;
}
public IFrame setCustomized(boolean customized) {
this.customized = customized;
return this;
}
public IFrame setSmooth(byte smooth) {
this.smooth = smooth;
return this;
}
public float getSpeed() {
return speed;
}
public IFrame useRenderTicks(boolean renderTicks) {
this.renderTicks = renderTicks;
return this;
}
public IFrame setSpeed(float speed) {
this.speed = speed;
return this;
}
public boolean useRenderTicks() {
return this.renderTicks;
}
public byte smoothType() {
return smooth;
}
public int getColorMarker() {
return this.colorMarker;
}
public IFrame setSmooth(byte smooth) {
this.smooth = smooth;
return this;
}
public void setColorMarker(int color) {
this.colorMarker = color;
}
public int getColorMarker() {
return this.colorMarker;
}
public void readFromNBT(NBTTagCompound compound){
duration = compound.getInteger("Duration");
if (compound.hasKey("ColorMarker")) {
this.setColorMarker(compound.getInteger("ColorMarker"));
}
public void setColorMarker(int color) {
this.colorMarker = color;
}
// Customized = TRUE if Speed or Smooth Exist
if(compound.hasKey("Speed")){
customized = true;
speed = compound.getFloat("Speed");
}
if(compound.hasKey("Smooth")){
customized = true;
smooth = compound.getByte("Smooth");
}
if(compound.hasKey("RenderTicks")){
customized = true;
renderTicks = compound.getBoolean("RenderTicks");
}
public String getComment() {
return this.comment;
}
if (!customized) {
this.speed = parent.speed;
this.smooth = parent.smooth;
this.renderTicks = parent.renderTicks;
}
public void setComment(String comment) {
this.comment = comment;
}
HashMap<EnumAnimationPart,FramePart> frameParts = new HashMap<>();
NBTTagList list = compound.getTagList("FrameParts", 10);
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound item = list.getCompoundTagAt(i);
FramePart framePart = new FramePart();
framePart.readFromNBT(item);
if (!framePart.customized) {
framePart.smooth = this.smooth;
framePart.speed = this.speed;
}
frameParts.put(framePart.part,framePart);
}
this.frameParts = frameParts;
}
public void readFromNBT(NBTTagCompound compound){
duration = compound.getInteger("Duration");
if (compound.hasKey("ColorMarker")) {
this.setColorMarker(compound.getInteger("ColorMarker"));
}
if (compound.hasKey("Comment")) {
this.comment = compound.getString("Comment");
}
public NBTTagCompound writeToNBT(){
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("Duration", duration);
compound.setInteger("ColorMarker", this.colorMarker);
// Customized = TRUE if Speed or Smooth Exist
if(compound.hasKey("Speed")){
customized = true;
speed = compound.getFloat("Speed");
}
if(compound.hasKey("Smooth")){
customized = true;
smooth = compound.getByte("Smooth");
}
if(customized){
compound.setFloat("Speed", speed);
compound.setByte("Smooth", smooth);
compound.setBoolean("RenderTicks", renderTicks);
}
if (compound.hasKey("TickDuration")) {
customized = true;
this.tickDuration = compound.getInteger("TickDuration");
} else if(compound.hasKey("RenderTicks")){
customized = true;
this.tickDuration = compound.getBoolean("RenderTicks") ? 20 : 50;
}
NBTTagList list = new NBTTagList();
for(FramePart framePart : frameParts.values()){
NBTTagCompound item = framePart.writeToNBT();
list.appendTag(item);
}
compound.setTag("FrameParts", list);
return compound;
}
if (!customized && parent != null) {
this.speed = parent.speed;
this.smooth = parent.smooth;
this.tickDuration = parent.tickDuration;
}
public Frame copy() {
Frame frame = new Frame(this.duration);
HashMap<EnumAnimationPart,FramePart> frameParts = this.frameParts;
for (Map.Entry<EnumAnimationPart,FramePart> entry : frameParts.entrySet()) {
frame.frameParts.put(entry.getKey(),entry.getValue().copy());
}
frame.parent = this.parent;
frame.duration = this.duration;
frame.customized = this.customized;
frame.speed = this.speed;
frame.smooth = this.smooth;
frame.renderTicks = this.renderTicks;
frame.colorMarker = this.colorMarker;
return frame;
}
HashMap<EnumAnimationPart,FramePart> frameParts = new HashMap<>();
NBTTagList list = compound.getTagList("FrameParts", 10);
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound item = list.getCompoundTagAt(i);
FramePart framePart = new FramePart();
framePart.readFromNBT(item);
if (!framePart.customized) {
framePart.smooth = this.smooth;
framePart.speed = this.speed;
}
frameParts.put(framePart.part,framePart);
}
this.frameParts = frameParts;
}
public NBTTagCompound writeToNBT(){
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("Duration", duration);
compound.setInteger("ColorMarker", this.colorMarker);
compound.setString("Comment", this.comment);
if(customized){
compound.setFloat("Speed", speed);
compound.setByte("Smooth", smooth);
compound.setInteger("TickDuration", tickDuration);
}
NBTTagList list = new NBTTagList();
for(FramePart framePart : frameParts.values()){
NBTTagCompound item = framePart.writeToNBT();
list.appendTag(item);
}
compound.setTag("FrameParts", list);
return compound;
}
public Frame copy() {
Frame frame = new Frame(this.duration);
HashMap<EnumAnimationPart,FramePart> frameParts = this.frameParts;
for (Map.Entry<EnumAnimationPart,FramePart> entry : frameParts.entrySet()) {
frame.frameParts.put(entry.getKey(),entry.getValue().copy());
}
frame.parent = this.parent;
frame.duration = this.duration;
frame.customized = this.customized;
frame.speed = this.speed;
frame.smooth = this.smooth;
frame.tickDuration = this.tickDuration;
frame.colorMarker = this.colorMarker;
return frame;
}
}
@@ -97,7 +97,7 @@ public class PlayerDataScript implements INpcScriptHandler {
}
public boolean isClient() {
return this.player.isClientWorld();
return this.player != null && this.player.isClientWorld();
}
public boolean getEnabled() {
return ScriptController.Instance.playerScripts.enabled;