Compare commits
2
Commits
487d5ae2a9
...
dfb110e0f8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dfb110e0f8 | ||
|
|
8add5f852e |
@@ -91,9 +91,9 @@ export abstract class Entity {
|
||||
this.walk_position += this.walk_speed;
|
||||
}
|
||||
|
||||
// after moving each tick: a step every STEP_DISTANCE it walks with a block under its feet, own when it has its own
|
||||
// step sound (see ENTITY_SOUNDS), the block's otherwise
|
||||
play_steps(own: string | undefined) {
|
||||
// after moving each tick: a step every STEP_DISTANCE it walks with a block under its feet, what own gives when it
|
||||
// has its own step sound (see ENTITY_SOUNDS), the block's otherwise
|
||||
play_steps(own?: () => string | undefined) {
|
||||
const [x, y, z] = [Math.floor(this.x), Math.floor(this.y - 0.2), Math.floor(this.z)];
|
||||
const nid = this.level.get_block(x, y, z);
|
||||
const below = nid === AIR ? undefined : EverythingRegistry.get_by_id<BlockRegistry>("blocks", nid);
|
||||
@@ -102,7 +102,8 @@ export abstract class Entity {
|
||||
if (this.#walked < STEP_DISTANCE) return;
|
||||
this.#walked %= STEP_DISTANCE;
|
||||
const at = { x: this.x, y: this.y, z: this.z };
|
||||
if (own) sounds.play(own, { at });
|
||||
const sound = own?.();
|
||||
if (sound) sounds.play(sound, { at });
|
||||
else sounds.play_of(below.sounds, "step", { at, volume: BLOCK_STEP_VOLUME });
|
||||
}
|
||||
|
||||
|
||||
@@ -199,7 +199,7 @@ export class LocalPlayer extends Player {
|
||||
if (Math.abs(this.vz) < MIN_SPEED) this.vz = 0;
|
||||
this.update_swim_animation();
|
||||
// creeping and flying are quiet
|
||||
if (this.on_ground && !this.sneaking) this.play_steps(undefined);
|
||||
if (this.on_ground && !this.sneaking) this.play_steps();
|
||||
this.#send_position(
|
||||
(this.on_ground && !was_on_ground) || this.swimming !== was_swimming ||
|
||||
this.holding_sneak !== was_holding_sneak,
|
||||
|
||||
@@ -107,7 +107,10 @@ export class RemoteEntity extends Entity {
|
||||
this.update_walk_animation();
|
||||
if (this.swing_ticks !== undefined && ++this.swing_ticks >= SWING_TICKS) this.swing_ticks = undefined;
|
||||
if (!this.dead) {
|
||||
this.play_steps(sound_of(this.#sounds, "step"));
|
||||
this.play_steps(() => {
|
||||
const own = sound_of(this.#sounds, "step");
|
||||
return this.animation ? this.animation.step_sound(own) : own;
|
||||
});
|
||||
if (--this.#ambient_ticks <= 0) {
|
||||
this.#ambient_ticks = random_ambient_ticks();
|
||||
sounds.play_of(this.#sounds, "ambient", { follow: this.id });
|
||||
|
||||
@@ -58,6 +58,6 @@ export class RemotePlayer extends Player {
|
||||
this.z += (this.target_z - this.z) * t;
|
||||
this.update_walk_animation();
|
||||
this.update_swim_animation();
|
||||
this.play_steps(undefined);
|
||||
this.play_steps();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,14 @@ export class EntityAnimation {
|
||||
return posed ? offsets : undefined;
|
||||
}
|
||||
|
||||
// the sound its next step makes, what the animator says when it has a step_sound, own otherwise
|
||||
step_sound(own: string | undefined): string | undefined {
|
||||
const animator = this.#animator;
|
||||
if (!animator?.step_sound) return own;
|
||||
let sound: string | undefined;
|
||||
return this.#run("step_sound", () => sound = animator.step_sound!()) ? sound : own;
|
||||
}
|
||||
|
||||
#on_data(field: string) {
|
||||
const animator = this.#animator;
|
||||
if (animator?.on_data) this.#run("on_data", () => animator.on_data!(field, this.#source.age));
|
||||
|
||||
@@ -189,6 +189,9 @@ export interface EntityAnimator {
|
||||
// a field of its client data changed (see MobRef.set_client_data in cubi/server), or was already set when the
|
||||
// animator was made
|
||||
on_data?(field: string, time: number): void;
|
||||
// the sound its next step makes in place of its json's step sound, or undefined for the step of the block it walks
|
||||
// on, like a mob that only stomps once it's angry. see docs/modding/resources/sounds.md
|
||||
step_sound?(): string | undefined;
|
||||
}
|
||||
|
||||
// the entity an animator poses
|
||||
|
||||
@@ -67,7 +67,15 @@ block, and `check-mods` reports a block or entity whose `sounds` has none of its
|
||||
The player breaking or placing a block hears it right away from their own client, and everyone else from the server.
|
||||
Players step with the blocks they walk on, except the one playing while they sneak or fly. Anything about a mob that
|
||||
depends on what it's doing is its scripts' to play, see [From the Server](#from-the-server) and
|
||||
[Lasting Sounds](#lasting-sounds).
|
||||
[Lasting Sounds](#lasting-sounds). A mob whose steps change with what it's doing gets them from its animator's
|
||||
`step_sound`, which says the sound each step makes, or `undefined` for the block's step:
|
||||
|
||||
```ts
|
||||
ctx.render.register_entity_animator("my_mod:walker", (walker) => ({
|
||||
pose(pose, time) {/* ... */},
|
||||
step_sound: () => walker.get_client_data("angry") ? "my_mod:walker/stomp" : undefined,
|
||||
}));
|
||||
```
|
||||
|
||||
## Playing Sounds
|
||||
|
||||
|
||||
@@ -18,14 +18,14 @@
|
||||
}
|
||||
],
|
||||
"variants": {
|
||||
"facing=0": {
|
||||
"facing=1": {
|
||||
"y": 90
|
||||
},
|
||||
"facing=2": {
|
||||
"y": 180
|
||||
},
|
||||
"facing=1": {
|
||||
"y": 270
|
||||
},
|
||||
"facing=3": {
|
||||
"y": 90
|
||||
"y": 270
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
"model": "dangerous_business:jester",
|
||||
"texture": "dangerous_business:jester",
|
||||
"behavior": "dangerous_business:jester",
|
||||
"sounds": "dangerous_business:jester",
|
||||
"width": 0.8,
|
||||
"height": 1.9,
|
||||
"max_health": 40,
|
||||
|
||||
@@ -161,8 +161,8 @@ function nearest_player(ctx: ServerContext, mob: MobRef) {
|
||||
}
|
||||
|
||||
// what bedrock's animation controller did: idle and walk while it roams, crank, then pop, then its chase. what its
|
||||
// clips did with expressions is here as code. its music box plays while it cranks, and it screams while it's popped.
|
||||
// a player who comes upon it partway sees and hears it from as far as it's got, by when its state started
|
||||
// clips did with expressions is here as code. its music box plays while it cranks, and it screams and stomps while
|
||||
// it's popped. a player who comes upon it partway sees and hears it from as far as it's got, by when its state started
|
||||
export function register_jester_animator(ctx: ClientContext) {
|
||||
const clip = (name: string) => ctx.render.clip(`dangerous_business:jester/${name}`);
|
||||
const idle = clip("idle");
|
||||
@@ -195,6 +195,8 @@ export function register_jester_animator(ctx: ClientContext) {
|
||||
theme = sound_while(state === CRANKING, theme, () => play("dangerous_business:jester/theme"));
|
||||
scream = sound_while(state === AGGRO, scream, () => play("dangerous_business:jester/scream"));
|
||||
},
|
||||
step_sound: () =>
|
||||
jester.get_client_data<number>("state") === AGGRO ? "dangerous_business:jester/stomp" : undefined,
|
||||
pose(pose, time) {
|
||||
if (cranking.started) {
|
||||
pose.play_state(crank, cranking, time);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"sounds": {
|
||||
"jester/step": { "files": ["jester/stomp_1", "jester/stomp_2", "jester/stomp_3"], "category": "entities" },
|
||||
"jester/stomp": { "files": ["jester/stomp_1", "jester/stomp_2", "jester/stomp_3"], "category": "entities" },
|
||||
"jester/turn_crank": {
|
||||
"files": ["jester/turn_crank_1", "jester/turn_crank_2", "jester/turn_crank_3"],
|
||||
"category": "entities"
|
||||
|
||||
@@ -303,6 +303,20 @@ Deno.test("a clip plays from when its state started, and with walking as strongl
|
||||
assertAlmostEquals(animation.pose(15)!.get("arm")!.rotation[0], 22.5);
|
||||
});
|
||||
|
||||
Deno.test("an animator's step_sound picks each step's sound, and one without it keeps the entity's own", () => {
|
||||
const { type } = animator_type("stomper", (entity) => ({
|
||||
pose() {},
|
||||
step_sound: () => entity.get_client_data<boolean>("angry") ? "test:stomp" : undefined,
|
||||
}));
|
||||
const entity = animated(type);
|
||||
const animation = animation_for(entity)!;
|
||||
assertEquals(animation.step_sound("test:own"), undefined);
|
||||
entity.data = { client_data: { angry: true } };
|
||||
assertEquals(animation.step_sound("test:own"), "test:stomp");
|
||||
const { type: quiet } = animator_type("quiet", () => ({ pose() {} }));
|
||||
assertEquals(animation_for(animated(quiet))!.step_sound("test:own"), "test:own");
|
||||
});
|
||||
|
||||
Deno.test("an animator that throws is removed, and the entity is posed without it", async () => {
|
||||
const { type } = animator_type("thrower", () => ({
|
||||
pose(pose) {
|
||||
|
||||
Reference in New Issue
Block a user