From ca787254f2d7c894660e9eb93e2cd7a6fe1ddf9e Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 18 Aug 2021 17:32:23 +0200 Subject: [PATCH] Added a separate stat for magical exhaustion --- .../ability/UnicornCastingAbility.java | 2 +- .../ability/UnicornProjectileAbility.java | 2 +- .../ability/magic/spell/JoustingSpell.java | 2 +- .../unicopia/client/gui/ManaRingSlot.java | 2 +- .../unicopia/client/gui/UHud.java | 73 ++++++++++++------- .../entity/effect/RaceChangeStatusEffect.java | 1 + .../unicopia/entity/player/MagicReserves.java | 5 ++ .../unicopia/entity/player/ManaContainer.java | 13 ++++ .../unicopia/entity/player/PlayerPhysics.java | 2 +- .../unicopia/entity/player/Pony.java | 1 + 10 files changed, 72 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java index 621b2c37..77ccfdbb 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java @@ -145,7 +145,7 @@ public class UnicornCastingAbility implements Ability { @Override public void preApply(Pony player, AbilitySlot slot) { - player.getMagicalReserves().getEnergy().multiply(3.3F); + player.getMagicalReserves().getExhaustion().multiply(3.3F); if (getAmulet(player).getResult() == ActionResult.CONSUME) { Vec3d eyes = player.getMaster().getCameraPosVec(1); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornProjectileAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornProjectileAbility.java index fcbc8702..54f6ebac 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornProjectileAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornProjectileAbility.java @@ -87,7 +87,7 @@ public class UnicornProjectileAbility implements Ability { @Override public void preApply(Pony player, AbilitySlot slot) { - player.getMagicalReserves().getEnergy().multiply(3.3F); + player.getMagicalReserves().getExhaustion().multiply(3.3F); player.spawnParticles(MagicParticleEffect.UNICORN, 5); } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/JoustingSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/JoustingSpell.java index d25d1084..0b7334ac 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/JoustingSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/JoustingSpell.java @@ -69,7 +69,7 @@ public class JoustingSpell extends AbstractSpell implements Attached { source.getEntity().setVelocity(velocity); if (source instanceof Pony) { - ((Pony)source).getMagicalReserves().getEnergy().multiply(0.2F); + ((Pony)source).getMagicalReserves().getExhaustion().multiply(0.2F); } return !source.getEntity().isRemoved() && age++ < 90 + 7 * (source.getLevel().get() + 1); diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/ManaRingSlot.java b/src/main/java/com/minelittlepony/unicopia/client/gui/ManaRingSlot.java index 803dae83..623a6046 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/ManaRingSlot.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/ManaRingSlot.java @@ -63,7 +63,7 @@ class ManaRingSlot extends Slot { } } - arcBegin = renderRing(matrices, 17, 13, arcBegin, mana.getEnergy(), 0xFF002299, tickDelta); + arcBegin = renderRing(matrices, 17, 13, arcBegin, mana.getExhaustion(), 0xFF002299, tickDelta); matrices.pop(); 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 b42ad56d..af966056 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java @@ -21,8 +21,10 @@ import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.gui.hud.InGameHud; import net.minecraft.client.gui.screen.ingame.InventoryScreen; +import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.EntityDimensions; +import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; import net.minecraft.util.Arm; import net.minecraft.util.Identifier; @@ -66,32 +68,7 @@ public class UHud extends DrawableHelper { Pony pony = Pony.of(client.player); - boolean hasEffect = client.player.hasStatusEffect(SunBlindnessStatusEffect.INSTANCE); - - if (hasEffect || (pony.getSpecies() == Race.BAT && SunBlindnessStatusEffect.hasSunExposure(client.player))) { - float i = hasEffect ? (client.player.getStatusEffect(SunBlindnessStatusEffect.INSTANCE).getDuration() - tickDelta) / SunBlindnessStatusEffect.MAX_DURATION : 0; - - float pulse = (1 + (float)Math.sin(client.player.age / 108F)) * 0.25F; - - float strength = MathHelper.clamp(pulse + i, 0.3F, 1F); - - int alpha1 = (int)(strength * 205) << 24 & -16777216; - int alpha2 = (int)(alpha1 * 0.6F); - - fillGradient(matrices, 0, 0, scaledWidth, scaledHeight / 2, 0xFFFFFF | alpha1, 0xFFFFFF | alpha2); - fillGradient(matrices, 0, scaledHeight / 2, scaledWidth, scaledHeight, 0xFFFFFF | alpha2, 0xFFFFFF | alpha1); - - if (hasEffect) { - matrices.push(); - matrices.translate(scaledWidth, 0, 0); - matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(90)); - - fillGradient(matrices, 0, 0, scaledHeight, scaledWidth / 2, 0xFFFFFF | 0, 0xFFFFFF | alpha2); - fillGradient(matrices, 0, scaledWidth / 2, scaledHeight, scaledWidth, 0xFFFFFF | alpha2, 0xFFFFFF | 0); - - matrices.pop(); - } - } + renderViewEffects(pony, matrices, scaledWidth, scaledHeight, tickDelta); if (client.currentScreen instanceof HidesHud || client.player.isSpectator() || client.options.hudHidden) { return; @@ -169,6 +146,50 @@ public class UHud extends DrawableHelper { } } + protected void renderViewEffects(Pony pony, MatrixStack matrices, int scaledWidth, int scaledHeight, float tickDelta) { + + boolean hasEffect = client.player.hasStatusEffect(SunBlindnessStatusEffect.INSTANCE); + + if (hasEffect || (pony.getSpecies() == Race.BAT && SunBlindnessStatusEffect.hasSunExposure(client.player))) { + float i = hasEffect ? (client.player.getStatusEffect(SunBlindnessStatusEffect.INSTANCE).getDuration() - tickDelta) / SunBlindnessStatusEffect.MAX_DURATION : 0; + + float pulse = (1 + (float)Math.sin(client.player.age / 108F)) * 0.25F; + + float strength = MathHelper.clamp(pulse + i, 0.3F, 1F); + + int alpha1 = (int)(strength * 205) << 24 & -16777216; + int alpha2 = (int)(alpha1 * 0.6F); + + fillGradient(matrices, 0, 0, scaledWidth, scaledHeight / 2, 0xFFFFFF | alpha1, 0xFFFFFF | alpha2); + fillGradient(matrices, 0, scaledHeight / 2, scaledWidth, scaledHeight, 0xFFFFFF | alpha2, 0xFFFFFF | alpha1); + + if (hasEffect) { + matrices.push(); + matrices.translate(scaledWidth, 0, 0); + matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(90)); + + fillGradient(matrices, 0, 0, scaledHeight, scaledWidth / 2, 0xFFFFFF | 0, 0xFFFFFF | alpha2); + fillGradient(matrices, 0, scaledWidth / 2, scaledHeight, scaledWidth, 0xFFFFFF | alpha2, 0xFFFFFF | 0); + + matrices.pop(); + } + } + + float exhaustion = pony.getMagicalReserves().getExhaustion().getPercentFill(); + + if (exhaustion > 0.5F) { + if (tickDelta == 0) { + client.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.BLOCK_ANVIL_BREAK, 1)); + } + + int alpha1 = 205 << 24 & -16777216; + int alpha2 = (int)(alpha1 * 0.6F); + + fillGradient(matrices, 0, 0, scaledWidth, scaledHeight / 2, 0xFFFFFF | alpha1, 0x000000 | alpha2); + fillGradient(matrices, 0, scaledHeight / 2, scaledWidth, scaledHeight, 0xFFFFFF | alpha2, 0x000000 | alpha1); + } + } + public void setMessage(Text message) { this.message = message; this.messageTime = 60; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/RaceChangeStatusEffect.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/RaceChangeStatusEffect.java index 1e914995..34464d4c 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/RaceChangeStatusEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/RaceChangeStatusEffect.java @@ -93,6 +93,7 @@ public class RaceChangeStatusEffect extends StatusEffect { MagicReserves magic = pony.getMagicalReserves(); magic.getExertion().add(50); magic.getEnergy().add(3); + magic.getExhaustion().add(3); if (state.shouldShowParticles()) { pony.spawnParticles(ParticleTypes.TOTEM_OF_UNDYING, 5); 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 0d27d073..a21cf4cf 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/MagicReserves.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/MagicReserves.java @@ -14,6 +14,11 @@ public interface MagicReserves { */ Bar getEnergy(); + /** + * Gets the amount of fatigue induced by using magic. + */ + Bar getExhaustion(); + /** * Gets the amount of magical energy the player has. * This is increases slowly with time by performing certain actions. 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 394d0519..287334b8 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java @@ -9,6 +9,7 @@ public class ManaContainer implements MagicReserves, Tickable { private final Pony pony; private final BarInst energy; + private final BarInst exhaustion; private final BarInst exertion; private final BarInst mana; private final BarInst xp; @@ -16,6 +17,7 @@ public class ManaContainer implements MagicReserves, Tickable { public ManaContainer(Pony pony) { this.pony = pony; this.energy = new BarInst(Pony.ENERGY, 100F, 0); + this.exhaustion = new BarInst(Pony.EXHAUSTION, 100F, 0); this.exertion = new BarInst(Pony.EXERTION, 10F, 0); this.xp = new BarInst(Pony.XP, 1, 0); this.mana = new XpCollectingBar(Pony.MANA, 100F, 100F); @@ -26,6 +28,11 @@ public class ManaContainer implements MagicReserves, Tickable { return exertion; } + @Override + public Bar getExhaustion() { + return exhaustion; + } + @Override public Bar getEnergy() { return energy; @@ -56,6 +63,12 @@ public class ManaContainer implements MagicReserves, Tickable { energy.add(-1); } + if (exhaustion.get() > 5) { + exhaustion.multiply(0.8F); + } else { + exhaustion.add(-1); + } + if (!pony.getSpecies().canFly() || !pony.getPhysics().isFlying()) { if (mana.getShadowFill() <= mana.getPercentFill()) { mana.add(18); 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 d4eea06a..21d9417a 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -364,7 +364,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickab if (mana.getPercentFill() < 0.2) { pony.getMagicalReserves().getExertion().add(2); - pony.getMagicalReserves().getEnergy().add(2 + (int)(getHorizontalMotion(entity) * 5)); + pony.getMagicalReserves().getExhaustion().add(2 + (int)(getHorizontalMotion(entity) * 50)); if (mana.getPercentFill() < 0.1 && ticksInAir % 10 == 0) { float exhaustion = (0.3F * ticksInAir) / 70; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java index eb3324d1..d7ec38fb 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -62,6 +62,7 @@ public class Pony extends Living implements Transmittable, Copieab private static final TrackedData RACE = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.INTEGER); static final TrackedData ENERGY = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT); + static final TrackedData EXHAUSTION = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT); static final TrackedData EXERTION = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT); static final TrackedData MANA = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT); static final TrackedData XP = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT);