Spaces:
Build error
Build error
File size: 2,306 Bytes
d46f4a3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
package net.minecraft.client.resources.sounds;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.entity.vehicle.NewMinecartBehavior;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class MinecartSoundInstance extends AbstractTickableSoundInstance {
private static final float VOLUME_MIN = 0.0F;
private static final float VOLUME_MAX = 0.7F;
private static final float PITCH_MIN = 0.0F;
private static final float PITCH_MAX = 1.0F;
private static final float PITCH_DELTA = 0.0025F;
private final AbstractMinecart minecart;
private float pitch = 0.0F;
public MinecartSoundInstance(AbstractMinecart p_119696_) {
super(SoundEvents.MINECART_RIDING, SoundSource.NEUTRAL, SoundInstance.createUnseededRandom());
this.minecart = p_119696_;
this.looping = true;
this.delay = 0;
this.volume = 0.0F;
this.x = (double)((float)p_119696_.getX());
this.y = (double)((float)p_119696_.getY());
this.z = (double)((float)p_119696_.getZ());
}
@Override
public boolean canPlaySound() {
return !this.minecart.isSilent();
}
@Override
public boolean canStartSilent() {
return true;
}
@Override
public void tick() {
if (this.minecart.isRemoved()) {
this.stop();
} else {
this.x = (double)((float)this.minecart.getX());
this.y = (double)((float)this.minecart.getY());
this.z = (double)((float)this.minecart.getZ());
float f = (float)this.minecart.getDeltaMovement().horizontalDistance();
boolean flag = !this.minecart.isOnRails() && this.minecart.getBehavior() instanceof NewMinecartBehavior;
if (f >= 0.01F && this.minecart.level().tickRateManager().runsNormally() && !flag) {
this.pitch = Mth.clamp(this.pitch + 0.0025F, 0.0F, 1.0F);
this.volume = Mth.lerp(Mth.clamp(f, 0.0F, 0.5F), 0.0F, 0.7F);
} else {
this.pitch = 0.0F;
this.volume = 0.0F;
}
}
}
} |