// what players wear, like curios' render layer: each worn item's model (see WornProperties) on the player, its bones // named like the player's parts turned the way those parts are, so it moves with them like minecraft's // TransformCopyingHumanoidModel. see docs/modding/items/index.md import { AssetManager } from "$/client/assets.ts"; import type { Player } from "$/client/entity/player.ts"; import type { Texture } from "$/client/renderer/mod.ts"; import { get_sprite_region } from "$/client/sprites.ts"; import { EverythingRegistry, type ItemRegistry } from "$/common/everything_registry.ts"; import type { EntityBoneJson, EntityModelJson } from "$/common/mod_data.ts"; import { IDENTITY, type Vec3 } from "./model_math.ts"; import { push_model } from "./model_renderer.ts"; import { on_part, type PlayerPose, pose_to_world, right_arm, worn_bone_pose, worn_look } from "./player_model.ts"; // the atlas has to be the current texture. tint is the player's, for light and flashing red export function render_worn(player: Player, pose: PlayerPose, tint?: Vec3) { if (player.worn.length === 0) return; const atlas = AssetManager.instance.get("bworld:textures"); const to_world = pose_to_world(pose); for (const stack of player.worn) { const worn = EverythingRegistry.get("items", stack.type_id)?.worn; if (!worn) continue; const look = worn_look(worn, pose.slim); const model = EverythingRegistry.get("entity_models", look.model); if (!model) continue; push_model(model, worn_bone_pose(pose), atlas, get_sprite_region(look.texture), to_world, tint); } } // what's worn on a player's right arm, in first person, like artifacts' renderFirstPersonArm. transform is the arm's, // from points around its pivot (see hand_renderer's arm_pose). the atlas has to be the current texture export function render_worn_arm(player: Player, transform: (x: number, y: number, z: number) => Vec3, tint?: Vec3) { const atlas = AssetManager.instance.get("bworld:textures"); const [px, py, pz] = right_arm(player.slim).pivot; // the model's pixels, standing still, to around the arm's pivot const to_arm = (x: number, y: number, z: number) => transform(x - px, y - py, z - pz); for (const stack of player.worn) { const worn = EverythingRegistry.get("items", stack.type_id)?.worn; if (!worn) continue; const look = worn_look(worn, player.slim); const model = EverythingRegistry.get("entity_models", look.model); if (!model) continue; const only = (bone: EntityBoneJson) => on_part(model, bone, "right_arm"); push_model(model, () => IDENTITY, atlas, get_sprite_region(look.texture), to_arm, tint, only); } }