diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java b/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java index 32bb05b3..45ed4df1 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java @@ -6,6 +6,7 @@ import java.util.List; import com.minelittlepony.unicopia.ability.Abilities; import com.minelittlepony.unicopia.ability.AbilityDispatcher; import com.minelittlepony.unicopia.ability.AbilitySlot; +import com.minelittlepony.unicopia.entity.player.MagicReserves; import com.minelittlepony.unicopia.entity.player.MagicReserves.Bar; import com.minelittlepony.unicopia.entity.player.Pony; import com.mojang.blaze3d.systems.RenderSystem; @@ -89,37 +90,47 @@ public class UHud extends DrawableHelper { } void renderManaRings(MatrixStack matrices) { - matrices.push(); matrices.translate(24.5, 25.5, 0); - Bar mana = Pony.of(client.player).getMagicalReserves().getMana(); - Bar exer = Pony.of(client.player).getMagicalReserves().getEnergy(); + MagicReserves mana = Pony.of(client.player).getMagicalReserves(); - renderRing(matrices, 17, 13, MathHelper.lerp(client.getTickDelta(), mana.getPrev(), mana.get()) / mana.getMax(), 0xFF88FF99); - renderRing(matrices, 17, 13, MathHelper.lerp(client.getTickDelta(), exer.getPrev(), exer.get()) / exer.getMax(), 0xFF002299); + double arcBegin = 0; + + arcBegin = renderRing(matrices, 17, 13, 0, mana.getMana(), 0xFF88FF99); + arcBegin = renderRing(matrices, 17, 13, arcBegin, mana.getEnergy(), 0xFF002299); matrices.pop(); } - static void renderRing(MatrixStack matrices, double outerRadius, double innerRadius, double maxAngle, int color) { + private double renderRing(MatrixStack matrices, double outerRadius, double innerRadius, double offsetAngle, Bar bar, int color) { + double fill = bar.getPercentFill() * Math.PI * 2; - float f = (color >> 24 & 255) / 255.0F; - float g = (color >> 16 & 255) / 255.0F; - float h = (color >> 8 & 255) / 255.0F; - float k = (color & 255) / 255.0F; + renderArc(matrices, innerRadius, outerRadius, offsetAngle, fill, color, false); + return offsetAngle + fill; + } + + /** + * Renders a colored arc. + * + * @param mirrorHorizontally Whether or not the arc must be mirrored across the horizontal plane. Will produce a bar that grows from the middle filling both sides. + */ + static void renderArc(MatrixStack matrices, double innerRadius, double outerRadius, double startAngle, double arcAngle, int color, boolean mirrorHorizontally) { + float f = (color >> 24 & 255) / 255F; + float g = (color >> 16 & 255) / 255F; + float h = (color >> 8 & 255) / 255F; + float k = (color & 255) / 255F; final double num_rings = 300; - double twoPi = Math.PI * 2; + final double twoPi = Math.PI * 2; final double increment = twoPi / num_rings; - maxAngle *= twoPi; - maxAngle = MathHelper.clamp(maxAngle, 0, twoPi - increment); - - if (maxAngle < increment) { + if (arcAngle < increment) { return; } + final double maxAngle = MathHelper.clamp(startAngle + arcAngle, 0, twoPi - increment); + BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer(); RenderSystem.enableBlend(); RenderSystem.disableTexture(); @@ -129,7 +140,11 @@ public class UHud extends DrawableHelper { Matrix4f model = matrices.peek().getModel(); - for (double angle = 0; angle >= -maxAngle; angle -= increment) { + if (!mirrorHorizontally) { + startAngle = -startAngle; + } + + for (double angle = startAngle; angle >= -maxAngle; angle -= increment) { // center bufferBuilder.vertex(model, (float)(innerRadius * Math.sin(angle)), diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/MagicReserves.java b/src/main/java/com/minelittlepony/unicopia/entity/player/MagicReserves.java index d28c5045..e07928e4 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/MagicReserves.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/MagicReserves.java @@ -27,12 +27,6 @@ public interface MagicReserves { */ float get(); - /** - * Gets the previous value from the last tick. - * Only updated when calling getPrev again. - */ - float getPrev(); - /** * Sets the absolute value */ @@ -62,8 +56,6 @@ public interface MagicReserves { /** * Get the maximum value this bar is allowed to contain */ - default float getMax() { - return 100F; - } + float getMax(); } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java b/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java index 7871753e..df744f1c 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java @@ -12,9 +12,9 @@ public class ManaContainer implements MagicReserves { public ManaContainer(Pony pony) { this.pony = pony; - this.energy = new BarInst(Pony.ENERGY); - this.exertion = new BarInst(Pony.EXERTION); - this.mana = new BarInst(Pony.MANA); + this.energy = new BarInst(Pony.ENERGY, 100F); + this.exertion = new BarInst(Pony.EXERTION, 10F); + this.mana = new BarInst(Pony.MANA, 100F); } @Override @@ -35,10 +35,11 @@ public class ManaContainer implements MagicReserves { class BarInst implements Bar { private final TrackedData marker; - private float prev; + private final float max; - BarInst(TrackedData marker) { + BarInst(TrackedData marker, float max) { this.marker = marker; + this.max = max; pony.getOwner().getDataTracker().startTracking(marker, 0F); } @@ -47,16 +48,14 @@ public class ManaContainer implements MagicReserves { return pony.getOwner().getDataTracker().get(marker); } - @Override - public float getPrev() { - float value = prev; - prev = get(); - return value; - } - @Override public void set(float value) { pony.getOwner().getDataTracker().set(marker, MathHelper.clamp(value, 0, getMax())); } + + @Override + public float getMax() { + return max; + } } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java index ba13e6a9..39153083 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -109,11 +109,11 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti if (ticksInAir > 100) { Bar mana = pony.getMagicalReserves().getMana(); - mana.add((int)(-getHorizontalMotion(entity) * 100)); + mana.add((int)(-getHorizontalMotion(entity) * 50)); if (mana.getPercentFill() < 0.2) { pony.getMagicalReserves().getExertion().add(2); - pony.getMagicalReserves().getEnergy().add(2); + pony.getMagicalReserves().getEnergy().add(2 + (int)(getHorizontalMotion(entity) * 5)); if (mana.getPercentFill() < 0.1 && ticksInAir % 10 == 0) { float exhaustion = (0.3F * ticksInAir) / 70;