mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 23:25:07 +00:00
Animation overhaul, along with animation changes to the API.
This commit is contained in:
1 parent
bda76bafe6
commit
be18e756fc
23 files changed
+648
-1229
No files matched your search
@@ -2,67 +2,169 @@ package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.api.handler.data.IAnimation;
|
||||
import noppes.npcs.api.handler.data.IFrame;
|
||||
import noppes.npcs.constants.EnumAnimationPart;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class Animation {
|
||||
public class Animation implements IAnimation {
|
||||
|
||||
public ArrayList<Frame> frames = new ArrayList<Frame>();
|
||||
public int currentFrame = 0;
|
||||
public int currentFrameTime = 0;
|
||||
|
||||
public int id = 0;
|
||||
public String name;
|
||||
public float speed = 1.0F;
|
||||
public boolean smooth = false;
|
||||
public byte smooth = 0;
|
||||
public boolean renderTicks = false; // If true, MC ticks are used. If false, render ticks are used.
|
||||
|
||||
public boolean whileStanding = true;
|
||||
public boolean whileAttacking = true;
|
||||
public boolean whileMoving = true;
|
||||
|
||||
public Animation(){}
|
||||
|
||||
public Animation(ArrayList<Frame> parts, String name){
|
||||
this.frames = parts;
|
||||
public Animation(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Animation(ArrayList<Frame> parts, String name, float speed, boolean smooth){
|
||||
this.frames = parts;
|
||||
public Animation(String name, float speed, byte smooth){
|
||||
this.name = name;
|
||||
this.speed = speed;
|
||||
this.smooth = smooth;
|
||||
}
|
||||
|
||||
public ArrayList<Frame> getFrames() {
|
||||
return frames;
|
||||
public IFrame currentFrame() {
|
||||
return currentFrame < frames.size() ? frames.get(currentFrame) : null;
|
||||
}
|
||||
|
||||
public IFrame[] getFrames() {
|
||||
return frames.toArray(new Frame[0]);
|
||||
}
|
||||
|
||||
public IAnimation setFrames(IFrame[] frames) {
|
||||
this.clearFrames();
|
||||
for (IFrame frame : frames) {
|
||||
this.frames.add((Frame) frame);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAnimation clearFrames() {
|
||||
this.frames.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAnimation addFrame(IFrame frame) {
|
||||
this.frames.add((Frame) frame);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAnimation addFrame(int index, IFrame frame) {
|
||||
this.frames.add(index, (Frame) frame);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAnimation removeFrame(IFrame frame) {
|
||||
this.frames.remove((Frame) frame);
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public IAnimation setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public IAnimation setSpeed(float speed) {
|
||||
this.speed = speed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getSpeed() {
|
||||
return speed;
|
||||
return this.speed;
|
||||
}
|
||||
|
||||
public boolean isSmooth() {
|
||||
return smooth;
|
||||
public IAnimation setSmooth(byte smooth) {
|
||||
this.smooth = smooth;
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte isSmooth() {
|
||||
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;
|
||||
}
|
||||
|
||||
public boolean doWhileStanding() {
|
||||
return this.whileStanding;
|
||||
}
|
||||
|
||||
public IAnimation doWhileMoving(boolean whileMoving) {
|
||||
this.whileMoving = whileMoving;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean doWhileMoving() {
|
||||
return this.whileMoving;
|
||||
}
|
||||
|
||||
public IAnimation doWhileAttacking(boolean whileAttacking) {
|
||||
this.whileAttacking = whileAttacking;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean doWhileAttacking() {
|
||||
return this.whileAttacking;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound){
|
||||
name = compound.getString("Name");
|
||||
id = compound.getInteger("ID");
|
||||
speed = compound.getFloat("Speed");
|
||||
smooth = compound.getBoolean("Smooth");
|
||||
smooth = compound.getByte("Smooth");
|
||||
|
||||
renderTicks = compound.getBoolean("RenderTicks");
|
||||
currentFrame = compound.getInteger("CurrentFrame");
|
||||
|
||||
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;
|
||||
|
||||
this.whileStanding = compound.getBoolean("WhileStanding");
|
||||
this.whileMoving = compound.getBoolean("WhileWalking");
|
||||
this.whileAttacking = compound.getBoolean("WhileAttacking");
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(){
|
||||
@@ -70,7 +172,10 @@ public class Animation {
|
||||
compound.setString("Name", name);
|
||||
compound.setInteger("ID", id);
|
||||
compound.setFloat("Speed", speed);
|
||||
compound.setBoolean("Smooth", smooth);
|
||||
compound.setByte("Smooth", smooth);
|
||||
|
||||
compound.setBoolean("RenderTicks", renderTicks);
|
||||
compound.setInteger("CurrentFrame", currentFrame);
|
||||
|
||||
NBTTagList list = new NBTTagList();
|
||||
for(Frame frame : frames){
|
||||
@@ -78,7 +183,28 @@ public class Animation {
|
||||
list.appendTag(item);
|
||||
}
|
||||
compound.setTag("Frames", list);
|
||||
|
||||
compound.setBoolean("WhileStanding", whileStanding);
|
||||
compound.setBoolean("WhileWalking", whileMoving);
|
||||
compound.setBoolean("WhileAttacking", whileAttacking);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void increaseTime() {
|
||||
this.currentFrameTime++;
|
||||
if (this.currentFrameTime == this.currentFrame().getDuration()) {
|
||||
Frame prevFrame = (Frame) this.currentFrame();
|
||||
this.currentFrameTime = 0;
|
||||
this.currentFrame++;
|
||||
if (this.currentFrame < this.frames.size()) {
|
||||
Frame nextFrame = this.frames.get(this.currentFrame);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user