Undergarden mod !
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// entities mods define (entities/<name>.json), drawn with their entity model and a texture from the atlas. there are no
|
||||
// animations yet: the model turns to the entity's yaw, and a bone named "head" to where it looks. entities without a
|
||||
// model are their texture facing the camera, like minecraft's fishing hook
|
||||
// animation files yet: the model turns to the entity's yaw, a bone named "head" to where it looks, and bones named
|
||||
// like minecraft's humanoid ones (right_arm, left_arm, right_leg, left_leg) swing as it walks, the right arm when it
|
||||
// attacks too. entities without a model are their texture facing the camera, like minecraft's fishing hook
|
||||
import { AssetManager } from "$/client/assets.ts";
|
||||
import type { Camera } from "$/client/camera.ts";
|
||||
import type { RemoteEntity } from "$/client/entity/remote_entity.ts";
|
||||
@@ -39,6 +40,7 @@ export function render_mod_entity(entity: RemoteEntity, camera: Camera, partial_
|
||||
const yaw_sin = Math.sin(entity.yaw);
|
||||
const yaw_cos = Math.cos(entity.yaw);
|
||||
|
||||
const limbs = limb_angles(entity, partial_tick);
|
||||
const bones = new Map<string, Matrix>();
|
||||
for (const bone of model.bones) {
|
||||
let matrix = bone_matrix(bone);
|
||||
@@ -46,6 +48,8 @@ export function render_mod_entity(entity: RemoteEntity, camera: Camera, partial_
|
||||
const look = rotation_around(model_pivot(bone), entity.pitch, entity.head_yaw - entity.yaw, 0);
|
||||
matrix = multiply(look, matrix);
|
||||
}
|
||||
const limb = limbs[bone.name];
|
||||
if (limb) matrix = multiply(rotation_around(model_pivot(bone), limb, 0, 0), matrix);
|
||||
if (bone.parent) matrix = multiply(bones.get(bone.parent) ?? IDENTITY, matrix);
|
||||
bones.set(bone.name, matrix);
|
||||
|
||||
@@ -65,6 +69,22 @@ export function render_mod_entity(entity: RemoteEntity, camera: Camera, partial_
|
||||
}
|
||||
}
|
||||
|
||||
// how far each humanoid limb turns forward (radians), like minecraft's HumanoidModel.setupAnim: arms and legs swing
|
||||
// opposite each other as it walks, and the right arm comes down in an attack like undergarden's rotwalker's
|
||||
function limb_angles(entity: RemoteEntity, partial_tick: number): Record<string, number> {
|
||||
const walk = entity.walk_animation(partial_tick);
|
||||
const swing = Math.cos(walk.position * 0.6662) * 1.4 * walk.speed;
|
||||
const attack = entity.attack_animation(partial_tick);
|
||||
// ease out quart, so it comes down fast
|
||||
const eased = 1 - (1 - attack) ** 4;
|
||||
return {
|
||||
right_arm: -swing + Math.sin(eased * Math.PI) * 1.2,
|
||||
left_arm: swing,
|
||||
right_leg: swing,
|
||||
left_leg: -swing,
|
||||
};
|
||||
}
|
||||
|
||||
// the whole texture, 16 pixels to a block, facing the camera around the middle of the entity's box
|
||||
function render_sprite(
|
||||
entity: RemoteEntity,
|
||||
|
||||
Reference in New Issue
Block a user