mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-17 10:24:23 +01:00
Added a background sound effect when flying as a pegasus
This commit is contained in:
parent
ab442461d3
commit
4c3831fb8a
4 changed files with 69 additions and 0 deletions
|
@ -19,6 +19,7 @@ public class InteractionManager {
|
|||
public static final int SOUND_CHANGELING_BUZZ = 1;
|
||||
public static final int SOUND_BEE = 2;
|
||||
public static final int SOUND_MINECART = 3;
|
||||
public static final int SOUND_GLIDING = 4;
|
||||
|
||||
public static InteractionManager INSTANCE = new InteractionManager();
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.minelittlepony.unicopia.FlightType;
|
|||
import com.minelittlepony.unicopia.InteractionManager;
|
||||
import com.minelittlepony.unicopia.USounds;
|
||||
import com.minelittlepony.unicopia.client.sound.LoopingSoundInstance;
|
||||
import com.minelittlepony.unicopia.client.sound.MotionBasedSoundInstance;
|
||||
import com.minelittlepony.unicopia.entity.effect.SunBlindnessStatusEffect;
|
||||
import com.minelittlepony.unicopia.entity.player.PlayerPhysics;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
|
@ -27,6 +28,7 @@ import net.minecraft.entity.LivingEntity;
|
|||
import net.minecraft.entity.passive.BeeEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ClientInteractionManager extends InteractionManager {
|
||||
|
@ -64,6 +66,8 @@ public class ClientInteractionManager extends InteractionManager {
|
|||
PlayerPhysics physics = Pony.of(e).getPhysics();
|
||||
return physics.isFlying() && physics.getFlightType() == FlightType.INSECTOID;
|
||||
}, USounds.ENTITY_PLAYER_CHANGELING_BUZZ, 1F, 1F));
|
||||
} else if (type == SOUND_GLIDING && source instanceof PlayerEntity) {
|
||||
soundManager.play(new MotionBasedSoundInstance(SoundEvents.ITEM_ELYTRA_FLYING, (PlayerEntity)source));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package com.minelittlepony.unicopia.client.sound;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
public class MotionBasedSoundInstance extends FadeOutSoundInstance {
|
||||
|
||||
private final PlayerEntity player;
|
||||
|
||||
private int tickCount;
|
||||
|
||||
public MotionBasedSoundInstance(SoundEvent sound, PlayerEntity player) {
|
||||
super(sound, player.getSoundCategory(), 0.1F);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldKeepPlaying() {
|
||||
++tickCount;
|
||||
|
||||
if (player.isRemoved() || tickCount > 200) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Pony pony = Pony.of(player);
|
||||
|
||||
if (!pony.getPhysics().isFlying() || !pony.getPhysics().getFlightType().isAvian()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
x = ((float)player.getX());
|
||||
y = ((float)player.getY());
|
||||
z = ((float)this.player.getZ());
|
||||
|
||||
float f = (float)player.getVelocity().lengthSquared();
|
||||
if (f >= 1.0E-7D) {
|
||||
volume = MathHelper.clamp(f / 4F, 0, 1);
|
||||
} else {
|
||||
volume = 0.0F;
|
||||
}
|
||||
|
||||
if (tickCount < 20) {
|
||||
volume = 0;
|
||||
} else if (tickCount < 40) {
|
||||
volume = (float)(volume * ((tickCount - 20) / 20D));
|
||||
}
|
||||
|
||||
if (volume > 0.8F) {
|
||||
pitch = 1 + (volume - 0.8F);
|
||||
} else {
|
||||
pitch = 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -304,6 +304,11 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
|
|||
flapping = true;
|
||||
ticksToGlide = 20;
|
||||
}
|
||||
|
||||
if (ticksInAir % 200 == 1) {
|
||||
InteractionManager.instance().playLoopingSound(entity, InteractionManager.SOUND_GLIDING);
|
||||
}
|
||||
|
||||
velocity.y -= 0.02 * getGravitySignum();
|
||||
velocity.x *= 0.9896;
|
||||
velocity.z *= 0.9896;
|
||||
|
|
Loading…
Reference in a new issue