From 68303948702eea601ffd81d1c07a3eb75f916f45 Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 24 Sep 2018 21:38:21 +0200 Subject: [PATCH] Add flying physics for pegasi --- .../player/PlayerGravityDelegate.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/player/PlayerGravityDelegate.java b/src/main/java/com/minelittlepony/unicopia/player/PlayerGravityDelegate.java index a0060f95..21eeff72 100644 --- a/src/main/java/com/minelittlepony/unicopia/player/PlayerGravityDelegate.java +++ b/src/main/java/com/minelittlepony/unicopia/player/PlayerGravityDelegate.java @@ -20,7 +20,7 @@ class PlayerGravityDelegate implements IUpdatable, InbtSerialisabl private final IPlayer player; - private static final float MAXIMUM_FLIGHT_EXPERIENCE = 100; + private static final float MAXIMUM_FLIGHT_EXPERIENCE = 500; private int ticksInAir = 0; private float flightExperience = 0; @@ -34,10 +34,15 @@ class PlayerGravityDelegate implements IUpdatable, InbtSerialisabl @Override public void onUpdate(EntityPlayer entity) { entity.capabilities.allowFlying = entity.capabilities.isCreativeMode || player.getPlayerSpecies().canFly(); - entity.capabilities.isFlying |= entity.capabilities.allowFlying && isFlying; + + if (!entity.capabilities.isCreativeMode) { + entity.capabilities.isFlying |= entity.capabilities.allowFlying && isFlying && !entity.onGround; + } + + isFlying = entity.capabilities.isFlying; if (!entity.capabilities.isCreativeMode && !entity.isElytraFlying()) { - if (entity.capabilities.isFlying && !entity.isRiding()) { + if (isFlying && !entity.isRiding()) { entity.fallDistance = 0; @@ -48,9 +53,17 @@ class PlayerGravityDelegate implements IUpdatable, InbtSerialisabl entity.addExhaustion(exhaustion * (1 - flightExperience)); - if (entity.ticksExisted % 20000 == 0) { + if (ticksInAir > 2000) { + ticksInAir = 1; addFlightExperience(entity); + entity.playSound(SoundEvents.ENTITY_GUARDIAN_FLOP, 1, 1); } + + float forward = 0.00015F * flightExperience; + + entity.motionX += - forward * MathHelper.sin(entity.rotationYaw * 0.017453292F); + entity.motionY -= 0.05F - ((entity.motionX * entity.motionX) + (entity.motionZ + entity.motionZ)) / 100; + entity.motionZ += forward * MathHelper.cos(entity.rotationYaw * 0.017453292F); } else { ticksInAir = 0; } @@ -95,7 +108,7 @@ class PlayerGravityDelegate implements IUpdatable, InbtSerialisabl private void addFlightExperience(EntityPlayer entity) { entity.addExperience(1); - flightExperience += (flightExperience - MAXIMUM_FLIGHT_EXPERIENCE) / 20; + flightExperience += (MAXIMUM_FLIGHT_EXPERIENCE - flightExperience) / 20; } public void updateFlightStat(EntityPlayer entity, boolean flying) {