Add some lerping to the various mana bars

This commit is contained in:
Sollace 2023-08-16 15:57:21 +01:00
parent 8331906d61
commit 5f8dfe14e9
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
4 changed files with 37 additions and 12 deletions

View file

@ -65,8 +65,8 @@ class ManaRingSlot extends Slot {
} }
private double renderRing(MatrixStack matrices, double outerRadius, double innerRadius, double offsetAngle, Bar bar, int color, float tickDelta) { private double renderRing(MatrixStack matrices, double outerRadius, double innerRadius, double offsetAngle, Bar bar, int color, float tickDelta) {
double fill = bar.getPercentFill() * DrawableUtil.TAU; double fill = bar.getPercentFill(tickDelta) * DrawableUtil.TAU;
double shadow = bar.getShadowFill() * DrawableUtil.TAU; double shadow = bar.getShadowFill(tickDelta) * DrawableUtil.TAU;
DrawableUtil.drawArc(matrices, innerRadius, outerRadius, offsetAngle, fill, color, true); DrawableUtil.drawArc(matrices, innerRadius, outerRadius, offsetAngle, fill, color, true);

View file

@ -67,7 +67,8 @@ public class SpellbookProfilePageContent implements SpellbookChapterList.Content
int y = SpellbookScreen.TITLE_Y; int y = SpellbookScreen.TITLE_Y;
float delta = pony.asEntity().age + client.getTickDelta(); float tickDelta = client.getTickDelta();
float delta = pony.asEntity().age + tickDelta;
int currentLevel = pony.getLevel().get(); int currentLevel = pony.getLevel().get();
float currentScaledLevel = pony.getLevel().getScaled(1); float currentScaledLevel = pony.getLevel().getScaled(1);
float currentCorruption = pony.getCorruption().getScaled(1); float currentCorruption = pony.getCorruption().getScaled(1);
@ -100,8 +101,8 @@ public class SpellbookProfilePageContent implements SpellbookChapterList.Content
double growth = MathHelper.sin(delta / 9F) * 2; double growth = MathHelper.sin(delta / 9F) * 2;
double radius = 40 + growth; double radius = 40 + growth;
float xpPercentage = reserves.getXp().getPercentFill(); float xpPercentage = reserves.getXp().getPercentFill(tickDelta);
float manaPercentage = reserves.getMana().getPercentFill(); float manaPercentage = reserves.getMana().getPercentFill(tickDelta);
float alphaF = (MathHelper.sin(delta / 9F) + 1) / 2F; float alphaF = (MathHelper.sin(delta / 9F) + 1) / 2F;
int alpha = (int)(alphaF * 0x10) & 0xFF; int alpha = (int)(alphaF * 0x10) & 0xFF;

View file

@ -41,7 +41,14 @@ public interface MagicReserves {
/** /**
* Gets the current value of this bar * Gets the current value of this bar
*/ */
float get(); default float get() {
return get(1);
}
/**
* Gets the (lerped) value of this bar
*/
float get(float tickDelta);
/** /**
* Sets the absolute value * Sets the absolute value
@ -52,13 +59,20 @@ public interface MagicReserves {
* Gets the percentage fill of this bar * Gets the percentage fill of this bar
*/ */
default float getPercentFill() { default float getPercentFill() {
return get() / getMax(); return getPercentFill(1);
}
/**
* Gets the percentage fill of this bar
*/
default float getPercentFill(float tickDelta) {
return get(tickDelta) / getMax();
} }
/** /**
* Gets the shadow fill used for animating on the UI * Gets the shadow fill used for animating on the UI
*/ */
float getShadowFill(); float getShadowFill(float tickDelta);
/** /**
* Adds a percentage increment to this bar's current value * Adds a percentage increment to this bar's current value

View file

@ -102,8 +102,8 @@ class ManaContainer implements MagicReserves, Tickable, NbtSerialisable, Copyabl
} }
if (!pony.getSpecies().canFly() || !pony.getPhysics().isFlying()) { if (!pony.getSpecies().canFly() || !pony.getPhysics().isFlying()) {
if (mana.getPercentFill() < 1 && mana.getShadowFill() == mana.getPercentFill()) { if (mana.getPercentFill() < 1 && mana.getShadowFill(1) <= mana.getPercentFill(1)) {
mana.addPercent(MathHelper.clamp(1 + pony.getLevel().get(), 1, 50)); mana.addPercent(MathHelper.clamp(1 + pony.getLevel().get(), 1, 50) / 4F);
} }
} }
@ -157,6 +157,8 @@ class ManaContainer implements MagicReserves, Tickable, NbtSerialisable, Copyabl
private final float max; private final float max;
private float trailingValue; private float trailingValue;
private float prevTrailingValue;
private float prevValue;
BarInst(TrackedData<Float> marker, float max, float initial) { BarInst(TrackedData<Float> marker, float max, float initial) {
this.marker = marker; this.marker = marker;
@ -171,8 +173,13 @@ class ManaContainer implements MagicReserves, Tickable, NbtSerialisable, Copyabl
} }
@Override @Override
public float getShadowFill() { public float get(float tickDelta) {
return trailingValue; return MathHelper.lerp(tickDelta, prevValue, get());
}
@Override
public float getShadowFill(float tickDelta) {
return MathHelper.lerp(tickDelta, prevTrailingValue, trailingValue);
} }
@Override @Override
@ -203,6 +210,9 @@ class ManaContainer implements MagicReserves, Tickable, NbtSerialisable, Copyabl
} }
void tick() { void tick() {
prevValue = get();
prevTrailingValue = trailingValue;
float fill = getPercentFill(); float fill = getPercentFill();
float trailingIncrement = 0.003F; float trailingIncrement = 0.003F;