Class SoundDefinition.Sound

java.lang.Object
net.minecraftforge.common.data.SoundDefinition.Sound
Enclosing class:
SoundDefinition

public static final class SoundDefinition.Sound extends 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 Details

  • Constructor Details

  • Method Details

    • sound

      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

    • type

    • serialize

      com.google.gson.JsonElement serialize()
    • canBeInShortForm

      private boolean canBeInShortForm()
    • stripMcPrefix

      private String stripMcPrefix(ResourceLocation name)