RidingEntitySoundInstance .java

net.minecraft.client.resources.sounds.RidingEntitySoundInstance (class): members: volumeAmplifier, shouldNotPlayUnderwaterSound, shoudlPlaySound, entity.

net.minecraft.client.resources.soundsclass88 linesclientextends AbstractTickableSoundInstance2.3 KB

API Surface (6)

boolean canPlaySound()
boolean canStartSilent()
boolean shouldNotPlayUnderwaterSound()
float getEntitySpeed()
boolean shoudlPlaySound()
void tick()

Fields & Constants (8)

player
entity
underwaterSound
volumeMin
volumeMax
volumeAmplifier
soundEvent
soundSource

Code Graph: Dependencies (7)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

RidingEntitySoundInstance.java88 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.resources.sounds;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.sounds.SoundEvent;
6
import net.minecraft.sounds.SoundSource;
7
import net.minecraft.util.Mth;
8
import net.minecraft.world.entity.Entity;
9
import net.minecraft.world.entity.player.Player;
10
11
@Environment(EnvType.CLIENT)
12
public class RidingEntitySoundInstance extends AbstractTickableSoundInstance {
13
	private final Player player;
14
	private final Entity entity;
15
	private final boolean underwaterSound;
16
	private final float volumeMin;
17
	private final float volumeMax;
18
	private final float volumeAmplifier;
19
20
	public RidingEntitySoundInstance(
21
		final Player player,
22
		final Entity entity,
23
		final boolean underwaterSound,
24
		final SoundEvent soundEvent,
25
		final SoundSource soundSource,
26
		final float volumeMin,
27
		final float volumeMax,
28
		final float volumeAmplifier
29
	) {
30
		super(soundEvent, soundSource, SoundInstance.createUnseededRandom());
31
		this.player = player;
32
		this.entity = entity;
33
		this.x = entity.getX();
34
		this.y = entity.getY();
35
		this.z = entity.getZ();
36
		this.underwaterSound = underwaterSound;
37
		this.volumeMin = volumeMin;
38
		this.volumeMax = volumeMax;
39
		this.volumeAmplifier = volumeAmplifier;
40
		this.attenuation = SoundInstance.Attenuation.NONE;
41
		this.looping = true;
42
		this.delay = 0;
43
		this.volume = volumeMin;
44
	}
45
46
	@Override
47
	public boolean canPlaySound() {
48
		return !this.entity.isSilent();
49
	}
50
51
	@Override
52
	public boolean canStartSilent() {
53
		return true;
54
	}
55
56
	protected boolean shouldNotPlayUnderwaterSound() {
57
		return this.underwaterSound != this.entity.isUnderWater();
58
	}
59
60
	protected float getEntitySpeed() {
61
		return (float)this.entity.getDeltaMovement().length();
62
	}
63
64
	protected boolean shoudlPlaySound() {
65
		return true;
66
	}
67
68
	@Override
69
	public void tick() {
70
		if (this.entity.isRemoved() || !this.player.isPassenger() || this.player.getVehicle() != this.entity) {
71
			this.stop();
72
		} else if (this.shouldNotPlayUnderwaterSound()) {
73
			this.volume = this.volumeMin;
74
		} else {
75
			float speed = this.getEntitySpeed();
76
			if (speed >= 0.01F && this.shoudlPlaySound()) {
77
				this.volume = this.volumeAmplifier * Mth.clampedLerp(speed, this.volumeMin, this.volumeMax);
78
			} else {
79
				this.volume = this.volumeMin;
80
			}
81
82
			this.x = this.entity.getX();
83
			this.y = this.entity.getY();
84
			this.z = this.entity.getZ();
85
		}
86
	}
87
}
88

Decompiled Minecraft 26.3 source of RidingEntitySoundInstance (net/minecraft/client/resources/sounds/RidingEntitySoundInstance.java) with Mojang official mappings, stored verbatim on the site.