Archive incari-client (client, 26.3, clean)

This commit is contained in:
2026-11-28 00:54:38 -06:00
parent 7a6174687f
commit 12838e838c
2383 changed files with 280266 additions and 0 deletions
@@ -0,0 +1,5 @@
// The crosshair is on a block, for the block-hit.
fn incari_oldanimations_highlight(pos: [i32; 3]) {
let _ = pos;
crate::game::incari_oldanimations::with(|b| b.seen_block());
}
@@ -0,0 +1,49 @@
# Incari's 1.7 Animations (features/oldanimations) for the Rust build (ADR 0068, 0069).
# Hooks by name where Horizon has stamped the hook point (native-hooks.json), by function where
# it's still pending. Its settings are the client's (rust/mods/incari): the module menu shows them.
[mod]
id = "incari_oldanimations"
version = "0.1.0"
priority = 100
[[module]]
id = "runtime"
file = "crates/horizon-client/src/game.rs"
name = "incari_oldanimations"
source = "runtime.rs"
[[injection]]
id = "tick"
hook = "tick"
hook_version = 1
kind = "HEAD"
helper = "tick.rs"
bindings = [
{ name = "game", ty = "&mut crate::game::Game<'_>", value = "&mut *self" },
]
[[injection]]
id = "highlight"
hook = "block_highlight"
hook_version = 1
kind = "HEAD"
helper = "highlight.rs"
bindings = [
{ name = "pos", ty = "[i32; 3]", value = "pos" },
]
[[injection]]
id = "pose"
# Horizon's hand_pose hook point is still a pending fragment
# (tools/native-hook-fragments/incari_client_hooks.json), so this targets its function. Make it
# `hook = "hand_pose"` and `hook_version = 1` once Horizon stamps it.
target = "horizon_client::game::native_hooks::Game<'_>::native_hand_pose"
kind = "HEAD"
helper = "pose.rs"
bindings = [
{ name = "game", ty = "&crate::game::Game<'_>", value = "self" },
{ name = "hand", ty = "horizon_client::first_person::Hand", value = "hand" },
{ name = "stack", ty = "&horizon_client::items::ItemStack", value = "stack" },
{ name = "using", ty = "bool", value = "using" },
{ name = "pose", ty = "&mut glam::Mat4", value = "&mut *pose" },
]
@@ -0,0 +1,67 @@
// The held item in 1.7's poses: the block-hit's swing, the sword-blocking pose, the rod turned
// round and flat items held as 1.7 held them, in that order (ModuleHands's).
fn incari_oldanimations_pose(
game: &crate::game::Game<'_>,
hand: horizon_client::first_person::Hand,
stack: &horizon_client::items::ItemStack,
using: bool,
pose: &mut glam::Mat4,
) {
use crate::game::{incari_client as c, incari_oldanimations as m};
let _ = game;
let Some(o) = c::settings(m::ID, |s| m::Options {
block_hit: s.bool("block-hit"),
items: s.bool("items"),
rod: s.bool("rod"),
sword_block: s.bool("sword-block"),
}) else {
return;
};
// Horizon's hook doesn't say which arm holds the hand: the main hand's is taken as the right.
let main = hand == horizon_client::first_person::Hand::Main;
let invert = if main { 1.0 } else { -1.0 };
let mut ops = m::Ops::default();
if main && using {
// The window's own milliseconds, for the block-hit's swing.
thread_local! {
static START: std::cell::Cell<Option<horizon_os::time::Instant>> =
const { std::cell::Cell::new(None) };
}
let start = START.with(|s| {
s.get().unwrap_or_else(|| {
let now = horizon_os::time::Instant::now();
s.set(Some(now));
now
})
});
let now = start.elapsed().as_secs_f64() * 1000.0;
let swing = m::with(|b| {
b.seen_using();
b.swing(now)
});
if o.block_hit
&& let Some(a) = swing
{
m::attack(&mut ops, invert, a);
}
}
let block_posed = o.sword_block && using && m::is_sword(&stack.item);
if block_posed {
m::block_pose(&mut ops, invert);
}
if o.rod && &*stack.item == m::FISHING_ROD {
m::rod(&mut ops, invert);
}
if (o.items || block_posed) && m::held_flat(&stack.item) {
m::legacy_item(&mut ops, invert);
}
for op in ops.as_slice() {
*pose *= match *op {
m::Op::Scale(s) => glam::Mat4::from_scale(glam::Vec3::from_array(s)),
m::Op::TurnX(d) => glam::Mat4::from_rotation_x(d.to_radians()),
m::Op::TurnY(d) => glam::Mat4::from_rotation_y(d.to_radians()),
m::Op::TurnZ(d) => glam::Mat4::from_rotation_z(d.to_radians()),
m::Op::Move(v) => glam::Mat4::from_translation(glam::Vec3::from_array(v)),
};
}
}
@@ -0,0 +1,278 @@
// Incari's 1.7 Animations for the Rust build (ADR 0068, 0069), as features/oldanimations and the
// Java client's ModuleHands do it: first person as 1.7 drew it. Flat items held smaller and tilted,
// the fishing rod the other way round, 1.7's sword-blocking pose for a sword in use (on servers
// where swords block), and the block-hit: attacking a block while an item's in use swings the arm,
// drawn only. Horizon's hand pose hook moves the drawn item, before the model's own first-person
// transform, as the Java hook does. Its settings are the module's in `incari_core::modules`.
// No game types: rust/lib.rs tests it; the hook turns the steps here into matrices.
/// The module's id, as the Java client's profiles name it.
pub const ID: &str = "oldanimations";
pub const FISHING_ROD: &str = "minecraft:fishing_rod";
/// One step of a pose, as a PoseStack takes them: each applies after (to the right of) the last.
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Op {
Scale([f32; 3]),
/// Degrees about x, y or z.
TurnX(f32),
TurnY(f32),
TurnZ(f32),
Move([f32; 3]),
}
/// Steps, without allocating: the hook runs for each hand each frame.
#[derive(Clone, Copy, Debug)]
pub struct Ops {
ops: [Op; 24],
len: usize,
}
impl Default for Ops {
fn default() -> Self {
Self {
ops: [Op::Scale([1.0; 3]); 24],
len: 0,
}
}
}
impl Ops {
pub fn push(&mut self, op: Op) {
if self.len < self.ops.len() {
self.ops[self.len] = op;
self.len += 1;
}
}
pub fn as_slice(&self) -> &[Op] {
&self.ops[..self.len]
}
}
/// The module's settings, read once a hand.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Options {
pub block_hit: bool,
pub items: bool,
pub rod: bool,
pub sword_block: bool,
}
pub fn is_sword(item: &str) -> bool {
item.ends_with("_sword")
}
/// Whether 1.7 held `item` as a flat item and the game's model holds it as flat and handheld
/// items are (`item/handheld`, `item/generated`: turned 0, -90, 25), the transform `legacy_item`
/// undoes. Horizon's hook doesn't say which model an item has, or whether it's a block, so these
/// are the ones known to be: tools, weapons, sticks and the bow.
pub fn held_flat(item: &str) -> bool {
let Some(name) = item.strip_prefix("minecraft:") else {
return false;
};
["_sword", "_axe", "_pickaxe", "_shovel", "_hoe"]
.iter()
.any(|s| name.ends_with(s))
|| matches!(name, "stick" | "bone" | "blaze_rod" | "breeze_rod" | "bow")
}
/// 1.7's blocking pose for a sword in use, in place of today's (which Horizon doesn't draw: its
/// pose for an item in use is the arm's alone). `invert` is 1 for the right arm, -1 the left.
pub fn block_pose(ops: &mut Ops, invert: f32) {
// 1.7's block turn, in the frame its item renderer worked in (turned 45 degrees, at 0.4 scale).
ops.push(Op::TurnY(invert * 45.0));
ops.push(Op::Scale([0.4; 3]));
ops.push(Op::Move([invert * -0.5, 0.2, 0.0]));
ops.push(Op::TurnY(invert * 30.0));
ops.push(Op::TurnX(-80.0));
ops.push(Op::TurnY(invert * 60.0));
ops.push(Op::Scale([2.5; 3]));
ops.push(Op::TurnY(invert * -45.0));
}
/// 1.7's fishing rod: turned round.
pub fn rod(ops: &mut Ops, invert: f32) {
ops.push(Op::TurnY(invert * 180.0));
}
/// The first-person transform vanilla's flat and handheld models give the right hand: turned
/// (x, y, z) degrees, moved (in blocks), scaled. The left hand's is mirrored.
pub const FLAT_TURN: [f32; 3] = [0.0, -90.0, 25.0];
pub const FLAT_MOVE: [f32; 3] = [1.13 / 16.0, 3.2 / 16.0, 1.13 / 16.0];
pub const FLAT_SCALE: f32 = 0.68;
/// 1.7's flat item, from the arm: smaller, turned edge-on and tilted, its grip at the hand; then
/// the model's own first-person transform undone, so that transform leaves it where 1.7 put it.
pub fn legacy_item(ops: &mut Ops, invert: f32) {
let tilt = 25f32.to_radians();
ops.push(Op::Scale([0.6; 3]));
ops.push(Op::TurnY(invert * 275.0));
ops.push(Op::TurnZ(invert * 25.0));
ops.push(Op::Move([
invert * (-0.2 * tilt.sin() + 0.4375),
-0.2 * tilt.cos() + 0.4375,
0.03125,
]));
// The inverse of `ItemTransform.apply` (moved, turned x then y then z, scaled), which mirrors
// the move's x and the y and z turns for the left hand; that hand's sprite seen from behind,
// as 1.7's pose mirrored for it wants.
let left = invert < 0.0;
if left {
ops.push(Op::TurnY(180.0));
}
let [rx, ry, rz] = FLAT_TURN;
let [tx, ty, tz] = FLAT_MOVE;
ops.push(Op::Scale([1.0 / FLAT_SCALE; 3]));
ops.push(Op::TurnZ(-rz));
ops.push(Op::TurnY(-ry));
ops.push(Op::TurnX(-rx));
ops.push(Op::Move([-invert * tx, -ty, -tz]));
}
/// The attack swing's turn of the arm at `attack` (0 to 1), as it's drawn unused
/// (`applyItemArmAttackTransform`): what the block-hit adds to an item in use.
pub fn attack(ops: &mut Ops, invert: f32, attack: f32) {
let pi = std::f32::consts::PI;
let root = (attack.sqrt() * pi).sin();
ops.push(Op::TurnY(
invert * (45.0 + (attack * attack * pi).sin() * -20.0),
));
ops.push(Op::TurnZ(invert * root * -20.0));
ops.push(Op::TurnX(root * -80.0));
ops.push(Op::TurnY(invert * -45.0));
}
/// A swing's length: vanilla's, without Haste or Mining Fatigue (6 ticks).
pub const SWING_MS: f64 = 300.0;
/// The block-hit's own swing: Horizon swings no arm while an item's in use, so the module times
/// its own, as `LivingEntity.swing` would.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct BlockHit {
/// Ticks so far.
pub tick: u64,
/// The tick the main hand was last drawn in use, and the crosshair last on a block.
pub using: Option<u64>,
pub block: Option<u64>,
/// A tick asked for a swing.
pub wanted: bool,
/// When the swing started, in the hook's milliseconds.
pub start: Option<f64>,
}
impl BlockHit {
pub fn seen_using(&mut self) {
self.using = Some(self.tick);
}
pub fn seen_block(&mut self) {
self.block = Some(self.tick);
}
/// Once a tick: with the block-hit `on`, playing, and the attack key held while the main hand
/// is in use and the crosshair is on a block (both seen since the last tick), the arm swings.
pub fn tick(&mut self, on: bool, playing: bool, attack_held: bool) {
let recent = |t: Option<u64>| t.is_some_and(|t| t >= self.tick);
self.wanted = on && playing && attack_held && recent(self.using) && recent(self.block);
self.tick += 1;
}
/// The swing's progress at `now` (0 to 1), None with no swing. A swing asked for starts
/// again once the last is half done, as `LivingEntity.swing` does.
pub fn swing(&mut self, now: f64) -> Option<f32> {
if self.wanted {
if self.start.is_none_or(|s| now - s >= SWING_MS / 2.0) {
self.start = Some(now);
}
self.wanted = false;
}
let since = now - self.start?;
if !(0.0..SWING_MS).contains(&since) {
self.start = None;
return None;
}
Some((since / SWING_MS) as f32)
}
}
// The window's thread only: ticks and the hand's drawing both run there.
thread_local! {
static BLOCK_HIT: std::cell::Cell<BlockHit> = std::cell::Cell::new(BlockHit::default());
}
/// Runs `f` on the block-hit's state.
pub fn with<R>(f: impl FnOnce(&mut BlockHit) -> R) -> R {
BLOCK_HIT.with(|cell| {
let mut state = cell.get();
let r = f(&mut state);
cell.set(state);
r
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn knows_flat_items_and_swords() {
assert!(is_sword("minecraft:netherite_sword") && !is_sword("minecraft:shield"));
assert!(held_flat("minecraft:diamond_pickaxe") && held_flat("minecraft:stick"));
assert!(
!held_flat("minecraft:stone")
&& !held_flat(FISHING_ROD)
&& !held_flat("minecraft:mace")
);
}
#[test]
fn poses_add_up_without_allocating() {
let mut ops = Ops::default();
block_pose(&mut ops, 1.0);
legacy_item(&mut ops, -1.0);
rod(&mut ops, 1.0);
attack(&mut ops, 1.0, 0.5);
assert_eq!(ops.as_slice().len(), 8 + 10 + 1 + 4);
assert_eq!(ops.as_slice()[0], Op::TurnY(45.0));
// At rest the swing turns nothing.
let mut rest = Ops::default();
attack(&mut rest, 1.0, 0.0);
assert_eq!(rest.as_slice()[0], Op::TurnY(45.0));
assert_eq!(rest.as_slice()[3], Op::TurnY(-45.0));
}
#[test]
fn block_hits_while_using_on_a_block() {
let mut b = BlockHit::default();
b.seen_using();
b.seen_block();
b.tick(true, true, true);
assert_eq!(b.swing(1000.0), Some(0.0));
assert_eq!(b.swing(1150.0), Some(0.5));
b.tick(true, true, true);
let carried = b.swing(1200.0).unwrap();
assert!(
(carried - 2.0 / 3.0).abs() < 1e-6,
"the stale use and block ask for nothing"
);
b.seen_using();
b.seen_block();
b.tick(true, true, true);
assert_eq!(
b.swing(1260.0),
Some(0.0),
"past half done: it starts again"
);
b.seen_using();
b.seen_block();
b.tick(true, true, true);
assert_eq!(b.swing(1320.0), Some(0.2), "not half done: it carries on");
assert_eq!(b.swing(1600.0), None);
b.seen_using();
b.seen_block();
b.tick(false, true, true);
assert_eq!(b.swing(2000.0), None);
}
}
@@ -0,0 +1,16 @@
// Once a tick: the block-hit swings the arm while the attack key's held on a block with an item
// in use. Drawn only: nothing is sent.
fn incari_oldanimations_tick(game: &mut crate::game::Game<'_>) {
use crate::game::{incari_client as c, incari_oldanimations as m};
if !game.native_window() {
return;
}
let on = c::settings(m::ID, |s| s.bool("block-hit")).unwrap_or(false);
let playing = game.native_playing();
let attack = on
&& playing
&& game
.native_mapping("key.attack")
.is_some_and(|(down, _)| down);
m::with(|b| b.tick(on, playing, attack));
}