diff --git a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java index 52aada57..71d89141 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java @@ -25,13 +25,20 @@ public class ChangelingDisguiseAbility extends ChangelingFeedAbility { @Nullable @Override public Hit tryActivate(Pony player) { - return Hit.INSTANCE; + if (player.getMagicalReserves().getMana().getPercentFill() >= 0.9F) { + return Hit.INSTANCE; + } + return null; } @Override public void apply(Pony iplayer, Hit data) { PlayerEntity player = iplayer.getOwner(); + if (iplayer.getMagicalReserves().getMana().getPercentFill() < 0.9F) { + return; + } + RayTraceHelper.Trace trace = RayTraceHelper.doTrace(player, 10, 1, EntityPredicates.EXCEPT_SPECTATOR.and(e -> !(e instanceof LightningEntity))); Entity looked = trace.getEntity().map(e -> { @@ -56,19 +63,21 @@ public class ChangelingDisguiseAbility extends ChangelingFeedAbility { return disc; }).setDisguise(looked); + iplayer.getMagicalReserves().getMana().multiply(0.1F); + player.calculateDimensions(); iplayer.setDirty(); } @Override public void preApply(Pony player, AbilitySlot slot) { - player.getMagicalReserves().addEnergy(20); + player.getMagicalReserves().getEnergy().add(20); player.spawnParticles(UParticles.CHANGELING_MAGIC, 5); } @Override public void postApply(Pony player, AbilitySlot slot) { - player.getMagicalReserves().setEnergy(0); + player.getMagicalReserves().getEnergy().set(0); player.spawnParticles(UParticles.CHANGELING_MAGIC, 5); } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java index 8cf1ad23..b7101ede 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java @@ -149,7 +149,7 @@ public class ChangelingFeedAbility implements Ability { @Override public void preApply(Pony player, AbilitySlot slot) { - player.getMagicalReserves().addExertion(6); + player.getMagicalReserves().getExertion().add(6); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java index f1b2d46f..a337d040 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java @@ -73,7 +73,7 @@ public class EarthPonyGrowAbility implements Ability { @Override public void preApply(Pony player, AbilitySlot slot) { - player.getMagicalReserves().addExertion(30); + player.getMagicalReserves().getExertion().add(30); if (player.getWorld().isClient()) { player.spawnParticles(MagicParticleEffect.UNICORN, 1); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java index b61b1705..f021d9ae 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java @@ -184,7 +184,7 @@ public class EarthPonyStompAbility implements Ability { @Override public void preApply(Pony player, AbilitySlot slot) { - player.getMagicalReserves().addExertion(40); + player.getMagicalReserves().getExertion().add(40); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java index 38d577af..b73a6bd5 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java @@ -62,7 +62,7 @@ public class UnicornCastingAbility implements Ability { @Override public void preApply(Pony player, AbilitySlot slot) { - player.getMagicalReserves().addEnergy(3); + player.getMagicalReserves().getEnergy().add(3); player.spawnParticles(MagicParticleEffect.UNICORN, 5); } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java index 82bbef4c..84fea889 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java @@ -45,7 +45,8 @@ public class UnicornTeleportAbility implements Ability { @Override public Pos tryActivate(Pony player) { - HitResult ray = RayTraceHelper.doTrace(player.getOwner(), 100, 1, EntityPredicates.EXCEPT_SPECTATOR).getResult(); + int maxDistance = player.getOwner().isCreative() ? 1000 : 100; + HitResult ray = RayTraceHelper.doTrace(player.getOwner(), maxDistance, 1, EntityPredicates.EXCEPT_SPECTATOR).getResult(); World w = player.getWorld(); @@ -152,7 +153,7 @@ public class UnicornTeleportAbility implements Ability { @Override public void preApply(Pony player, AbilitySlot slot) { - player.getMagicalReserves().addExertion(30); + player.getMagicalReserves().getExertion().add(30); player.spawnParticles(MagicParticleEffect.UNICORN, 5); } diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/Slot.java b/src/main/java/com/minelittlepony/unicopia/client/gui/Slot.java index 5bb06180..5af2794a 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/Slot.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/Slot.java @@ -81,17 +81,19 @@ class Slot { } // contents - //int middle = (slotPadding + size - iconSize)/2; - uHud.renderAbilityIcon(matrices, stat, slotPadding / 2, slotPadding / 2, iconSize, iconSize, iconSize, iconSize); - // foreground - UHud.drawTexture(matrices, 0, 0, backgroundU, backgroundV, size, size, 128, 128); - matrices.pop(); } void renderForeground(MatrixStack matrices, AbilityDispatcher abilities, float tickDelta) { + matrices.push(); + matrices.translate(x, y, 0); + UHud.drawTexture(matrices, 0, 0, backgroundU, backgroundV, size, size, 128, 128); + matrices.pop(); + } + + void renderLabel(MatrixStack matrices, AbilityDispatcher abilities, float tickDelta) { Text label = KeyBindingsHandler.INSTANCE.getBinding(aSlot).getBoundKeyLocalizedText(); matrices.push(); 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 5dbbdd24..32bb05b3 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.Bar; import com.minelittlepony.unicopia.entity.player.Pony; import com.mojang.blaze3d.systems.RenderSystem; @@ -13,9 +14,15 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.gui.hud.InGameHud; +import net.minecraft.client.render.BufferBuilder; +import net.minecraft.client.render.BufferRenderer; +import net.minecraft.client.render.Tessellator; +import net.minecraft.client.render.VertexFormats; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; import net.minecraft.util.Util; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Matrix4f; public class UHud extends DrawableHelper { @@ -57,8 +64,13 @@ public class UHud extends DrawableHelper { boolean swap = client.options.keySneak.isPressed(); slots.forEach(slot -> slot.renderBackground(matrices, abilities, swap, tickDelta)); + + renderManaRings(matrices); + slots.forEach(slot -> slot.renderForeground(matrices, abilities, tickDelta)); + slots.forEach(slot -> slot.renderLabel(matrices, abilities, tickDelta)); + RenderSystem.disableBlend(); RenderSystem.disableAlphaTest(); @@ -75,4 +87,74 @@ public class UHud extends DrawableHelper { client.getTextureManager().bindTexture(HUD_TEXTURE); }); } + + 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(); + + 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); + + matrices.pop(); + } + + static void renderRing(MatrixStack matrices, double outerRadius, double innerRadius, double maxAngle, int color) { + + 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; + + final double num_rings = 300; + double twoPi = Math.PI * 2; + final double increment = twoPi / num_rings; + + maxAngle *= twoPi; + maxAngle = MathHelper.clamp(maxAngle, 0, twoPi - increment); + + if (maxAngle < increment) { + return; + } + + BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer(); + RenderSystem.enableBlend(); + RenderSystem.disableTexture(); + RenderSystem.defaultBlendFunc(); + + bufferBuilder.begin(7, VertexFormats.POSITION_COLOR); + + Matrix4f model = matrices.peek().getModel(); + + for (double angle = 0; angle >= -maxAngle; angle -= increment) { + // center + bufferBuilder.vertex(model, + (float)(innerRadius * Math.sin(angle)), + (float)(innerRadius * Math.cos(angle)), 0).color(f, g, h, k).next(); + + // point one + bufferBuilder.vertex(model, + (float)(outerRadius * Math.sin(angle)), + (float)(outerRadius * Math.cos(angle)), 0).color(f, g, h, k).next(); + + // point two + bufferBuilder.vertex(model, + (float)(outerRadius * Math.sin(angle + increment)), + (float)(outerRadius * Math.cos(angle + increment)), 0).color(f, g, h, k).next(); + + // back to center + bufferBuilder.vertex(model, + (float)(innerRadius * Math.sin(angle + increment)), + (float)(innerRadius * Math.cos(angle + increment)), 0).color(f, g, h, k).next(); + + } + + bufferBuilder.end(); + BufferRenderer.draw(bufferBuilder); + + RenderSystem.enableTexture(); + } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/SphereModel.java b/src/main/java/com/minelittlepony/unicopia/client/particle/SphereModel.java index a036008d..70113521 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/SphereModel.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/SphereModel.java @@ -79,7 +79,7 @@ public class SphereModel { drawVertex(model, vertexWriter, radius, zenith, azimuth + azimuthIncrement, light, overlay, r, g, b, a); } - protected void drawVertex(Matrix4f model, VertexConsumer vertexWriter, + public static void drawVertex(Matrix4f model, VertexConsumer vertexWriter, double radius, double zenith, double azimuth, int light, int overlay, float r, float g, float b, float a) { Vector4f position = convertToCartesianCoord(radius, zenith, azimuth); @@ -87,7 +87,7 @@ public class SphereModel { vertexWriter.vertex(position.getX(), position.getY(), position.getZ(), r, g, b, a, 0, 0, overlay, light, 0, 0, 0); } - protected Vector4f convertToCartesianCoord(double r, double theta, double phi) { + public static Vector4f convertToCartesianCoord(double r, double theta, double phi) { double x = r * Math.sin(theta) * Math.cos(phi); double y = r * Math.sin(theta) * Math.sin(phi); 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 f90d7955..9eb7e950 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/RaceChangeStatusEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/RaceChangeStatusEffect.java @@ -91,8 +91,8 @@ public class RaceChangeStatusEffect extends StatusEffect { if (entity instanceof PlayerEntity) { Pony pony = (Pony)eq; MagicReserves magic = pony.getMagicalReserves(); - magic.addExertion(50); - magic.addEnergy(3); + magic.getExertion().add(50); + magic.getEnergy().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 8aa04df0..d28c5045 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/MagicReserves.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/MagicReserves.java @@ -1,40 +1,69 @@ package com.minelittlepony.unicopia.entity.player; public interface MagicReserves { + /** * Gets the amount of exertion this player has put toward any given activity. * This is simillar to tiredness. */ - float getExertion(); - - /** - * Sets the player's exertion level. - */ - void setExertion(float exertion); - - /** - * Adds player tiredness. - */ - default void addExertion(int exertion) { - setExertion(getExertion() + exertion/100F); - } + Bar getExertion(); /** * Gets the amount of excess energy the player has. * This is increased by eating sugar. */ - float getEnergy(); + Bar getEnergy(); /** - * Sets the player's energy level. + * Gets the amount of magical energy the player has. + * This is increases slowly with time by performing certain actions. */ - void setEnergy(float energy); + Bar getMana(); - /** - * Adds energy to the player's existing energy level. - */ - default void addEnergy(int energy) { - setEnergy(getEnergy() + energy / 100F); + public interface Bar { + + /** + * Gets the current value of this bar + */ + float get(); + + /** + * Gets the previous value from the last tick. + * Only updated when calling getPrev again. + */ + float getPrev(); + + /** + * Sets the absolute value + */ + void set(float value); + + /** + * Gets the percentage fill of this bar + */ + default float getPercentFill() { + return get() / getMax(); + } + + /** + * Adds a percentage increment to this bar's current value + */ + default void add(int step) { + set(get() + (step / getMax())); + } + + /** + * Multiplies the current value. + */ + default void multiply(float scalar) { + set(get() * scalar); + } + + /** + * Get the maximum value this bar is allowed to contain + */ + default float getMax() { + return 100F; + } } - } 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 088a5675..7871753e 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java @@ -1,32 +1,62 @@ package com.minelittlepony.unicopia.entity.player; +import net.minecraft.entity.data.TrackedData; +import net.minecraft.util.math.MathHelper; + public class ManaContainer implements MagicReserves { private final Pony pony; + private final Bar energy; + private final Bar exertion; + private final Bar mana; + public ManaContainer(Pony pony) { this.pony = pony; - pony.getOwner().getDataTracker().startTracking(Pony.ENERGY, 0F); - pony.getOwner().getDataTracker().startTracking(Pony.EXERTION, 0F); + this.energy = new BarInst(Pony.ENERGY); + this.exertion = new BarInst(Pony.EXERTION); + this.mana = new BarInst(Pony.MANA); } @Override - public float getExertion() { - return pony.getOwner().getDataTracker().get(Pony.EXERTION); + public Bar getExertion() { + return exertion; } @Override - public void setExertion(float exertion) { - pony.getOwner().getDataTracker().set(Pony.EXERTION, Math.max(0, exertion)); + public Bar getEnergy() { + return energy; } @Override - public float getEnergy() { - return pony.getOwner().getDataTracker().get(Pony.ENERGY); + public Bar getMana() { + return mana; } - @Override - public void setEnergy(float energy) { - pony.getOwner().getDataTracker().set(Pony.ENERGY, Math.max(0, energy)); - } + class BarInst implements Bar { + private final TrackedData marker; + private float prev; + + BarInst(TrackedData marker) { + this.marker = marker; + pony.getOwner().getDataTracker().startTracking(marker, 0F); + } + + @Override + public float get() { + 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())); + } + } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Motion.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Motion.java index d56af216..0b99d5ab 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Motion.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Motion.java @@ -9,11 +9,5 @@ public interface Motion { */ boolean isFlying(); - float getFlightExperience(); - - float getFlightDuration(); - - boolean isExperienceCritical(); - PlayerDimensions getDimensions(); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java index 097925ea..1355a266 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java @@ -45,14 +45,14 @@ public class PlayerCamera extends MotionCompositor { } public double calculateFieldOfView(double fov) { - fov += player.getMagicalReserves().getExertion() / 5F; + fov += player.getMagicalReserves().getExertion().get() / 5F; fov += getEnergyAddition(); return fov; } protected float getEnergyAddition() { - int maxE = (int)Math.floor(player.getMagicalReserves().getEnergy() * 100); + int maxE = (int)Math.floor(player.getMagicalReserves().getEnergy().get() * 100); if (maxE <= 0) { return 0; 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 2b44334e..ba13e6a9 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -1,13 +1,11 @@ package com.minelittlepony.unicopia.entity.player; -import java.util.Random; - import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.ability.FlightPredicate; import com.minelittlepony.unicopia.ability.magic.Spell; import com.minelittlepony.unicopia.entity.EntityPhysics; -import com.minelittlepony.unicopia.particle.MagicParticleEffect; +import com.minelittlepony.unicopia.entity.player.MagicReserves.Bar; import com.minelittlepony.unicopia.util.NbtSerialisable; import com.minelittlepony.unicopia.util.MutableVector; @@ -21,18 +19,13 @@ import net.minecraft.sound.SoundEvents; import net.minecraft.util.Tickable; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Vec3d; public class PlayerPhysics extends EntityPhysics implements Tickable, Motion, NbtSerialisable { - private static final float MAXIMUM_FLIGHT_EXPERIENCE = 1500; - - public int ticksNextLevel = 0; - public float flightExperience = 0; + private int ticksInAir; public boolean isFlyingEither = false; public boolean isFlyingSurvival = false; - public boolean isRainbooming = false; private double lastTickPosX = 0; private double lastTickPosZ = 0; @@ -78,11 +71,6 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti return dimensions; } - @Override - public boolean isExperienceCritical() { - return isRainbooming || flightExperience > MAXIMUM_FLIGHT_EXPERIENCE * 0.8; - } - @Override public void tick() { PlayerEntity entity = pony.getOwner(); @@ -97,20 +85,6 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti MutableVector velocity = new MutableVector(entity.getVelocity()); - if (isExperienceCritical() && pony.isClient()) { - Random rnd = pony.getWorld().random; - - for (int i = 0; i < 360 + getHorizontalMotion(entity); i += 10) { - Vec3d pos = pony.getOriginVector().add( - rnd.nextGaussian() * entity.getWidth(), - rnd.nextGaussian() * entity.getHeight()/2, - rnd.nextGaussian() * entity.getWidth() - ); - - pony.addParticle(MagicParticleEffect.UNICORN, pos, velocity.toImmutable()); - } - } - boolean creative = entity.abilities.creativeMode || pony.getOwner().isSpectator(); entity.abilities.allowFlying = checkCanFly(); @@ -121,72 +95,44 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti if ((entity.isOnGround() && entity.isSneaking()) || entity.isTouchingWater()) { entity.abilities.flying = false; } + + } isFlyingSurvival = entity.abilities.flying && !creative; isFlyingEither = isFlyingSurvival || (creative && entity.abilities.flying); - if (!creative && !entity.isFallFlying()) { - if (isFlyingSurvival && !entity.hasVehicle()) { + if (!creative && !entity.isFallFlying() && isFlyingSurvival && !entity.hasVehicle()) { - if (!isRainbooming && getHorizontalMotion(entity) > 0.2 && flightExperience < MAXIMUM_FLIGHT_EXPERIENCE) { - flightExperience++; - } + entity.fallDistance = 0; - entity.fallDistance = 0; + if (ticksInAir > 100) { + Bar mana = pony.getMagicalReserves().getMana(); - if (pony.getSpecies() != Race.CHANGELING && entity.world.random.nextInt(100) == 0) { - float exhaustion = (0.3F * ticksNextLevel) / 70; - if (entity.isSprinting()) { - exhaustion *= 3.11F; + mana.add((int)(-getHorizontalMotion(entity) * 100)); + + if (mana.getPercentFill() < 0.2) { + pony.getMagicalReserves().getExertion().add(2); + pony.getMagicalReserves().getEnergy().add(2); + + if (mana.getPercentFill() < 0.1 && ticksInAir % 10 == 0) { + float exhaustion = (0.3F * ticksInAir) / 70; + if (entity.isSprinting()) { + exhaustion *= 3.11F; + } + + entity.addExhaustion(exhaustion); } - - exhaustion *= (1 - flightExperience / MAXIMUM_FLIGHT_EXPERIENCE); - - entity.addExhaustion(exhaustion); - } - - if (ticksNextLevel++ >= MAXIMUM_FLIGHT_EXPERIENCE) { - ticksNextLevel = 0; - - entity.addExperience(1); - addFlightExperience(1); - entity.playSound(SoundEvents.ENTITY_GUARDIAN_FLOP, 1, 1); - } - - moveFlying(entity, velocity); - - if (isExperienceCritical()) { - - if (pony.getMagicalReserves().getEnergy() <= 0.25F) { - pony.getMagicalReserves().addEnergy(2); - } - - if (isRainbooming || (entity.isSneaking() && isRainboom())) { - performRainboom(entity, velocity); - } - } - - if (ticksNextLevel > 0 && ticksNextLevel % 30 == 0) { - entity.playSound(getWingSound(), 0.5F, 1); - } - } else { - if (ticksNextLevel != 0) { - entity.playSound(getWingSound(), 0.4F, 1); - } - - ticksNextLevel = 0; - - if (isExperienceCritical()) { - addFlightExperience(-0.39991342F); - } else { - addFlightExperience(-0.019991342F); - } - - if (flightExperience < 0.02) { - isRainbooming = false; } } + + moveFlying(entity, velocity); + + if (ticksInAir++ > 0 && ticksInAir % 30 == 0) { + entity.playSound(getWingSound(), 0.5F, 1); + } + } else { + ticksInAir = 0; } if (pony.getPhysics().isGravityNegative()) { @@ -208,28 +154,9 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti return pony.getSpecies() == Race.CHANGELING ? USounds.CHANGELING_BUZZ : USounds.WING_FLAP; } - protected void performRainboom(Entity entity, MutableVector velocity) { - float forward = 0.5F * flightExperience / MAXIMUM_FLIGHT_EXPERIENCE; - - velocity.x += - forward * MathHelper.sin(entity.yaw * 0.017453292F); - velocity.z += forward * MathHelper.cos(entity.yaw * 0.017453292F); - velocity.y += forward * MathHelper.sin(entity.pitch * 0.017453292F); - - if (!isRainbooming || entity.world.random.nextInt(5) == 0) { - entity.playSound(SoundEvents.ENTITY_LIGHTNING_BOLT_THUNDER, 1, 1); - } - - if (flightExperience > 0) { - flightExperience -= 13; - isRainbooming = true; - } else { - isRainbooming = false; - } - } - protected void moveFlying(Entity player, MutableVector velocity) { - float forward = 0.000015F * flightExperience * (float)Math.sqrt(getHorizontalMotion(player)); + float forward = 0.000015F * (float)Math.sqrt(getHorizontalMotion(player)); boolean sneak = !player.isSneaking(); // vertical drop due to gravity @@ -287,13 +214,6 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti return distance > 4 ? SoundEvents.ENTITY_PLAYER_BIG_FALL : SoundEvents.ENTITY_PLAYER_SMALL_FALL; } - private void addFlightExperience(float factor) { - float maximumGain = MAXIMUM_FLIGHT_EXPERIENCE - flightExperience; - float gainSteps = 20; - - flightExperience = Math.max(0, flightExperience + factor * maximumGain / gainSteps); - } - public void updateFlightStat(boolean flying) { PlayerEntity entity = pony.getOwner(); @@ -303,10 +223,6 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti entity.abilities.flying |= flying; isFlyingSurvival = entity.abilities.flying; - - if (isFlyingSurvival) { - ticksNextLevel = 0; - } } else { entity.abilities.flying = false; isFlyingSurvival = false; @@ -316,21 +232,17 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti @Override public void toNBT(CompoundTag compound) { super.toNBT(compound); - compound.putInt("flightDuration", ticksNextLevel); - compound.putFloat("flightExperience", flightExperience); compound.putBoolean("isFlying", isFlyingSurvival); compound.putBoolean("isFlyingEither", isFlyingEither); - compound.putBoolean("isRainbooming", isRainbooming); + compound.putInt("ticksInAir", ticksInAir); } @Override public void fromNBT(CompoundTag compound) { super.fromNBT(compound); - ticksNextLevel = compound.getInt("flightDuration"); - flightExperience = compound.getFloat("flightExperience"); isFlyingSurvival = compound.getBoolean("isFlying"); isFlyingEither = compound.getBoolean("isFlyingEither"); - isRainbooming = compound.getBoolean("isRainbooming"); + ticksInAir = compound.getInt("ticksInAir"); pony.getOwner().calculateDimensions(); } @@ -339,14 +251,4 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti public boolean isFlying() { return isFlyingSurvival; } - - @Override - public float getFlightExperience() { - return flightExperience / MAXIMUM_FLIGHT_EXPERIENCE; - } - - @Override - public float getFlightDuration() { - return ticksNextLevel / MAXIMUM_FLIGHT_EXPERIENCE; - } } 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 0712cf17..2d419180 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -54,8 +54,11 @@ import net.minecraft.util.math.Vec3d; public class Pony implements Caster, Equine, Transmittable, Copieable { private static final TrackedData RACE = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.INTEGER); + static final TrackedData ENERGY = 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); + private static final TrackedData EFFECT = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.TAG_COMPOUND); private static final TrackedData HELD_EFFECT = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.TAG_COMPOUND); @@ -273,8 +276,12 @@ public class Pony implements Caster, Equine, Transmi } } - mana.addExertion(-10); - mana.addEnergy(-1); + mana.getExertion().add(-10); + mana.getEnergy().add(-1); + + if (!getSpecies().canFly() || !gravity.isFlying()) { + mana.getMana().add(60); + } attributes.applyAttributes(this); @@ -323,13 +330,24 @@ public class Pony implements Caster, Equine, Transmi @Override public boolean subtractEnergyCost(double foodSubtract) { if (!entity.abilities.creativeMode) { - int food = (int)(entity.getHungerManager().getFoodLevel() - foodSubtract); - if (food < 0) { - entity.getHungerManager().add(-entity.getHungerManager().getFoodLevel(), 0); - entity.damage(MagicalDamageSource.EXHAUSTION, -food/2); + float currentMana = mana.getMana().get(); + float foodManaRatio = 10; + + if (currentMana >= foodSubtract * foodManaRatio) { + mana.getMana().set(currentMana - (float)foodSubtract * foodManaRatio); } else { - entity.getHungerManager().add((int)-foodSubtract, 0); + mana.getMana().set(0); + foodSubtract -= currentMana / foodManaRatio; + + int food = (int)(entity.getHungerManager().getFoodLevel() - foodSubtract); + + if (food < 0) { + entity.getHungerManager().add(-entity.getHungerManager().getFoodLevel(), 0); + entity.damage(MagicalDamageSource.EXHAUSTION, -food/2); + } else { + entity.getHungerManager().add((int)-foodSubtract, 0); + } } }