ElytraOnPlayerSoundInstance .java

net.minecraft.client.resources.sounds.ElytraOnPlayerSoundInstance (class, 55 lines): members: DELAY, time, player, tick. imports: LocalPlayer, SoundSource.

net.minecraft.client.resources.soundsclass55 linesclientextends AbstractTickableSoundInstance1.5 KB

API Surface (1)

void tick()

Fields & Constants (3)

DELAY
player
time

Code Graph: Dependencies (6)

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

Full Source

ElytraOnPlayerSoundInstance.java55 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.client.player.LocalPlayer;
6
import net.minecraft.sounds.SoundEvents;
7
import net.minecraft.sounds.SoundSource;
8
import net.minecraft.util.Mth;
9
10
@Environment(EnvType.CLIENT)
11
public class ElytraOnPlayerSoundInstance extends AbstractTickableSoundInstance {
12
	public static final int DELAY = 20;
13
	private final LocalPlayer player;
14
	private int time;
15
16
	public ElytraOnPlayerSoundInstance(final LocalPlayer player) {
17
		super(SoundEvents.ELYTRA_FLYING, SoundSource.PLAYERS, SoundInstance.createUnseededRandom());
18
		this.player = player;
19
		this.looping = true;
20
		this.delay = 0;
21
		this.volume = 0.1F;
22
	}
23
24
	@Override
25
	public void tick() {
26
		this.time++;
27
		if (!this.player.isRemoved() && (this.time <= 20 || this.player.isFallFlying())) {
28
			this.x = (float)this.player.getX();
29
			this.y = (float)this.player.getY();
30
			this.z = (float)this.player.getZ();
31
			float speed = (float)this.player.getDeltaMovement().lengthSqr();
32
			if (speed >= 1.0E-7) {
33
				this.volume = Mth.clamp(speed / 4.0F, 0.0F, 1.0F);
34
			} else {
35
				this.volume = 0.0F;
36
			}
37
38
			if (this.time < 20) {
39
				this.volume = 0.0F;
40
			} else if (this.time < 40) {
41
				this.volume = this.volume * ((this.time - 20) / 20.0F);
42
			}
43
44
			float pitchThreshold = 0.8F;
45
			if (this.volume > 0.8F) {
46
				this.pitch = 1.0F + (this.volume - 0.8F);
47
			} else {
48
				this.pitch = 1.0F;
49
			}
50
		} else {
51
			this.stop();
52
		}
53
	}
54
}
55

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