feat: implement frame time option for cosmetics

This commit is contained in:
LordMZTE 2023-11-24 21:47:15 +01:00
parent e6ff1536e2
commit b8cb282a62
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
4 changed files with 21 additions and 1 deletions

View file

@ -112,7 +112,7 @@ public class CosmeticArmorRenderer extends BipedEntityModel<PlayerEntity>
poseStack.translate(0, 24 / 16F, 0);
poseStack.scale(-1, -1, 1);
double currentTick = entityLiving.age; // TODO: Custom frametime/animation speed
double currentTick = entityLiving.age / this.getCurrentCosmetic().getFrameTime();
currentFrame
= ((int) (currentTick * 1.0F)) % this.getCurrentCosmetic().getTotalFrames();
;

View file

@ -46,4 +46,11 @@ public interface ICosmetic {
default int getTotalFrames() {
return 1;
}
/**
* Returns how many ticks a frame of the animation should take.
*/
default int getFrameTime() {
return 1;
}
}

View file

@ -19,6 +19,7 @@ public class RemoteCosmetic implements ICosmetic {
private Identifier animationsLocation;
private CosmeticParts parts = new CosmeticParts();
private String idleAnimation = null;
private int frameTime = 1;
private int frameCount = 1;
public RemoteCosmetic(String id) {
@ -61,6 +62,7 @@ public class RemoteCosmetic implements ICosmetic {
public void loadTexture(TextureData data) {
this.frameCount = data.frameCount;
this.frameTime = data.frameTime;
this.loadedTexture = true;
}
@ -113,4 +115,9 @@ public class RemoteCosmetic implements ICosmetic {
public int getTotalFrames() {
return this.frameCount;
}
@Override
public int getFrameTime() {
return this.frameTime;
}
}

View file

@ -6,7 +6,13 @@ import com.google.gson.annotations.SerializedName;
public class TextureData {
@Expose
public String url;
@Expose
@SerializedName("total_frames")
public int frameCount;
@Expose
@SerializedName("frame_time")
public int frameTime;
}