Block visuals
This commit is contained in:
@@ -70,9 +70,72 @@ export interface ClientContext {
|
||||
};
|
||||
// every mod's block, item and entity tags
|
||||
tags: TagApi;
|
||||
// blocks drawn with code, like a shaft that turns, see docs/modding/blocks/visuals.md
|
||||
render: ClientRender;
|
||||
log(...args: unknown[]): void;
|
||||
}
|
||||
|
||||
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
|
||||
// terrain, for a visual that draws all of it
|
||||
register_visual(
|
||||
block: Id,
|
||||
create: (block: VisualBlock, instances: Instances) => Visual,
|
||||
options?: { replaces_model?: boolean },
|
||||
): void;
|
||||
}
|
||||
|
||||
// the block a visual draws
|
||||
export interface VisualBlock {
|
||||
readonly id: Id;
|
||||
readonly x: number;
|
||||
readonly y: number;
|
||||
readonly z: number;
|
||||
// they stay the same for the visual's life, it's made again when they change
|
||||
readonly states: Readonly<Record<string, number>>;
|
||||
// a field of its client data now, a copy, see BlockRef.set_client_data in bworld/server
|
||||
get_client_data<T>(field: string): T | undefined;
|
||||
}
|
||||
|
||||
export interface Visual {
|
||||
// a field of its block's client data changed
|
||||
update?(): void;
|
||||
// before each frame its chunk is in view, for what moves on the cpu, like a crank slowing down. time is in ticks
|
||||
// with the part of the next one, the same time rotating instances turn by
|
||||
on_frame?(time: number): void;
|
||||
// it's going, with its block, with its chunk, or because its states changed. its instances go with it
|
||||
on_delete?(): void;
|
||||
}
|
||||
|
||||
// a model from models/ by id, turned like a block variant: x then y, in steps of 90 degrees
|
||||
export type ModelRef = Id | { model: Id; x?: number; y?: number };
|
||||
|
||||
// what a visual draws: models lit by the block's light. without a model, the block's own, the way its states draw it
|
||||
export interface Instances {
|
||||
// placed by a matrix, set again whenever it moves
|
||||
transformed(model?: ModelRef): TransformedInstance;
|
||||
// turning at a steady speed worked out from the time, so it never needs anything per frame
|
||||
rotating(model?: ModelRef): RotatingInstance;
|
||||
}
|
||||
|
||||
export interface Instance {
|
||||
// stops drawing it for good
|
||||
delete(): void;
|
||||
}
|
||||
|
||||
export interface TransformedInstance extends Instance {
|
||||
// a 4x4 matrix in column major order, like gl-matrix's mat4, from the model's space (0 to 1 across the block) to
|
||||
// the block's, where 0 0 0 is its corner. where the block is when not set
|
||||
set_transform(matrix: ArrayLike<number>): void;
|
||||
}
|
||||
|
||||
export interface RotatingInstance extends Instance {
|
||||
// turns around axis through the middle of the block, counterclockwise seen from the axis's positive end when rpm
|
||||
// is positive, at time * rpm * 0.3 + offset degrees. still when not set
|
||||
set_rotation(axis: "x" | "y" | "z", rpm: number, offset?: number): void;
|
||||
}
|
||||
|
||||
// the keys the player has bound, like the key mappings in minecraft's Options
|
||||
export interface KeyMappings {
|
||||
readonly key_forward: KeyCode;
|
||||
|
||||
Reference in New Issue
Block a user