Make players mobs too !
This commit is contained in:
@@ -4,6 +4,9 @@ import { push_vertex, type Texture } from "$/client/renderer/mod.ts";
|
||||
|
||||
export type Vec3 = [number, number, number];
|
||||
|
||||
// how much of each color is left while something flashes red after being hurt, like minecraft's
|
||||
export const HURT_TINT: Vec3 = [1, 0.6, 0.6];
|
||||
|
||||
// minecraft's player model is 32 skin pixels tall, it's scaled to the player's height
|
||||
const PIXEL = PLAYER_HEIGHT / 32;
|
||||
// keeps nearest sampling from picking the texel next to a face's edge
|
||||
@@ -144,8 +147,9 @@ const FACES: { rect: (w: number, h: number, d: number) => number[]; corners: num
|
||||
},
|
||||
];
|
||||
|
||||
// a player with a minecraft skin, like minecraft's PlayerRenderer. the skin has to be the current texture
|
||||
export function render_player(player: Player, skin: Texture, partial_tick: number) {
|
||||
// a player with a minecraft skin, like minecraft's PlayerRenderer. the skin has to be the current texture. tint
|
||||
// multiplies its colors, for flashing red when hurt
|
||||
export function render_player(player: Player, skin: Texture, partial_tick: number, tint?: Vec3) {
|
||||
const { x, y, z } = player.render_position(partial_tick);
|
||||
const yaw_sin = Math.sin(player.yaw);
|
||||
const yaw_cos = Math.cos(player.yaw);
|
||||
@@ -173,8 +177,8 @@ export function render_player(player: Player, skin: Texture, partial_tick: numbe
|
||||
const mz = (py * sin + pz * cos + pivot_z) * PIXEL;
|
||||
return [x + mx * yaw_cos + mz * yaw_sin, y + my, z - mx * yaw_sin + mz * yaw_cos];
|
||||
};
|
||||
push_cube(skin, part, part.texture, 0, transform);
|
||||
push_cube(skin, part, part.overlay, part.inflate, transform);
|
||||
push_cube(skin, part, part.texture, 0, transform, tint);
|
||||
push_cube(skin, part, part.overlay, part.inflate, transform, tint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,10 +188,11 @@ function push_cube(
|
||||
uv: [number, number],
|
||||
inflate: number,
|
||||
transform: (x: number, y: number, z: number) => Vec3,
|
||||
tint?: Vec3,
|
||||
) {
|
||||
const low = part.from.map((n) => n - inflate) as Vec3;
|
||||
const high = part.from.map((n, i) => n + part.size[i] + inflate) as Vec3;
|
||||
push_box(part.size, low, high, uv, (u, v) => [u / skin.width, v / skin.height], transform);
|
||||
push_box(part.size, low, high, uv, (u, v) => [u / skin.width, v / skin.height], transform, tint);
|
||||
}
|
||||
|
||||
// a box of a model, from low to high, textured like minecraft's box uv from [u, v] for a box of size (in texture
|
||||
|
||||
Reference in New Issue
Block a user