From 92fd22668ec0a3792b8eddfca93bf381ce6a8fbf Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 13 Feb 2024 17:24:05 +0000 Subject: [PATCH] Smooth motion due to airflow and wind. Should fix any bumps and sudden changes in direction/altitude when flying and overall make controlling whilst flying more manageable --- .../unicopia/entity/player/PlayerPhysics.java | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) 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 971f8b26..2b4b93d0 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -88,6 +88,9 @@ public class PlayerPhysics extends EntityPhysics implements Tickab private final Pony pony; + private Lerp updraft = new Lerp(0); + private Lerp windStrength = new Lerp(0); + public PlayerPhysics(Pony pony) { super(pony.asEntity(), Creature.GRAVITY); this.pony = pony; @@ -364,6 +367,8 @@ public class PlayerPhysics extends EntityPhysics implements Tickab soundPlaying = false; descentRate = 0; ticksDiving = 0; + updraft.update(0, 100); + windStrength.update(0, 100); if (Abilities.RAINBOOM.canUse(pony.getCompositeRace()) && entity.isOnGround()) { pony.getMagicalReserves().getCharge().set(0); @@ -376,6 +381,8 @@ public class PlayerPhysics extends EntityPhysics implements Tickab } else { descentRate = 0; soundPlaying = false; + updraft.update(0, 100); + windStrength.update(0, 100); } if (!entity.isOnGround()) { @@ -623,12 +630,13 @@ public class PlayerPhysics extends EntityPhysics implements Tickab velocity.x += - forward * MathHelper.sin(entity.getYaw() * 0.017453292F); velocity.z += forward * MathHelper.cos(entity.getYaw() * 0.017453292F); - if (entity.getWorld().hasRain(entity.getBlockPos())) { applyTurbulance(velocity); } else { - double updraft = WeatherConditions.getUpdraft(new BlockPos.Mutable().set(entity.getBlockPos()), entity.getWorld()) / 3F; - updraft *= 1 + motion; + float targetUpdraft = (float)WeatherConditions.getUpdraft(new BlockPos.Mutable().set(entity.getBlockPos()), entity.getWorld()) / 3F; + targetUpdraft *= 1 + motion; + this.updraft.update(targetUpdraft, targetUpdraft > this.updraft.getTarget() ? 30_000 : 3000); + double updraft = this.updraft.getValue(); velocity.y += updraft; descentRate -= updraft; } @@ -702,19 +710,25 @@ public class PlayerPhysics extends EntityPhysics implements Tickab .multiply(globalEffectStrength / 100D) .multiply(1 / (1 + Math.floor(pony.getLevel().get() / 10F))); + + + + if (effectStrength * gust.getX() >= 1) { SoundEmitter.playSoundAt(entity, USounds.AMBIENT_WIND_GUST, SoundCategory.AMBIENT, 3, 1); } float weight = 1 + (EnchantmentHelper.getEquipmentLevel(UEnchantments.HEAVY, entity) * 0.8F) + (pony.getCompositeRace().canUseEarth() ? 1 : 0); - velocity.add(WeatherConditions.getAirflow(entity.getBlockPos(), entity.getWorld()), 0.04F * effectStrength); - velocity.add(Vec3d.fromPolar( - (entity.getPitch() + (float)gust.getY()) * MathHelper.RADIANS_PER_DEGREE, - (entity.getYaw() + (float)gust.getZ()) * MathHelper.RADIANS_PER_DEGREE - ), - effectStrength * (float)gust.getX() / weight - ); + Vec3d airflow = WeatherConditions.getAirflow(entity.getBlockPos(), entity.getWorld()) + .multiply(0.04F * effectStrength) + .add(Vec3d.fromPolar( + (entity.getPitch() + (float)gust.getY()) * MathHelper.RADIANS_PER_DEGREE, + (entity.getYaw() + (float)gust.getZ()) * MathHelper.RADIANS_PER_DEGREE + ).multiply(effectStrength * (float)gust.getX() / weight)); + + windStrength.update((float)airflow.length(), airflow.length() > windStrength.getValue() ? 1000 : 500); + velocity.add(airflow.normalize(), windStrength.getValue()); if (!entity.getWorld().isClient && effectStrength > 0.9F && entity.getWorld().isThundering() && entity.getWorld().random.nextInt(9000) == 0) { LightningEntity lightning = EntityType.LIGHTNING_BOLT.create(entity.getWorld()); @@ -794,6 +808,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickab compound.putBoolean("isFlyingEither", isFlyingEither); compound.putInt("ticksInAir", ticksInAir); compound.putFloat("descentRate", descentRate); + compound.putFloat("updraft", updraft.getValue()); } @Override @@ -804,6 +819,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickab isFlyingEither = compound.getBoolean("isFlyingEither"); ticksInAir = compound.getInt("ticksInAir"); descentRate = compound.getFloat("descentRate"); + updraft.update(compound.getFloat("updraft"), 0); entity.calculateDimensions(); }