Record Class SoundContext

java.lang.Object
java.lang.Record
dev.jaxydog.astral.content.sound.SoundContext
Record Components:
event - The sound event.
category - The sound category.
volume - The sound volume.
pitch - The sound pitch.
pitchVariance - The amount of variation in the sound pitch.

public record SoundContext(net.minecraft.sound.SoundEvent event, net.minecraft.sound.SoundCategory category, float volume, float pitch, float pitchVariance) extends Record
A sound context.

This is most useful for playing sounds that generally share the same traits without repeating code.

Since:
2.0.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final SoundContext
    A player's burping sound.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SoundContext(net.minecraft.sound.SoundEvent event, net.minecraft.sound.SoundCategory category)
    A sound context.
    SoundContext(net.minecraft.sound.SoundEvent event, net.minecraft.sound.SoundCategory category, float pitch)
    A sound context.
    SoundContext(net.minecraft.sound.SoundEvent event, net.minecraft.sound.SoundCategory category, float volume, float pitch)
    A sound context.
    SoundContext(net.minecraft.sound.SoundEvent event, net.minecraft.sound.SoundCategory category, float volume, float pitch, float pitchVariance)
    Creates an instance of a SoundContext record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    net.minecraft.sound.SoundCategory
    Returns the value of the category record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    net.minecraft.sound.SoundEvent
    Returns the value of the event record component.
    final int
    Returns a hash code value for this object.
    float
    Returns the value of the pitch record component.
    float
    pitch(net.minecraft.util.math.random.Random random)
    Returns the sound pitch with a random variance applied.
    float
    Returns the value of the pitchVariance record component.
    void
    play(net.minecraft.world.World world, double x, double y, double z)
    Plays a sound at the provided position within the world.
    void
    play(net.minecraft.world.World world, net.minecraft.entity.Entity entity)
    Plays a sound centered on the provided entity.
    void
    play(net.minecraft.world.World world, net.minecraft.util.math.BlockPos blockPos)
    Plays a sound centered on the provided block position.
    void
    play(net.minecraft.world.World world, net.minecraft.util.math.BlockPos blockPos, boolean useDistance)
    Plays a sound centered on the provided block position.
    void
    play(net.minecraft.world.World world, net.minecraft.util.math.Vec3d position)
    Plays a sound at the provided position within the world.
    final String
    Returns a string representation of this record class.
    float
    Returns the value of the volume record component.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • BURP

      public static final SoundContext BURP
      A player's burping sound.
      Since:
      2.0.0
  • Constructor Details

    • SoundContext

      public SoundContext(net.minecraft.sound.SoundEvent event, net.minecraft.sound.SoundCategory category, float volume, float pitch)
      A sound context.

      This is most useful for playing sounds that generally share the same traits without repeating code.

      By default, a pitch variance of 0.625F is used.

      Parameters:
      event - The sound event.
      category - The sound category.
      volume - The sound volume.
      pitch - The sound pitch.
      Since:
      2.0.0
    • SoundContext

      public SoundContext(net.minecraft.sound.SoundEvent event, net.minecraft.sound.SoundCategory category, float pitch)
      A sound context.

      This is most useful for playing sounds that generally share the same traits without repeating code.

      By default, a volume of 1F and a pitch variance of 0.625F is used.

      Parameters:
      event - The sound event.
      category - The sound category.
      pitch - The sound pitch.
      Since:
      2.0.0
    • SoundContext

      public SoundContext(net.minecraft.sound.SoundEvent event, net.minecraft.sound.SoundCategory category)
      A sound context.

      This is most useful for playing sounds that generally share the same traits without repeating code.

      By default, a volume of 1F, a pitch of 1F, and a pitch variance of 0.625F is used.

      Parameters:
      event - The sound event.
      category - The sound category.
      Since:
      2.0.0
    • SoundContext

      public SoundContext(net.minecraft.sound.SoundEvent event, net.minecraft.sound.SoundCategory category, float volume, float pitch, float pitchVariance)
      Creates an instance of a SoundContext record class.
      Parameters:
      event - the value for the event record component
      category - the value for the category record component
      volume - the value for the volume record component
      pitch - the value for the pitch record component
      pitchVariance - the value for the pitchVariance record component
  • Method Details

    • pitch

      public float pitch(net.minecraft.util.math.random.Random random)
      Returns the sound pitch with a random variance applied.
      Parameters:
      random - A random number generator.
      Returns:
      A varied pitch.
      Since:
      2.0.0
    • play

      public void play(net.minecraft.world.World world, double x, double y, double z)
      Plays a sound at the provided position within the world.
      Parameters:
      world - The world.
      x - The X position.
      y - The Y position.
      z - The Z position.
      Since:
      2.0.0
    • play

      public void play(net.minecraft.world.World world, net.minecraft.util.math.Vec3d position)
      Plays a sound at the provided position within the world.
      Parameters:
      world - The world.
      position - The position.
      Since:
      2.0.0
    • play

      public void play(net.minecraft.world.World world, net.minecraft.entity.Entity entity)
      Plays a sound centered on the provided entity.
      Parameters:
      world - The world.
      entity - The entity.
      Since:
      2.0.0
    • play

      public void play(net.minecraft.world.World world, net.minecraft.util.math.BlockPos blockPos, boolean useDistance)
      Plays a sound centered on the provided block position.
      Parameters:
      world - The world.
      blockPos - The position.
      useDistance - Whether to use distance to determine if the sound should be played.
      Since:
      2.0.0
    • play

      public void play(net.minecraft.world.World world, net.minecraft.util.math.BlockPos blockPos)
      Plays a sound centered on the provided block position.
      Parameters:
      world - The world.
      blockPos - The position.
      Since:
      2.0.0
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • event

      public net.minecraft.sound.SoundEvent event()
      Returns the value of the event record component.
      Returns:
      the value of the event record component
    • category

      public net.minecraft.sound.SoundCategory category()
      Returns the value of the category record component.
      Returns:
      the value of the category record component
    • volume

      public float volume()
      Returns the value of the volume record component.
      Returns:
      the value of the volume record component
    • pitch

      public float pitch()
      Returns the value of the pitch record component.
      Returns:
      the value of the pitch record component
    • pitchVariance

      public float pitchVariance()
      Returns the value of the pitchVariance record component.
      Returns:
      the value of the pitchVariance record component