Removed "render ticks" tick type. Instead, animations and frames can define a tick speed measured in milliseconds. Animations/frames using MC tick type will be 50ms (1000ms/20), and render ticks 20ms.

This commit is contained in:
luisc committed 2024-03-23 23:34:01 -05:00
1 parent de909472b3
commit 799631eece
11 files changed
+97 -95

No files matched your search

@@ -24,7 +24,7 @@ public class Animation implements IAnimation {
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 int tickDuration = 50;
public boolean whileStanding = true;
public boolean whileAttacking = true;
@@ -93,6 +93,15 @@ public class Animation implements IAnimation {
return this.name;
}
public int tickDuration() {
return this.tickDuration;
}
public IAnimation setTickDuration(int tickDuration) {
this.tickDuration = tickDuration;
return this;
}
public IAnimation setSpeed(float speed) {
this.speed = speed;
return this;
@@ -111,15 +120,6 @@ public class Animation implements IAnimation {
return this.smooth;
}
public IAnimation useRenderTicks(boolean renderTicks) {
this.renderTicks = renderTicks;
return this;
}
public boolean useRenderTicks() {
return this.renderTicks;
}
public IAnimation doWhileStanding(boolean whileStanding) {
this.whileStanding = whileStanding;
return this;
@@ -183,8 +183,6 @@ public class Animation implements IAnimation {
smooth = compound.getByte("Smooth");
loop = compound.getInteger("Loop");
renderTicks = compound.getBoolean("RenderTicks");
ArrayList<Frame> frames = new ArrayList<Frame>();
NBTTagList list = compound.getTagList("Frames", 10);
for (int i = 0; i < list.tagCount(); i++) {
@@ -209,8 +207,6 @@ public class Animation implements IAnimation {
compound.setByte("Smooth", smooth);
compound.setInteger("Loop",loop);
compound.setBoolean("RenderTicks", renderTicks);
NBTTagList list = new NBTTagList();
for(Frame frame : frames){
NBTTagCompound item = frame.writeToNBT();
@@ -3,6 +3,7 @@ package noppes.npcs.controllers.data;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
@@ -12,6 +13,7 @@ import noppes.npcs.DataDisplay;
import noppes.npcs.Server;
import noppes.npcs.api.handler.data.IAnimation;
import noppes.npcs.api.handler.data.IAnimationData;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.constants.EnumAnimationPart;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.controllers.PlayerDataController;
@@ -154,27 +156,33 @@ public class AnimationData implements IAnimationData {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
this.animation = (Animation) animation;
} else {
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];
}
this.clientSetAnimation(animation);
}
}
@SideOnly(Side.CLIENT)
private void clientSetAnimation(IAnimation animation) {
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];
}
}
}
}
this.animation = newAnim;
newAnim.parent = this;
}
this.animation = newAnim;
newAnim.parent = this;
ClientCacheHandler.playingAnimations.add(newAnim);
}
public IAnimation getAnimation() {
@@ -14,10 +14,11 @@ public class Frame implements IFrame {
public Animation parent;
public HashMap<EnumAnimationPart,FramePart> frameParts = new HashMap<>();
public int duration = 0;
public int tickDuration = 50;
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.
private int colorMarker = 0xFFFFFF;
@@ -75,6 +76,15 @@ public class Frame implements IFrame {
return this;
}
public int tickDuration() {
return this.tickDuration;
}
public IFrame setTickDuration(int tickDuration) {
this.tickDuration = tickDuration;
return this;
}
public boolean isCustomized() {
return customized;
}
@@ -102,15 +112,6 @@ public class Frame implements IFrame {
return this;
}
public IFrame useRenderTicks(boolean renderTicks) {
this.renderTicks = renderTicks;
return this;
}
public boolean useRenderTicks() {
return this.renderTicks;
}
public int getColorMarker() {
return this.colorMarker;
}
@@ -136,13 +137,13 @@ public class Frame implements IFrame {
}
if(compound.hasKey("RenderTicks")){
customized = true;
renderTicks = compound.getBoolean("RenderTicks");
this.tickDuration = 20;
}
if (!customized) {
this.speed = parent.speed;
this.smooth = parent.smooth;
this.renderTicks = parent.renderTicks;
this.tickDuration = parent.tickDuration;
}
HashMap<EnumAnimationPart,FramePart> frameParts = new HashMap<>();
@@ -168,7 +169,7 @@ public class Frame implements IFrame {
if(customized){
compound.setFloat("Speed", speed);
compound.setByte("Smooth", smooth);
compound.setBoolean("RenderTicks", renderTicks);
compound.setInteger("TickDuration", tickDuration);
}
NBTTagList list = new NBTTagList();
@@ -191,7 +192,7 @@ public class Frame implements IFrame {
frame.customized = this.customized;
frame.speed = this.speed;
frame.smooth = this.smooth;
frame.renderTicks = this.renderTicks;
frame.tickDuration = this.tickDuration;
frame.colorMarker = this.colorMarker;
return frame;
}