58 lines
1.9 KiB
Java
58 lines
1.9 KiB
Java
package net.minecraft.client.resources.sounds;
|
|
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.minecraft.client.resources.sounds.SoundInstance.Attenuation;
|
|
import net.minecraft.sounds.SoundEvents;
|
|
import net.minecraft.sounds.SoundSource;
|
|
import net.minecraft.util.Mth;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.entity.vehicle.AbstractMinecart;
|
|
import net.minecraft.world.entity.vehicle.NewMinecartBehavior;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public class RidingMinecartSoundInstance extends AbstractTickableSoundInstance {
|
|
private static final float VOLUME_MIN = 0.0F;
|
|
private static final float VOLUME_MAX = 0.75F;
|
|
private final Player player;
|
|
private final AbstractMinecart minecart;
|
|
private final boolean underwaterSound;
|
|
|
|
public RidingMinecartSoundInstance(Player player, AbstractMinecart minecart, boolean underwaterSound) {
|
|
super(underwaterSound ? SoundEvents.MINECART_INSIDE_UNDERWATER : SoundEvents.MINECART_INSIDE, SoundSource.NEUTRAL, SoundInstance.createUnseededRandom());
|
|
this.player = player;
|
|
this.minecart = minecart;
|
|
this.underwaterSound = underwaterSound;
|
|
this.attenuation = Attenuation.NONE;
|
|
this.looping = true;
|
|
this.delay = 0;
|
|
this.volume = 0.0F;
|
|
}
|
|
|
|
@Override
|
|
public boolean canPlaySound() {
|
|
return !this.minecart.isSilent();
|
|
}
|
|
|
|
@Override
|
|
public boolean canStartSilent() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void tick() {
|
|
if (this.minecart.isRemoved() || !this.player.isPassenger() || this.player.getVehicle() != this.minecart) {
|
|
this.stop();
|
|
} else if (this.underwaterSound != this.player.isUnderWater()) {
|
|
this.volume = 0.0F;
|
|
} else {
|
|
float f = (float)this.minecart.getDeltaMovement().horizontalDistance();
|
|
boolean bl = !this.minecart.isOnRails() && this.minecart.getBehavior() instanceof NewMinecartBehavior;
|
|
if (f >= 0.01F && !bl) {
|
|
this.volume = Mth.clampedLerp(0.0F, 0.75F, f);
|
|
} else {
|
|
this.volume = 0.0F;
|
|
}
|
|
}
|
|
}
|
|
}
|