SoundEventAccessorComposite .java

net.minecraft.client.audio.SoundEventAccessorComposite (class): members: getSoundEventLocation, addSoundToEventPool, soundLocation, eventVolume, soundPool.

net.minecraft.client.audioclass81 linesclient2.3 KB

Implements

API Surface (5)

int getWeight()
SoundPoolEntry cloneEntry()
void addSoundToEventPool(ISoundEventAccessor<SoundPoolEntry> sound)
ResourceLocation getSoundEventLocation()
SoundCategory getSoundCategory()

Fields & Constants (6)

soundPool
rnd
soundLocation
category
eventPitch
eventVolume

Code Graph: Dependencies (4)

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

Full Source

SoundEventAccessorComposite.java81 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.audio;
2
3
import com.google.common.collect.Lists;
4
import java.util.List;
5
import java.util.Random;
6
import net.minecraft.util.ResourceLocation;
7
8
public class SoundEventAccessorComposite implements ISoundEventAccessor<SoundPoolEntry>
9
{
10
    private final List<ISoundEventAccessor<SoundPoolEntry>> soundPool = Lists.<ISoundEventAccessor<SoundPoolEntry>>newArrayList();
11
    private final Random rnd = new Random();
12
    private final ResourceLocation soundLocation;
13
    private final SoundCategory category;
14
    private double eventPitch;
15
    private double eventVolume;
16
17
    public SoundEventAccessorComposite(ResourceLocation soundLocation, double pitch, double volume, SoundCategory category)
18
    {
19
        this.soundLocation = soundLocation;
20
        this.eventVolume = volume;
21
        this.eventPitch = pitch;
22
        this.category = category;
23
    }
24
25
    public int getWeight()
26
    {
27
        int i = 0;
28
29
        for (ISoundEventAccessor<SoundPoolEntry> isoundeventaccessor : this.soundPool)
30
        {
31
            i += isoundeventaccessor.getWeight();
32
        }
33
34
        return i;
35
    }
36
37
    public SoundPoolEntry cloneEntry()
38
    {
39
        int i = this.getWeight();
40
41
        if (!this.soundPool.isEmpty() && i != 0)
42
        {
43
            int j = this.rnd.nextInt(i);
44
45
            for (ISoundEventAccessor<SoundPoolEntry> isoundeventaccessor : this.soundPool)
46
            {
47
                j -= isoundeventaccessor.getWeight();
48
49
                if (j < 0)
50
                {
51
                    SoundPoolEntry soundpoolentry = (SoundPoolEntry)isoundeventaccessor.cloneEntry();
52
                    soundpoolentry.setPitch(soundpoolentry.getPitch() * this.eventPitch);
53
                    soundpoolentry.setVolume(soundpoolentry.getVolume() * this.eventVolume);
54
                    return soundpoolentry;
55
                }
56
            }
57
58
            return SoundHandler.missing_sound;
59
        }
60
        else
61
        {
62
            return SoundHandler.missing_sound;
63
        }
64
    }
65
66
    public void addSoundToEventPool(ISoundEventAccessor<SoundPoolEntry> sound)
67
    {
68
        this.soundPool.add(sound);
69
    }
70
71
    public ResourceLocation getSoundEventLocation()
72
    {
73
        return this.soundLocation;
74
    }
75
76
    public SoundCategory getSoundCategory()
77
    {
78
        return this.category;
79
    }
80
}
81

Deobfuscated MCP 1.8.9 source of SoundEventAccessorComposite from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/audio/SoundEventAccessorComposite.java), stored verbatim.