Fix wings of icarus sounds not playing when running out of charge

This commit is contained in:
Sollace 2023-08-30 23:46:06 +01:00
parent a8d5e45f0e
commit 811e860a45
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 19 additions and 22 deletions

View file

@ -41,6 +41,7 @@ import net.minecraft.particle.ParticleTypes;
import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.math.*; import net.minecraft.util.math.*;
import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.event.GameEvent; import net.minecraft.world.event.GameEvent;
@ -249,7 +250,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
if (typeChanged) { if (typeChanged) {
pony.spawnParticles(ParticleTypes.CLOUD, 10); pony.spawnParticles(ParticleTypes.CLOUD, 10);
entity.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); entity.getAbilities().allowFlying = type.canFlyCreative(entity);
@ -320,7 +321,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
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 (type != FlightType.INSECTOID) {
entity.playSound(type.getWingFlapSound(), 0.25F, entity.getSoundPitch() * type.getWingFlapSoundPitch()); playSound(type.getWingFlapSound(), 0.25F, entity.getSoundPitch() * type.getWingFlapSoundPitch());
} }
entity.getWorld().emitGameEvent(entity, GameEvent.ELYTRA_GLIDE, entity.getPos()); entity.getWorld().emitGameEvent(entity, GameEvent.ELYTRA_GLIDE, entity.getPos());
} }
@ -405,7 +406,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
if (pony.getObservedSpecies() != Race.BAT && entity.getWorld().random.nextInt(9000) == 0) { if (pony.getObservedSpecies() != Race.BAT && entity.getWorld().random.nextInt(9000) == 0) {
entity.dropItem(UItems.PEGASUS_FEATHER); entity.dropItem(UItems.PEGASUS_FEATHER);
entity.playSound(USounds.ENTITY_PLAYER_PEGASUS_MOLT, 0.3F, 1); playSound(USounds.ENTITY_PLAYER_PEGASUS_MOLT, 0.3F, 1);
UCriteria.SHED_FEATHER.trigger(entity); UCriteria.SHED_FEATHER.trigger(entity);
} }
} else { } else {
@ -442,6 +443,9 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
private void tickArtificialFlight(MutableVector velocity) { private void tickArtificialFlight(MutableVector velocity) {
if (ticksInAir % 10 == 0 && !entity.getWorld().isClient) { if (ticksInAir % 10 == 0 && !entity.getWorld().isClient) {
ItemStack stack = AmuletItem.getForEntity(entity); ItemStack stack = AmuletItem.getForEntity(entity);
if (ChargeableItem.getEnergy(stack) < 9) {
playSound(USounds.ITEM_ICARUS_WINGS_WARN, 0.13F, 0.5F);
}
int damageInterval = 20; int damageInterval = 20;
int minDamage = 1; int minDamage = 1;
@ -458,26 +462,21 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
ChargeableItem.consumeEnergy(stack, energyConsumed); ChargeableItem.consumeEnergy(stack, energyConsumed);
if (ChargeableItem.getEnergy(stack) < 9) {
entity.playSound(USounds.ITEM_ICARUS_WINGS_WARN, 0.13F, 0.5F);
}
if (entity.getWorld().random.nextInt(damageInterval) == 0) { if (entity.getWorld().random.nextInt(damageInterval) == 0) {
int damageLeft = stack.getMaxDamage() - stack.getDamage(); stack.damage(minDamage + entity.getWorld().random.nextInt(50), entity, e -> e.sendEquipmentBreakStatus(EquipmentSlot.CHEST));
int damageApplied = Math.min(damageLeft - 1, minDamage + entity.getWorld().random.nextInt(50));
if (damageApplied > 0) {
stack.damage(damageApplied, entity, e -> e.sendEquipmentBreakStatus(EquipmentSlot.CHEST));
}
} }
if (!getFlightType().canFly()) { if (!getFlightType().canFly()) {
entity.playSound(USounds.ITEM_ICARUS_WINGS_EXHAUSTED, 1, 2); playSound(USounds.ITEM_ICARUS_WINGS_EXHAUSTED, 1, 2);
cancelFlight(false); cancelFlight(false);
} }
} }
} }
private void playSound(SoundEvent sound, float volume, float pitch) {
entity.getWorld().playSoundFromEntity(null, entity, sound, SoundCategory.PLAYERS, volume, pitch);
}
private void tickNaturalFlight(MutableVector velocity) { private void tickNaturalFlight(MutableVector velocity) {
float level = pony.getLevel().getScaled(5) + 1; float level = pony.getLevel().getScaled(5) + 1;
@ -556,8 +555,6 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
thrustScale = 0; thrustScale = 0;
entity.calculateDimensions(); entity.calculateDimensions();
if (entity.isOnGround() || !force) { if (entity.isOnGround() || !force) {
Supplier<Vec3d> vec = VecHelper.sphere(pony.asWorld().getRandom(), 0.5D); Supplier<Vec3d> vec = VecHelper.sphere(pony.asWorld().getRandom(), 0.5D);
pony.spawnParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, vec, vec, 5); pony.spawnParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, vec, vec, 5);
@ -585,13 +582,13 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
wallHitCooldown = MAX_WALL_HIT_CALLDOWN; wallHitCooldown = MAX_WALL_HIT_CALLDOWN;
if (bouncyness > 0) { if (bouncyness > 0) {
entity.playSound(USounds.ENTITY_PLAYER_REBOUND, 1, entity.getSoundPitch()); playSound(USounds.ENTITY_PLAYER_REBOUND, 1, entity.getSoundPitch());
ProjectileUtil.ricochet(entity, Vec3d.of(pos), 0.4F + Math.min(2, bouncyness / 18F)); ProjectileUtil.ricochet(entity, Vec3d.of(pos), 0.4F + Math.min(2, bouncyness / 18F));
velocity.fromImmutable(entity.getVelocity()); velocity.fromImmutable(entity.getVelocity());
distance /= bouncyness; distance /= bouncyness;
} else { } else {
LivingEntity.FallSounds fallSounds = entity.getFallSounds(); LivingEntity.FallSounds fallSounds = entity.getFallSounds();
entity.playSound(distance > 4 ? fallSounds.big() : fallSounds.small(), 1, entity.getSoundPitch()); playSound(distance > 4 ? fallSounds.big() : fallSounds.small(), 1, entity.getSoundPitch());
} }
entity.damage(entity.getDamageSources().flyIntoWall(), distance); entity.damage(entity.getDamageSources().flyIntoWall(), distance);
} }
@ -645,7 +642,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
flapping = false; flapping = false;
if (!SpellPredicate.IS_DISGUISE.isOn(pony)) { if (!SpellPredicate.IS_DISGUISE.isOn(pony)) {
if (getFlightType() != FlightType.INSECTOID) { if (getFlightType() != FlightType.INSECTOID) {
entity.playSound(getFlightType().getWingFlapSound(), 0.25F, entity.getSoundPitch() * getFlightType().getWingFlapSoundPitch()); playSound(getFlightType().getWingFlapSound(), 0.25F, entity.getSoundPitch() * getFlightType().getWingFlapSoundPitch());
} }
entity.getWorld().emitGameEvent(entity, GameEvent.ELYTRA_GLIDE, entity.getPos()); entity.getWorld().emitGameEvent(entity, GameEvent.ELYTRA_GLIDE, entity.getPos());
} }
@ -761,9 +758,9 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
pony.updateVelocity(); pony.updateVelocity();
if (isFlying()) { if (isFlying()) {
pony.playSound(USounds.ENTITY_PLAYER_PEGASUS_DASH, 1); playSound(USounds.ENTITY_PLAYER_PEGASUS_DASH, 1, 1);
} else { } else {
pony.playSound(USounds.ENTITY_PLAYER_EARTHPONY_DASH, 2, 0.3F); playSound(USounds.ENTITY_PLAYER_EARTHPONY_DASH, 2, 0.3F);
} }
} }

View file

@ -27,7 +27,7 @@ public class PegasusAmuletItem extends AmuletItem implements ItemTracker.Trackab
@Override @Override
public boolean isApplicable(ItemStack stack) { public boolean isApplicable(ItemStack stack) {
return stack.getDamage() < stack.getMaxDamage() - 1 && super.isApplicable(stack); return super.isApplicable(stack);
} }
@Override @Override