Use the cached flight type rather than calculating it every time

This commit is contained in:
Sollace 2023-10-07 23:45:11 +01:00
parent 222e208141
commit b3b9cb7e89
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB

View file

@ -153,7 +153,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
float spreadAmount = -0.5F; float spreadAmount = -0.5F;
if (isFlying()) { if (isFlying()) {
if (getFlightType() == FlightType.INSECTOID) { if (lastFlightType == FlightType.INSECTOID) {
spreadAmount += Math.sin(pony.asEntity().age * 4F) * 8; spreadAmount += Math.sin(pony.asEntity().age * 4F) * 8;
} else { } else {
if (isGliding()) { if (isGliding()) {
@ -181,6 +181,10 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
} }
public FlightType getFlightType() { public FlightType getFlightType() {
return lastFlightType;
}
private FlightType recalculateFlightType() {
DimensionType dimension = entity.getWorld().getDimension(); DimensionType dimension = entity.getWorld().getDimension();
if ((RegistryUtils.isIn(entity.getWorld(), dimension, RegistryKeys.DIMENSION_TYPE, UTags.HAS_NO_ATMOSPHERE) if ((RegistryUtils.isIn(entity.getWorld(), dimension, RegistryKeys.DIMENSION_TYPE, UTags.HAS_NO_ATMOSPHERE)
@ -246,20 +250,21 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
entity.setPose(EntityPose.STANDING); entity.setPose(EntityPose.STANDING);
} }
FlightType type = getFlightType(); FlightType type = recalculateFlightType();
boolean typeChanged = type != lastFlightType && (lastFlightType.isArtifical() || type.isArtifical()); boolean typeChanged = type != lastFlightType;
if (typeChanged) { if (typeChanged && lastFlightType.isArtifical() || type.isArtifical()) {
pony.spawnParticles(ParticleTypes.CLOUD, 10); pony.spawnParticles(ParticleTypes.CLOUD, 10);
playSound(entity.getWorld().getDimension().ultrawarm() ? USounds.ITEM_ICARUS_WINGS_CORRUPT : USounds.ITEM_ICARUS_WINGS_PURIFY, 0.1125F, 1.5F); playSound(entity.getWorld().getDimension().ultrawarm() ? USounds.ITEM_ICARUS_WINGS_CORRUPT : USounds.ITEM_ICARUS_WINGS_PURIFY, 0.1125F, 1.5F);
} }
entity.getAbilities().allowFlying = type.canFlyCreative(entity); lastFlightType = type;
entity.getAbilities().allowFlying = lastFlightType.canFlyCreative(entity);
boolean creative = entity.isCreative() || entity.isSpectator(); boolean creative = entity.isCreative() || entity.isSpectator();
boolean startedFlyingCreative = !creative && isFlyingEither != entity.getAbilities().flying; boolean startedFlyingCreative = !creative && isFlyingEither != entity.getAbilities().flying;
if (!creative) { if (!creative) {
@ -271,8 +276,8 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
isCancelled = false; isCancelled = false;
} }
entity.getAbilities().flying |= (type.canFly() || entity.getAbilities().allowFlying) && isFlyingEither; entity.getAbilities().flying |= (lastFlightType.canFly() || entity.getAbilities().allowFlying) && isFlyingEither;
if (!type.canFly() && (type != lastFlightType)) { if (!lastFlightType.canFly() && typeChanged) {
entity.getAbilities().flying = false; entity.getAbilities().flying = false;
} }
@ -288,8 +293,6 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
cancelFlight(false); cancelFlight(false);
} }
} }
if (isGravityNegative()) { if (isGravityNegative()) {
@ -302,7 +305,6 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
} }
} }
lastFlightType = type;
isFlyingSurvival = entity.getAbilities().flying && !creative; isFlyingSurvival = entity.getAbilities().flying && !creative;
isFlyingEither = isFlyingSurvival || (creative && entity.getAbilities().flying); isFlyingEither = isFlyingSurvival || (creative && entity.getAbilities().flying);
@ -310,10 +312,10 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
entity.calculateDimensions(); entity.calculateDimensions();
} }
if (type.canFly()) { if (lastFlightType.canFly()) {
if (isFlying()) { if (isFlying()) {
ticksInAir++; ticksInAir++;
tickFlight(type, velocity); tickFlight(lastFlightType, velocity);
int strafing = (int)Math.signum(entity.sidewaysSpeed); int strafing = (int)Math.signum(entity.sidewaysSpeed);
if (strafing != prevStrafe) { if (strafing != prevStrafe) {
@ -321,8 +323,8 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
strafe = 1; strafe = 1;
ticksToGlide = MAX_TICKS_TO_GLIDE; ticksToGlide = MAX_TICKS_TO_GLIDE;
if (!SpellPredicate.IS_DISGUISE.isOn(pony)) { if (!SpellPredicate.IS_DISGUISE.isOn(pony)) {
if (type != FlightType.INSECTOID) { if (lastFlightType != FlightType.INSECTOID) {
playSound(type.getWingFlapSound(), 0.25F, entity.getSoundPitch() * type.getWingFlapSoundPitch()); playSound(lastFlightType.getWingFlapSound(), 0.25F, entity.getSoundPitch() * lastFlightType.getWingFlapSoundPitch());
} }
entity.getWorld().emitGameEvent(entity, GameEvent.ELYTRA_GLIDE, entity.getPos()); entity.getWorld().emitGameEvent(entity, GameEvent.ELYTRA_GLIDE, entity.getPos());
} }
@ -356,7 +358,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
descentRate = 0; descentRate = 0;
ticksDiving = 0; ticksDiving = 0;
if (Abilities.RAINBOOM.canUse(pony.getSpecies()) && entity.isOnGround()) { if (Abilities.RAINBOOM.canUse(pony.getCompositeRace()) && entity.isOnGround()) {
pony.getMagicalReserves().getCharge().set(0); pony.getMagicalReserves().getCharge().set(0);
} }
@ -467,7 +469,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
stack.damage(minDamage + entity.getWorld().random.nextInt(50), entity, e -> e.sendEquipmentBreakStatus(EquipmentSlot.CHEST)); stack.damage(minDamage + entity.getWorld().random.nextInt(50), entity, e -> e.sendEquipmentBreakStatus(EquipmentSlot.CHEST));
} }
if (!getFlightType().canFly()) { if (!lastFlightType.canFly()) {
playSound(USounds.ITEM_ICARUS_WINGS_EXHAUSTED, 1, 2); playSound(USounds.ITEM_ICARUS_WINGS_EXHAUSTED, 1, 2);
cancelFlight(false); cancelFlight(false);
} }
@ -642,8 +644,8 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
if (thrustScale <= 0.000001F & flapping) { if (thrustScale <= 0.000001F & flapping) {
flapping = false; flapping = false;
if (!SpellPredicate.IS_DISGUISE.isOn(pony)) { if (!SpellPredicate.IS_DISGUISE.isOn(pony)) {
if (getFlightType() != FlightType.INSECTOID) { if (lastFlightType != FlightType.INSECTOID) {
playSound(getFlightType().getWingFlapSound(), 0.25F, entity.getSoundPitch() * getFlightType().getWingFlapSoundPitch()); playSound(lastFlightType.getWingFlapSound(), 0.25F, entity.getSoundPitch() * lastFlightType.getWingFlapSoundPitch());
} }
entity.getWorld().emitGameEvent(entity, GameEvent.ELYTRA_GLIDE, entity.getPos()); entity.getWorld().emitGameEvent(entity, GameEvent.ELYTRA_GLIDE, entity.getPos());
} }
@ -709,10 +711,11 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
* Called when a player's species changes to update whether they can fly or not * Called when a player's species changes to update whether they can fly or not
*/ */
public void updateFlightState() { public void updateFlightState() {
FlightType type = getFlightType(); FlightType type = recalculateFlightType();
entity.getAbilities().allowFlying = type.canFlyCreative(entity); entity.getAbilities().allowFlying = type.canFlyCreative(entity);
entity.getAbilities().flying &= type.canFly() || entity.getAbilities().allowFlying; entity.getAbilities().flying &= type.canFly() || entity.getAbilities().allowFlying;
isFlyingSurvival = entity.getAbilities().flying; isFlyingSurvival = entity.getAbilities().flying;
lastFlightType = type;
} }
public void dashForward(float speed) { public void dashForward(float speed) {