2023-01-12 19:32:40 -05:00
|
|
|
package noppes.npcs.controllers.data;
|
|
|
|
|
|
2023-01-16 13:53:15 -06:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2023-01-12 20:34:07 -05:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2023-01-16 13:53:15 -06:00
|
|
|
import noppes.npcs.api.handler.data.IFramePart;
|
|
|
|
|
import noppes.npcs.client.ClientEventHandler;
|
2023-01-12 19:32:40 -05:00
|
|
|
import noppes.npcs.constants.EnumAnimationPart;
|
|
|
|
|
|
2023-01-16 13:53:15 -06:00
|
|
|
public class FramePart implements IFramePart {
|
2023-02-06 23:17:05 -06:00
|
|
|
public Animation parent;
|
2023-01-12 19:32:40 -05:00
|
|
|
public EnumAnimationPart part;
|
2023-01-17 13:08:10 -06:00
|
|
|
public float[] rotation = {0, 0, 0};
|
|
|
|
|
public float[] pivot = {0, 0, 0};
|
2023-01-12 19:32:40 -05:00
|
|
|
|
|
|
|
|
boolean customized = false;
|
|
|
|
|
|
|
|
|
|
public float speed = 1.0F;
|
2023-01-16 13:53:15 -06:00
|
|
|
//0 - Interpolated, 1 - Linear, 2 - None
|
|
|
|
|
public byte smooth = 0;
|
|
|
|
|
|
|
|
|
|
//Client-sided fields (unsaved)
|
2023-02-19 13:46:37 -06:00
|
|
|
public float[] prevRotations = {0,0,0};
|
2023-01-16 13:53:15 -06:00
|
|
|
public float[] prevPivots = {0,0,0};
|
|
|
|
|
public float partialRotationTick;
|
|
|
|
|
public float partialPivotTick;
|
2023-01-12 20:34:07 -05:00
|
|
|
|
2023-01-12 19:40:06 -05:00
|
|
|
public FramePart(){}
|
2023-01-12 19:32:40 -05:00
|
|
|
|
|
|
|
|
public FramePart(EnumAnimationPart part){
|
|
|
|
|
this.part = part;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 13:53:15 -06:00
|
|
|
public EnumAnimationPart getPart() {
|
|
|
|
|
return part;
|
2023-01-12 19:32:40 -05:00
|
|
|
}
|
|
|
|
|
|
2023-01-16 13:53:15 -06:00
|
|
|
public String getName() {
|
|
|
|
|
return part.name();
|
2023-01-12 19:32:40 -05:00
|
|
|
}
|
|
|
|
|
|
2023-01-16 13:53:15 -06:00
|
|
|
public int getPartId() {
|
|
|
|
|
return part.id;
|
2023-01-12 19:32:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setPart(EnumAnimationPart part) {
|
|
|
|
|
this.part = part;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 13:53:15 -06:00
|
|
|
public IFramePart setPart(String name) {
|
|
|
|
|
try {
|
|
|
|
|
this.setPart(EnumAnimationPart.valueOf(name));
|
|
|
|
|
} catch (IllegalArgumentException ignored) {}
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IFramePart setPart(int partId) {
|
|
|
|
|
for (EnumAnimationPart enumPart : EnumAnimationPart.values()) {
|
|
|
|
|
if (enumPart.id == partId) {
|
|
|
|
|
this.setPart(enumPart);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-17 13:08:10 -06:00
|
|
|
public float[] getRotations() {
|
2023-01-12 19:32:40 -05:00
|
|
|
return rotation;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-17 13:08:10 -06:00
|
|
|
public IFramePart setRotations(float[] rotation) {
|
2023-01-12 19:32:40 -05:00
|
|
|
this.rotation = rotation;
|
2023-01-16 13:53:15 -06:00
|
|
|
return this;
|
2023-01-12 19:32:40 -05:00
|
|
|
}
|
|
|
|
|
|
2023-01-17 13:08:10 -06:00
|
|
|
public float[] getPivots() {
|
2023-01-12 19:32:40 -05:00
|
|
|
return pivot;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-17 13:08:10 -06:00
|
|
|
public IFramePart setPivots(float[] pivot) {
|
2023-01-12 19:32:40 -05:00
|
|
|
this.pivot = pivot;
|
2023-01-16 13:53:15 -06:00
|
|
|
return this;
|
2023-01-12 19:32:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isCustomized() {
|
|
|
|
|
return customized;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 13:53:15 -06:00
|
|
|
public IFramePart setCustomized(boolean customized) {
|
2023-01-12 19:32:40 -05:00
|
|
|
this.customized = customized;
|
2023-01-16 13:53:15 -06:00
|
|
|
return this;
|
2023-01-12 19:32:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float getSpeed() {
|
|
|
|
|
return speed;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 13:53:15 -06:00
|
|
|
public IFramePart setSpeed(float speed) {
|
2023-01-12 19:32:40 -05:00
|
|
|
this.speed = speed;
|
2023-01-16 13:53:15 -06:00
|
|
|
return this;
|
2023-01-12 19:32:40 -05:00
|
|
|
}
|
|
|
|
|
|
2023-01-16 13:53:15 -06:00
|
|
|
public byte isSmooth() {
|
2023-01-12 19:32:40 -05:00
|
|
|
return smooth;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 13:53:15 -06:00
|
|
|
public IFramePart setSmooth(byte smooth) {
|
2023-01-12 19:32:40 -05:00
|
|
|
this.smooth = smooth;
|
2023-01-16 13:53:15 -06:00
|
|
|
return this;
|
2023-01-12 19:32:40 -05:00
|
|
|
}
|
|
|
|
|
|
2023-01-12 20:34:07 -05:00
|
|
|
public void readFromNBT(NBTTagCompound compound){
|
|
|
|
|
part = EnumAnimationPart.valueOf(compound.getString("Part"));
|
2023-01-17 13:08:10 -06:00
|
|
|
for (int i = 0; i < 3; i++) {
|
2023-01-17 14:08:19 -06:00
|
|
|
rotation[i] = compound.getFloat("Rotation" + i);
|
2023-01-17 13:08:10 -06:00
|
|
|
}
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
2023-01-17 14:08:19 -06:00
|
|
|
pivot[i] = compound.getFloat("Pivot" + i);
|
2023-01-17 13:08:10 -06:00
|
|
|
}
|
2023-01-12 20:34:07 -05:00
|
|
|
|
|
|
|
|
// Customized = TRUE if Speed or Smooth Exist
|
|
|
|
|
if(compound.hasKey("Speed")){
|
|
|
|
|
customized = true;
|
|
|
|
|
speed = compound.getFloat("Speed");
|
|
|
|
|
}
|
|
|
|
|
if(compound.hasKey("Smooth")){
|
|
|
|
|
customized = true;
|
2023-01-16 13:53:15 -06:00
|
|
|
smooth = compound.getByte("Smooth");
|
2023-01-12 20:34:07 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NBTTagCompound writeToNBT(){
|
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
|
compound.setString("Part", part.toString());
|
2023-01-17 13:08:10 -06:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
compound.setFloat("Rotation" + i, rotation[i]);
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
2023-01-17 14:08:19 -06:00
|
|
|
compound.setFloat("Pivot" + i, pivot[i]);
|
2023-01-17 13:08:10 -06:00
|
|
|
}
|
2023-01-12 21:33:06 -05:00
|
|
|
|
2023-01-12 20:34:07 -05:00
|
|
|
if(customized){
|
|
|
|
|
compound.setFloat("Speed", speed);
|
2023-01-16 13:53:15 -06:00
|
|
|
compound.setByte("Smooth", smooth);
|
2023-01-12 20:34:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
2023-01-16 13:53:15 -06:00
|
|
|
|
2023-02-19 13:46:37 -06:00
|
|
|
public FramePart copy() {
|
|
|
|
|
FramePart part = new FramePart(this.part);
|
|
|
|
|
part.rotation = new float[]{this.rotation[0],this.rotation[1],this.rotation[2]};
|
|
|
|
|
part.pivot = new float[]{this.pivot[0],this.pivot[1],this.pivot[2]};
|
|
|
|
|
part.customized = this.customized;
|
|
|
|
|
part.speed = this.speed;
|
|
|
|
|
part.smooth = this.smooth;
|
|
|
|
|
return part;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 13:53:15 -06:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public void interpolateAngles() {
|
2023-02-06 23:17:05 -06:00
|
|
|
if (parent != null && parent.paused)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-01-16 13:53:15 -06:00
|
|
|
float pi = (float) Math.PI / 180;
|
|
|
|
|
if (this.smooth == 2) {
|
|
|
|
|
this.prevRotations[0] = this.rotation[0] * pi;
|
|
|
|
|
this.prevRotations[1] = this.rotation[1] * pi;
|
|
|
|
|
this.prevRotations[2] = this.rotation[2] * pi;
|
|
|
|
|
} else if (this.partialRotationTick != ClientEventHandler.partialRenderTick) {
|
|
|
|
|
this.partialRotationTick = ClientEventHandler.partialRenderTick;
|
|
|
|
|
if (this.smooth == 0) {
|
|
|
|
|
this.prevRotations[0] = (this.rotation[0] * pi - this.prevRotations[0]) * Math.abs(this.speed) / 10f + this.prevRotations[0];
|
|
|
|
|
this.prevRotations[1] = (this.rotation[1] * pi - this.prevRotations[1]) * Math.abs(this.speed) / 10f + this.prevRotations[1];
|
|
|
|
|
this.prevRotations[2] = (this.rotation[2] * pi - this.prevRotations[2]) * Math.abs(this.speed) / 10f + this.prevRotations[2];
|
|
|
|
|
} else {
|
|
|
|
|
int directionX = Float.compare(this.rotation[0] * pi, this.prevRotations[0]);
|
|
|
|
|
this.prevRotations[0] += directionX * this.speed / 10f;
|
|
|
|
|
this.prevRotations[0] = directionX == 1 ?
|
|
|
|
|
Math.min(this.rotation[0] * pi, this.prevRotations[0]) : Math.max(this.rotation[0] * pi, this.prevRotations[0]);
|
|
|
|
|
int directionY = Float.compare(this.rotation[1] * pi, this.prevRotations[1]);
|
|
|
|
|
this.prevRotations[1] += directionY * this.speed / 10f;
|
|
|
|
|
this.prevRotations[1] = directionY == 1 ?
|
|
|
|
|
Math.min(this.rotation[1] * pi, this.prevRotations[1]) : Math.max(this.rotation[1] * pi, this.prevRotations[1]);
|
|
|
|
|
int directionZ = Float.compare(this.rotation[2] * pi, this.prevRotations[2]);
|
|
|
|
|
this.prevRotations[2] += directionZ * this.speed / 10f;
|
|
|
|
|
this.prevRotations[2] = directionZ == 1 ?
|
|
|
|
|
Math.min(this.rotation[2] * pi, this.prevRotations[2]) : Math.max(this.rotation[2] * pi, this.prevRotations[2]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public void interpolateOffset() {
|
2023-02-06 23:17:05 -06:00
|
|
|
if (parent != null && parent.paused)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-01-16 13:53:15 -06:00
|
|
|
if (this.smooth == 2) {
|
|
|
|
|
this.prevPivots[0] = this.pivot[0];
|
|
|
|
|
this.prevPivots[1] = this.pivot[1];
|
|
|
|
|
this.prevPivots[2] = this.pivot[2];
|
|
|
|
|
} else if (this.partialPivotTick != ClientEventHandler.partialRenderTick) {
|
|
|
|
|
this.partialPivotTick = ClientEventHandler.partialRenderTick;
|
|
|
|
|
if (this.smooth == 0) {
|
|
|
|
|
this.prevPivots[0] = (this.pivot[0] - this.prevPivots[0]) * Math.abs(this.speed) / 10f + this.prevPivots[0];
|
|
|
|
|
this.prevPivots[1] = (this.pivot[1] - this.prevPivots[1]) * Math.abs(this.speed) / 10f + this.prevPivots[1];
|
|
|
|
|
this.prevPivots[2] = (this.pivot[2] - this.prevPivots[2]) * Math.abs(this.speed) / 10f + this.prevPivots[2];
|
|
|
|
|
} else {
|
|
|
|
|
int directionX = Float.compare(this.pivot[0], this.prevPivots[0]);
|
|
|
|
|
this.prevPivots[0] += directionX * this.speed / 10f;
|
|
|
|
|
this.prevPivots[0] = directionX == 1 ?
|
|
|
|
|
Math.min(this.pivot[0],this.prevPivots[0]) : Math.max(this.pivot[0],this.prevPivots[0]);
|
|
|
|
|
int directionY = Float.compare(this.pivot[1], this.prevPivots[1]);
|
|
|
|
|
this.prevPivots[1] += directionY * this.speed / 10f;
|
|
|
|
|
this.prevPivots[1] = directionY == 1 ?
|
|
|
|
|
Math.min(this.pivot[1],this.prevPivots[1]) : Math.max(this.pivot[1],this.prevPivots[1]);
|
|
|
|
|
int directionZ = Float.compare(this.pivot[2], this.prevPivots[2]);
|
|
|
|
|
this.prevPivots[2] += directionZ * this.speed / 10f;
|
|
|
|
|
this.prevPivots[2] = directionZ == 1 ?
|
|
|
|
|
Math.min(this.pivot[2],this.prevPivots[2]) : Math.max(this.pivot[2],this.prevPivots[2]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-12 19:32:40 -05:00
|
|
|
}
|