Sounds on the client
This commit is contained in:
@@ -9,6 +9,7 @@ import type {
|
||||
ItemStack,
|
||||
KeyCode,
|
||||
ModInfo,
|
||||
PlayOptions,
|
||||
Position,
|
||||
RecipeLookup,
|
||||
Season,
|
||||
@@ -24,6 +25,7 @@ export type {
|
||||
ItemStack,
|
||||
KeyCode,
|
||||
ModInfo,
|
||||
PlayOptions,
|
||||
Position,
|
||||
Season,
|
||||
TagApi,
|
||||
@@ -124,9 +126,39 @@ export interface ClientContext {
|
||||
tags: TagApi;
|
||||
// blocks drawn with code, like a shaft that turns, see docs/modding/blocks/visuals.md
|
||||
render: ClientRender;
|
||||
// sounds from the mods' sounds.json, played on this client only, see docs/modding/resources/sounds.md
|
||||
sounds: ClientSounds;
|
||||
log(...args: unknown[]): void;
|
||||
}
|
||||
|
||||
export interface ClientSounds {
|
||||
// plays a sound on this client. without at or follow it's heard as it is wherever the player is, like a click in a
|
||||
// screen. throws for a sound no mod defines
|
||||
play(sound: Id, options?: ClientPlayOptions): PlayingSound;
|
||||
exists(sound: Id): boolean;
|
||||
}
|
||||
|
||||
export interface ClientPlayOptions extends PlayOptions {
|
||||
// where it comes from, fading out with distance until its range
|
||||
at?: Position;
|
||||
// an entity's id: it moves with the entity, and stops when the entity goes
|
||||
follow?: string;
|
||||
// plays again from the start until it's stopped. one out of the player's range waits silently, and comes back in
|
||||
// as far into the file as it would have got
|
||||
loop?: boolean;
|
||||
}
|
||||
|
||||
// a sound ctx.sounds.play started
|
||||
export interface PlayingSound {
|
||||
// false once it finished, was stopped, or what it followed went. a sound that couldn't play at all, like one
|
||||
// played out of range or before the player first clicked, is never playing, unless it loops
|
||||
readonly playing: boolean;
|
||||
stop(): void;
|
||||
// what play was given, changed while it plays, like a machine speeding up
|
||||
volume: number;
|
||||
pitch: number;
|
||||
}
|
||||
|
||||
export interface ClientRender {
|
||||
// every block of this id gets a visual from create while its chunk is shown, like a block entity renderer or
|
||||
// flywheel's visuals. only during setup, and one per block. replaces_model leaves the block's model out of the
|
||||
|
||||
@@ -116,6 +116,14 @@ export interface Position {
|
||||
z: number;
|
||||
}
|
||||
|
||||
// how a sound plays, on top of what its definition in sounds.json says. see docs/modding/resources/sounds.md
|
||||
export interface PlayOptions {
|
||||
// multiplies the sound's own. over 1 it's heard further away, not louder
|
||||
volume?: number;
|
||||
// multiplies the sound's own: 2 is an octave up and twice as fast
|
||||
pitch?: number;
|
||||
}
|
||||
|
||||
export type Face = "west" | "east" | "bottom" | "top" | "north" | "south";
|
||||
|
||||
// KeyboardEvent.code values, like "KeyE" or "Digit1"
|
||||
|
||||
Reference in New Issue
Block a user