Table of Contents

Struct SoundAttributes

Namespace
Vintagestory.API.Common
Assembly
VintagestoryAPI.dll

Properties that control how a sound is played. There are two forms of this that might be used in JSON files: Form 1 is simply stored as an AssetLocation that points to the sound file path. There are no extra proprties. This is what most JSON objects use. Form 2 is more complex, and uses the properties below to fully configure the sound. Only certain JSON objects use this, such as entity sounds. You can mix and match in a single sound array.

[DocumentAsJson]
public struct SoundAttributes
Inherited Members
Extension Methods

Examples

Form 1:

"sounds": {
"place": "block/plant",
"break": "block/plant",
"hit": "block/plant"
},
Form 2. Note that entity sounds can include * at the end for multiple sound files:
"sounds": {
"hurt": "creature/chicken/chick*",
"death": "creature/chicken/chick*",
"idle": {
"path": "creature/chicken/chick*",
"range": 14,
"pitch": {
"avg": 1,
"var": 0.25
}
}
},

Constructors

SoundAttributes()

public SoundAttributes()

SoundAttributes(AssetLocation, bool)

public SoundAttributes(AssetLocation assetLocation, bool withRandomPitch)

Parameters

assetLocation AssetLocation
withRandomPitch bool

Fields

Location

The location of the sound file.

[DocumentAsJson("Required", "", false)]
[JsonProperty("path")]
public AssetLocation? Location

Field Value

AssetLocation

NatFloatOne

public static NatFloat NatFloatOne

Field Value

NatFloat

Pitch

Controls a random pitch for when the sound is played.

[DocumentAsJson("Optional", "1", false)]
public NatFloat Pitch

Field Value

NatFloat

RandomPitch

public static NatFloat RandomPitch

Field Value

NatFloat

Range

The range at which the gain will be attenuated to 1% of the supplied volume. (i.e. the maximum range that the player will hear the sound)

[DocumentAsJson("Optional", "32", false)]
public float Range

Field Value

float

Type

The type of sound, used for volume control in the settings.

[DocumentAsJson("Optional", "Sound", false)]
[JsonProperty("soundType")]
public EnumSoundType Type

Field Value

EnumSoundType

Volume

Controls a random volume for when the sound is played.

[DocumentAsJson("Optional", "1", false)]
public NatFloat Volume

Field Value

NatFloat

Methods

Clone()

public SoundAttributes Clone()

Returns

SoundAttributes

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

Equals(SoundAttributes)

public bool Equals(SoundAttributes other)

Parameters

other SoundAttributes

Returns

bool

FromBytes(BinaryReader, string)

public static SoundAttributes FromBytes(BinaryReader reader, string version)

Parameters

reader BinaryReader
version string

Returns

SoundAttributes

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

ToBytes(BinaryWriter)

public void ToBytes(BinaryWriter writer)

Parameters

writer BinaryWriter

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

Operators

operator ==(SoundAttributes?, SoundAttributes?)

public static bool operator ==(SoundAttributes? left, SoundAttributes? right)

Parameters

left SoundAttributes?
right SoundAttributes?

Returns

bool

operator !=(SoundAttributes?, SoundAttributes?)

public static bool operator !=(SoundAttributes? left, SoundAttributes? right)

Parameters

left SoundAttributes?
right SoundAttributes?

Returns

bool