Class SoundDefinition.Sound
- java.lang.Object
-
- net.minecraftforge.common.data.SoundDefinition.Sound
-
- Enclosing class:
- SoundDefinition
public static final class SoundDefinition.Sound extends java.lang.Object
Identifies a specific sound that has to be played in a sound event, along with all the necessary parameters.If any of the optional parameters (i.e. the ones that aren't required to obtain an instance of this class) are unset, their default values will be used instead. The list of defaults is available in the text that follows:
- Volume: 1.0F
- Pitch: 1.0F
- Weight: 1
- Stream: false
- Attenuation Distance: 16
- Preload: false
-
-
Field Summary
Fields Modifier and Type Field Description private int
attenuationDistance
private static int
DEFAULT_ATTENUATION_DISTANCE
private static float
DEFAULT_PITCH
private static boolean
DEFAULT_PRELOAD
private static boolean
DEFAULT_STREAM
private static SoundDefinition.SoundType
DEFAULT_TYPE
private static float
DEFAULT_VOLUME
private static int
DEFAULT_WEIGHT
private ResourceLocation
name
private float
pitch
private boolean
preload
private boolean
stream
private SoundDefinition.SoundType
type
private float
volume
private int
weight
-
Constructor Summary
Constructors Modifier Constructor Description private
Sound(ResourceLocation name, SoundDefinition.SoundType type)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SoundDefinition.Sound
attenuationDistance(int attenuationDistance)
Sets the attenuation distance of the sound.private boolean
canBeInShortForm()
(package private) ResourceLocation
name()
SoundDefinition.Sound
pitch(double pitch)
Sets the pitch of this specific sound.SoundDefinition.Sound
pitch(float pitch)
Sets the pitch of this specific sound.SoundDefinition.Sound
preload()
Marks this sound as needing to be preloaded.SoundDefinition.Sound
preload(boolean preload)
Sets whether this sound should be preloaded or not.(package private) com.google.gson.JsonElement
serialize()
static SoundDefinition.Sound
sound(ResourceLocation name, SoundDefinition.SoundType type)
Creates a new sound with the given name and type.SoundDefinition.Sound
stream()
Sets this sound to a streamed sound.SoundDefinition.Sound
stream(boolean stream)
Sets whether this sound should be streamed or not.private java.lang.String
stripMcPrefix(ResourceLocation name)
(package private) SoundDefinition.SoundType
type()
SoundDefinition.Sound
volume(double volume)
Sets the volume of this specific sound.SoundDefinition.Sound
volume(float volume)
Sets the volume of this specific sound.SoundDefinition.Sound
weight(int weight)
Sets the weight of this specific sound.
-
-
-
Field Detail
-
DEFAULT_TYPE
private static final SoundDefinition.SoundType DEFAULT_TYPE
-
DEFAULT_VOLUME
private static final float DEFAULT_VOLUME
- See Also:
- Constant Field Values
-
DEFAULT_PITCH
private static final float DEFAULT_PITCH
- See Also:
- Constant Field Values
-
DEFAULT_WEIGHT
private static final int DEFAULT_WEIGHT
- See Also:
- Constant Field Values
-
DEFAULT_STREAM
private static final boolean DEFAULT_STREAM
- See Also:
- Constant Field Values
-
DEFAULT_ATTENUATION_DISTANCE
private static final int DEFAULT_ATTENUATION_DISTANCE
- See Also:
- Constant Field Values
-
DEFAULT_PRELOAD
private static final boolean DEFAULT_PRELOAD
- See Also:
- Constant Field Values
-
name
private final ResourceLocation name
-
type
private final SoundDefinition.SoundType type
-
volume
private float volume
-
pitch
private float pitch
-
weight
private int weight
-
stream
private boolean stream
-
attenuationDistance
private int attenuationDistance
-
preload
private boolean preload
-
-
Constructor Detail
-
Sound
private Sound(ResourceLocation name, SoundDefinition.SoundType type)
-
-
Method Detail
-
sound
public static SoundDefinition.Sound sound(ResourceLocation name, SoundDefinition.SoundType type)
Creates a new sound with the given name and type.- Parameters:
name
- The name of the sound to create.type
- The type of sound to create.
-
volume
public SoundDefinition.Sound volume(double volume)
Sets the volume of this specific sound.The volume of a sound represents how loud the sound is when played.
- Parameters:
volume
- The volume to set. It must be higher than 0.- Returns:
- This sound for chaining.
-
volume
public SoundDefinition.Sound volume(float volume)
Sets the volume of this specific sound.The volume of a sound represents how loud the sound is when played.
- Parameters:
volume
- The volume to set. It must be higher than 0.- Returns:
- This sound for chaining.
-
pitch
public SoundDefinition.Sound pitch(double pitch)
Sets the pitch of this specific sound.The pitch of a sound represents how high or low the sound is when played.
- Parameters:
pitch
- The pitch to set. It must be higher than 0.- Returns:
- This sound for chaining.
-
pitch
public SoundDefinition.Sound pitch(float pitch)
Sets the pitch of this specific sound.The pitch of a sound represents how high or low the sound is when played.
- Parameters:
pitch
- The pitch to set. It must be higher than 0.- Returns:
- This sound for chaining.
-
weight
public SoundDefinition.Sound weight(int weight)
Sets the weight of this specific sound.The weight represents how likely it is for this sound to be played when the respective event is triggered. This value is ignored when there is only one sound per event.
- Parameters:
weight
- The weight to set. It must be higher than 0.- Returns:
- This sound for chaining.
-
stream
public SoundDefinition.Sound stream()
Sets this sound to a streamed sound.In this context, streaming refers to reading the file on disk as needed instead of loading the whole set in memory. This is useful in case of longer sounds, like records and music (usually more than a minute).
This is equivalent to a call to
stream(boolean)
with a value of true.- Returns:
- This sound for chaining
-
stream
public SoundDefinition.Sound stream(boolean stream)
Sets whether this sound should be streamed or not.In this context, streaming refers to reading the file on disk as needed instead of loading the whole set in memory. This is useful in case of longer sounds, like records and music (usually more than a minute).
- Parameters:
stream
- Whether the sound should be streamed or not.- Returns:
- This sound for chaining.
-
attenuationDistance
public SoundDefinition.Sound attenuationDistance(int attenuationDistance)
Sets the attenuation distance of the sound.This represents how far this sound will be heard, in blocks. While the specs don't require so, it is suggested to keep this value positive.
- Parameters:
attenuationDistance
- The attenuation distance to set.- Returns:
- This sound for chaining.
-
preload
public SoundDefinition.Sound preload()
Marks this sound as needing to be preloaded.A preloaded sound identifies a sound that is loaded in memory as soon as the resource pack is loaded, without having to wait for the sound to be ready to stream. It is suggested to keep this to
false
, unless you are using it for a highly recurring sound (e.g. underwater ambient sounds).This is equivalent to a call to
preload(boolean)
with a value of true.- Returns:
- This sound for chaining.
-
preload
public SoundDefinition.Sound preload(boolean preload)
Sets whether this sound should be preloaded or not.A preloaded sound identifies a sound that is loaded in memory as soon as the resource pack is loaded, without having to wait for the sound to be ready to stream. It is suggested to keep this to
false
, unless you are using it for a highly recurring sound (e.g. underwater ambient sounds).- Parameters:
preload
- Whether the sound should be preloaded or not.- Returns:
- This sound for chaining.
-
name
ResourceLocation name()
-
type
SoundDefinition.SoundType type()
-
serialize
com.google.gson.JsonElement serialize()
-
canBeInShortForm
private boolean canBeInShortForm()
-
stripMcPrefix
private java.lang.String stripMcPrefix(ResourceLocation name)
-
-