UnderwaterAmbientSoundHandler .java

net.minecraft.client.resources.sounds.UnderwaterAmbientSoundHandler (class, 42 lines): members: ULTRA_RARE_CHANCE_PER_TICK, RARE_CHANCE_PER_TICK, player.

net.minecraft.client.resources.soundsclass42 linesclient1.5 KB

Implements

API Surface (1)

void tick()

Fields & Constants (7)

CHANCE_PER_TICK
RARE_CHANCE_PER_TICK
ULTRA_RARE_CHANCE_PER_TICK
MINIMUM_TICK_DELAY
player
soundManager
tickDelay

Code Graph: Dependencies (4)

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

Full Source

UnderwaterAmbientSoundHandler.java42 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.client.sounds.SoundManager;
7
import net.minecraft.sounds.SoundEvents;
8
9
@Environment(EnvType.CLIENT)
10
public class UnderwaterAmbientSoundHandler implements AmbientSoundHandler {
11
	public static final float CHANCE_PER_TICK = 0.01F;
12
	public static final float RARE_CHANCE_PER_TICK = 0.001F;
13
	public static final float ULTRA_RARE_CHANCE_PER_TICK = 1.0E-4F;
14
	private static final int MINIMUM_TICK_DELAY = 0;
15
	private final LocalPlayer player;
16
	private final SoundManager soundManager;
17
	private int tickDelay = 0;
18
19
	public UnderwaterAmbientSoundHandler(final LocalPlayer player, final SoundManager soundManager) {
20
		this.player = player;
21
		this.soundManager = soundManager;
22
	}
23
24
	@Override
25
	public void tick() {
26
		this.tickDelay--;
27
		if (this.tickDelay <= 0 && this.player.isUnderWater()) {
28
			float rand = this.player.level().getRandom().nextFloat();
29
			if (rand < 1.0E-4F) {
30
				this.tickDelay = 0;
31
				this.soundManager.play(new UnderLiquidSubSound(this.player, SoundEvents.AMBIENT_UNDERWATER_LOOP_ADDITIONS_ULTRA_RARE));
32
			} else if (rand < 0.001F) {
33
				this.tickDelay = 0;
34
				this.soundManager.play(new UnderLiquidSubSound(this.player, SoundEvents.AMBIENT_UNDERWATER_LOOP_ADDITIONS_RARE));
35
			} else if (rand < 0.01F) {
36
				this.tickDelay = 0;
37
				this.soundManager.play(new UnderLiquidSubSound(this.player, SoundEvents.AMBIENT_UNDERWATER_LOOP_ADDITIONS));
38
			}
39
		}
40
	}
41
}
42

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