mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-21 12:24:22 +01:00
Tweak flight controls and animations
This commit is contained in:
parent
5db8150c02
commit
5001a52e41
1 changed files with 51 additions and 14 deletions
|
@ -43,9 +43,15 @@ import net.minecraft.util.math.Vec3d;
|
||||||
public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickable, Motion, NbtSerialisable {
|
public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickable, Motion, NbtSerialisable {
|
||||||
|
|
||||||
private int ticksInAir;
|
private int ticksInAir;
|
||||||
|
private int ticksToGlide;
|
||||||
|
|
||||||
private float thrustScale = 0;
|
private float thrustScale = 0;
|
||||||
|
|
||||||
|
private boolean flapping;
|
||||||
|
|
||||||
|
private int prevStrafe;
|
||||||
|
private float strafe;
|
||||||
|
|
||||||
private FlightType lastFlightType = FlightType.NONE;
|
private FlightType lastFlightType = FlightType.NONE;
|
||||||
|
|
||||||
public boolean isFlyingEither = false;
|
public boolean isFlyingEither = false;
|
||||||
|
@ -79,7 +85,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isGliding() {
|
public boolean isGliding() {
|
||||||
return isFlying() && (entity.isSneaking() || ((Jumper)entity).isJumping()) && !pony.sneakingChanged();
|
return ticksToGlide <= 0 && isFlying() && !entity.isSneaking();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -95,18 +101,23 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
|
||||||
if (getFlightType() == FlightType.INSECTOID) {
|
if (getFlightType() == FlightType.INSECTOID) {
|
||||||
spreadAmount += Math.sin(pony.getEntity().age * 4F) * 8;
|
spreadAmount += Math.sin(pony.getEntity().age * 4F) * 8;
|
||||||
} else {
|
} else {
|
||||||
spreadAmount += isGliding() ? 3 : thrustScale * 60;
|
if (isGliding()) {
|
||||||
|
spreadAmount += 2.5F;
|
||||||
|
} else {
|
||||||
|
spreadAmount += strafe * 10;
|
||||||
|
spreadAmount += thrustScale * 24;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
spreadAmount += MathHelper.clamp(-entity.getVelocity().y, 0, 2);
|
spreadAmount += MathHelper.clamp(-entity.getVelocity().y, 0, 2);
|
||||||
spreadAmount += Math.sin(entity.age / 9F) / 9F;
|
spreadAmount += Math.sin(entity.age / 9F) / 9F;
|
||||||
}
|
|
||||||
|
|
||||||
if (entity.isSneaking()) {
|
if (entity.isSneaking()) {
|
||||||
spreadAmount += 2;
|
spreadAmount += 2;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
spreadAmount = MathHelper.clamp(spreadAmount, -2, 5);
|
spreadAmount = MathHelper.clamp(spreadAmount, -2, 6);
|
||||||
|
|
||||||
return pony.getInterpolator().interpolate("wingSpreadAmount", spreadAmount, 10);
|
return pony.getInterpolator().interpolate("wingSpreadAmount", spreadAmount, 10);
|
||||||
}
|
}
|
||||||
|
@ -144,6 +155,9 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
|
||||||
if (wallHitCooldown > 0) {
|
if (wallHitCooldown > 0) {
|
||||||
wallHitCooldown--;
|
wallHitCooldown--;
|
||||||
}
|
}
|
||||||
|
if (ticksToGlide > 0) {
|
||||||
|
ticksToGlide--;
|
||||||
|
}
|
||||||
|
|
||||||
final MutableVector velocity = new MutableVector(entity.getVelocity());
|
final MutableVector velocity = new MutableVector(entity.getVelocity());
|
||||||
|
|
||||||
|
@ -215,7 +229,19 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
|
||||||
|
|
||||||
ticksInAir++;
|
ticksInAir++;
|
||||||
tickFlight(type, velocity);
|
tickFlight(type, velocity);
|
||||||
|
|
||||||
|
int strafing = (int)Math.signum(entity.sidewaysSpeed);
|
||||||
|
if (strafing != prevStrafe) {
|
||||||
|
prevStrafe = strafing;
|
||||||
|
strafe = 1;
|
||||||
|
ticksToGlide = 20;
|
||||||
|
entity.playSound(getFlightType().getWingFlapSound(), 0.25F, 1);
|
||||||
} else {
|
} else {
|
||||||
|
strafe *= 0.28;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
prevStrafe = 0;
|
||||||
|
strafe = 0;
|
||||||
ticksInAir = 0;
|
ticksInAir = 0;
|
||||||
soundPlaying = false;
|
soundPlaying = false;
|
||||||
|
|
||||||
|
@ -237,10 +263,15 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
|
||||||
|
|
||||||
entity.setVelocity(velocity.toImmutable());
|
entity.setVelocity(velocity.toImmutable());
|
||||||
|
|
||||||
if (isFlying() && !entity.isInSwimmingPose()) {
|
if (isFlying() && !entity.isFallFlying()) {
|
||||||
|
|
||||||
float pitch = ((Leaner)entity).getLeaningPitch();
|
float pitch = ((Leaner)entity).getLeaningPitch();
|
||||||
if (pitch < 1) {
|
if (pitch < 1) {
|
||||||
((Leaner)entity).setLeaningPitch(Math.max(0, pitch + 0.18F));
|
if (pitch < 0.9F) {
|
||||||
|
pitch += 0.1F;
|
||||||
|
}
|
||||||
|
pitch += 0.09F;
|
||||||
|
((Leaner)entity).setLeaningPitch(Math.max(0, pitch));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,8 +301,8 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
|
||||||
|
|
||||||
if (type.isAvian()) {
|
if (type.isAvian()) {
|
||||||
if (entity.world.isClient && ticksInAir % 20 == 0 && entity.getVelocity().length() < 0.29) {
|
if (entity.world.isClient && ticksInAir % 20 == 0 && entity.getVelocity().length() < 0.29) {
|
||||||
entity.playSound(getFlightType().getWingFlapSound(), 0.5F, 1);
|
flapping = true;
|
||||||
thrustScale = 1;
|
ticksToGlide = 20;
|
||||||
}
|
}
|
||||||
velocity.y -= 0.02 * getGravitySignum();
|
velocity.y -= 0.02 * getGravitySignum();
|
||||||
velocity.x *= 0.9896;
|
velocity.x *= 0.9896;
|
||||||
|
@ -420,10 +451,16 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
|
||||||
|
|
||||||
private void applyThrust(MutableVector velocity) {
|
private void applyThrust(MutableVector velocity) {
|
||||||
if (pony.sneakingChanged() && entity.isSneaking()) {
|
if (pony.sneakingChanged() && entity.isSneaking()) {
|
||||||
thrustScale = 1;
|
flapping = true;
|
||||||
|
ticksToGlide = 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
thrustScale *= 0.2889F;
|
||||||
|
|
||||||
|
if (thrustScale <= 0.000001F & flapping) {
|
||||||
|
flapping = false;
|
||||||
entity.playSound(getFlightType().getWingFlapSound(), 0.5F, 1);
|
entity.playSound(getFlightType().getWingFlapSound(), 0.5F, 1);
|
||||||
} else {
|
thrustScale = 1;
|
||||||
thrustScale *= 0.1889F;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float heavyness = EnchantmentHelper.getEquipmentLevel(UEnchantments.HEAVY, entity) / 6F;
|
float heavyness = EnchantmentHelper.getEquipmentLevel(UEnchantments.HEAVY, entity) / 6F;
|
||||||
|
|
Loading…
Reference in a new issue