BeeSoundInstance .java

net.minecraft.client.resources.sounds.BeeSoundInstance (class, 77 lines): members: hasSwitched, bee, getAlternativeSoundInstance, shouldSwitchSounds, tick.

net.minecraft.client.resources.soundsclass77 linesclientextends AbstractTickableSoundInstance2.2 KB

API Surface (3)

void tick()
boolean canStartSilent()
boolean canPlaySound()

Fields & Constants (5)

VOLUME_MIN
VOLUME_MAX
PITCH_MIN
bee
hasSwitched

Code Graph: Dependencies (7)

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

Full Source

BeeSoundInstance.java77 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.Minecraft;
6
import net.minecraft.sounds.SoundEvent;
7
import net.minecraft.sounds.SoundSource;
8
import net.minecraft.util.Mth;
9
import net.minecraft.world.entity.animal.bee.Bee;
10
11
@Environment(EnvType.CLIENT)
12
public abstract class BeeSoundInstance extends AbstractTickableSoundInstance {
13
	private static final float VOLUME_MIN = 0.0F;
14
	private static final float VOLUME_MAX = 1.2F;
15
	private static final float PITCH_MIN = 0.0F;
16
	protected final Bee bee;
17
	private boolean hasSwitched;
18
19
	public BeeSoundInstance(final Bee bee, final SoundEvent event, final SoundSource source) {
20
		super(event, source, SoundInstance.createUnseededRandom());
21
		this.bee = bee;
22
		this.x = (float)bee.getX();
23
		this.y = (float)bee.getY();
24
		this.z = (float)bee.getZ();
25
		this.looping = true;
26
		this.delay = 0;
27
		this.volume = 0.0F;
28
	}
29
30
	@Override
31
	public void tick() {
32
		boolean shouldSwitchSounds = this.shouldSwitchSounds();
33
		if (shouldSwitchSounds && !this.isStopped()) {
34
			Minecraft.getInstance().getSoundManager().queueTickingSound(this.getAlternativeSoundInstance());
35
			this.hasSwitched = true;
36
		}
37
38
		if (!this.bee.isRemoved() && !this.hasSwitched) {
39
			this.x = (float)this.bee.getX();
40
			this.y = (float)this.bee.getY();
41
			this.z = (float)this.bee.getZ();
42
			float speed = (float)this.bee.getDeltaMovement().horizontalDistance();
43
			if (speed >= 0.01F) {
44
				this.pitch = Mth.lerp(Mth.clamp(speed, this.getMinPitch(), this.getMaxPitch()), this.getMinPitch(), this.getMaxPitch());
45
				this.volume = Mth.lerp(Mth.clamp(speed, 0.0F, 0.5F), 0.0F, 1.2F);
46
			} else {
47
				this.pitch = 0.0F;
48
				this.volume = 0.0F;
49
			}
50
		} else {
51
			this.stop();
52
		}
53
	}
54
55
	private float getMinPitch() {
56
		return this.bee.isBaby() ? 1.1F : 0.7F;
57
	}
58
59
	private float getMaxPitch() {
60
		return this.bee.isBaby() ? 1.5F : 1.1F;
61
	}
62
63
	@Override
64
	public boolean canStartSilent() {
65
		return true;
66
	}
67
68
	@Override
69
	public boolean canPlaySound() {
70
		return !this.bee.isSilent();
71
	}
72
73
	protected abstract AbstractTickableSoundInstance getAlternativeSoundInstance();
74
75
	protected abstract boolean shouldSwitchSounds();
76
}
77

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