Sounds on shared and server
This commit is contained in:
@@ -333,6 +333,8 @@ export class ModRuntime {
|
||||
fluid_rules: this.fluid_rules,
|
||||
recipes: () => this.game.recipes,
|
||||
running: () => this.#shared_setup,
|
||||
play_sound: (sound, x, y, z, options) =>
|
||||
this.game.play_sound(sound, x, y, z, { ...options, except: this.game.rules_player }),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -756,6 +758,9 @@ export class ModRuntime {
|
||||
const { [field]: _, ...rest } = mob.client_data;
|
||||
mob.client_data = value === undefined ? rest : { ...rest, [field]: structuredClone(value) };
|
||||
},
|
||||
play_sound(sound, options = {}) {
|
||||
mob.level.play_sound(mob, sound, options);
|
||||
},
|
||||
};
|
||||
return Object.defineProperties(living_ref(mob), Object.getOwnPropertyDescriptors(extra)) as MobRef;
|
||||
}
|
||||
@@ -787,6 +792,9 @@ export class ModRuntime {
|
||||
set_ticking(ticking) {
|
||||
game.set_tile_ticking(x, y, z, ticking);
|
||||
},
|
||||
play_sound(sound, options) {
|
||||
game.play_sound(sound, x + 0.5, y + 0.5, z + 0.5, options);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1250,6 +1258,14 @@ export class ModRuntime {
|
||||
game().world.dirty = true;
|
||||
},
|
||||
},
|
||||
sounds: {
|
||||
play: (sound, x, y, z, options = {}) => {
|
||||
const except = options.except && this.#server_players.get(options.except);
|
||||
if (options.except && !except) throw new Error("a sound's except must be a player");
|
||||
game().play_sound(sound, ...at_position(x, y, z), { ...options, except });
|
||||
},
|
||||
exists: (sound) => EverythingRegistry.get("sounds", sound) !== undefined,
|
||||
},
|
||||
log: (...args) => console.log(`[${mod}]`, ...args),
|
||||
};
|
||||
return ctx;
|
||||
@@ -1711,9 +1727,18 @@ function player_api(game: GameServer, player: ServerPlayer): Player {
|
||||
player.using = undefined;
|
||||
},
|
||||
is_using: () => player.using !== undefined,
|
||||
play_sound(sound, options) {
|
||||
game.play_sound_to(player, sound, options);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// a position a script gave, checked
|
||||
function at_position(x: unknown, y: unknown, z: unknown): [number, number, number] {
|
||||
if (![x, y, z].every(Number.isFinite)) throw new Error("a position is three numbers");
|
||||
return [x, y, z] as [number, number, number];
|
||||
}
|
||||
|
||||
function known_effect(id: string): EffectType {
|
||||
const type = effect_type(id);
|
||||
if (!type) throw new Error(`unknown effect ${id}`);
|
||||
@@ -1831,5 +1856,8 @@ export function entity_ref(entity: Entity): EntityRef {
|
||||
if (!item || item.count <= 0) entity.remove();
|
||||
else entity.item = new_stack(item);
|
||||
},
|
||||
play_sound(sound, options = {}) {
|
||||
entity.level.play_sound(entity, sound, options);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user