UnderLiquidAmbientSoundInstance .java

net.minecraft.client.resources.sounds.UnderLiquidAmbientSoundInstance (class): members: FADE_DURATION, isUnderLiquid, underwater, fade, player, tick.

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

API Surface (2)

UnderLiquidAmbientSoundInstance underwater(final LocalPlayer player)
void tick()

Fields & Constants (4)

FADE_DURATION
player
isUnderLiquid
fade

Code Graph: Dependencies (6)

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

Full Source

UnderLiquidAmbientSoundInstance.java48 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.resources.sounds;
2
3
import java.util.function.Predicate;
4
import net.fabricmc.api.EnvType;
5
import net.fabricmc.api.Environment;
6
import net.minecraft.client.player.LocalPlayer;
7
import net.minecraft.sounds.SoundEvent;
8
import net.minecraft.sounds.SoundEvents;
9
import net.minecraft.sounds.SoundSource;
10
11
@Environment(EnvType.CLIENT)
12
public class UnderLiquidAmbientSoundInstance extends AbstractTickableSoundInstance {
13
	public static final int FADE_DURATION = 40;
14
	private final LocalPlayer player;
15
	private final Predicate<LocalPlayer> isUnderLiquid;
16
	private int fade;
17
18
	public UnderLiquidAmbientSoundInstance(final SoundEvent event, final LocalPlayer player, final Predicate<LocalPlayer> isUnderLiquid) {
19
		super(event, SoundSource.AMBIENT, SoundInstance.createUnseededRandom());
20
		this.player = player;
21
		this.isUnderLiquid = isUnderLiquid;
22
		this.looping = true;
23
		this.delay = 0;
24
		this.volume = 1.0F;
25
		this.relative = true;
26
	}
27
28
	public static UnderLiquidAmbientSoundInstance underwater(final LocalPlayer player) {
29
		return new UnderLiquidAmbientSoundInstance(SoundEvents.AMBIENT_UNDERWATER_LOOP, player, LocalPlayer::isUnderWater);
30
	}
31
32
	@Override
33
	public void tick() {
34
		if (!this.player.isRemoved() && this.fade >= 0) {
35
			if (this.isUnderLiquid.test(this.player)) {
36
				this.fade++;
37
			} else {
38
				this.fade -= 2;
39
			}
40
41
			this.fade = Math.min(this.fade, 40);
42
			this.volume = Math.max(0.0F, Math.min(this.fade / 40.0F, 1.0F));
43
		} else {
44
			this.stop();
45
		}
46
	}
47
}
48

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