Merge pull request #183 from Online5277/fix/rabbit-animation

Drive rabbit hop and idle animations from runtime controls
This commit is contained in:
Ludovic Marie
2026-10-14 23:04:26 +02:00
committed by GitHub
10 changed files with 557 additions and 7 deletions
@@ -684,6 +684,7 @@ fn main() -> horizon_client::Result<()> {
let assets = Assets::load(root)?;
let registry = assets.registry;
let facts = BlockFacts::load(root, registry)?;
let motion = horizon_client::motion::MotionResources::load(root, &assets)?;
let data = MobData::load(root, &facts);
let types = MobTypes::load(root)?;
let biomes = Biomes::load(root)?;
@@ -911,6 +912,7 @@ fn main() -> horizon_client::Result<()> {
world: &world,
registry,
facts: &facts,
movement: &motion.blocks,
collision: &collision,
data: &data,
player: player.clone(),
@@ -324,6 +324,7 @@ impl Game<'_> {
world: &self.world,
registry: self.res.assets.registry,
facts: &self.res.facts,
movement: &self.motion.blocks,
collision: self.collision,
data: &self.res.mob_data,
player: self.player_view(),
@@ -681,6 +682,7 @@ impl Game<'_> {
pub(super) fn handle_mob_events(&mut self, events: Vec<MobEvent>) -> Result<()> {
for e in events {
match e {
MobEvent::RabbitHop { mob, at } => self.lan_entity_event(mob as i32, 1, at),
MobEvent::Sound(name, at, volume, pitch)
| MobEvent::LocalSound(name, at, volume, pitch) => {
self.audio
+3
View File
@@ -128,6 +128,9 @@ fn mob_meta(m: &Mob, hub: &Hub) -> Vec<(u8, i32, Value)> {
if m.health < m.kind.max_health {
meta.push((9, serializer::FLOAT, Value::Float(m.health.max(0.0))));
}
if kind == "minecraft:rabbit" && m.no_ai {
meta.push((15, serializer::BYTE, Value::Byte(1)));
}
if m.is_baby()
&& let Some(index) = baby_index(kind)
{
+23
View File
@@ -936,6 +936,17 @@ impl Game<'_> {
}
}
C::SetEntityData(p) => {
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32)
&& m.species() == horizon_client::mobs::Species::Rabbit
{
for (index, _, value) in &p.values {
match (index, value) {
(15, Value::Byte(flags)) => m.no_ai = flags & 1 != 0,
(16, Value::Bool(baby)) => m.extra.age = if *baby { -1 } else { 0 },
_ => {}
}
}
}
for (index, _, value) in &p.values {
if *index == ITEM_ENTITY_ITEM
&& let Value::Item(stack) = value
@@ -966,6 +977,12 @@ impl Game<'_> {
}
}
C::EntityEvent(p) => {
if p.event == 1
&& let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32)
&& m.species() == horizon_client::mobs::Species::Rabbit
{
horizon_client::mobs::rabbit::hop_event(m);
}
// EntityEvent.DEATH: start the death animation.
if p.event == 3
&& let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32)
@@ -1739,6 +1756,9 @@ impl Game<'_> {
m.previous_body_yaw = m.body_yaw;
m.previous_limb_speed = m.limb_speed;
m.age += 1;
if m.species() == horizon_client::mobs::Species::Rabbit {
horizon_client::mobs::rabbit::base_tick(m);
}
if m.hurt_time > 0 {
m.hurt_time -= 1;
}
@@ -1761,6 +1781,9 @@ impl Game<'_> {
let target = (((dx * dx + dz * dz).sqrt() * 4.0) as f32).min(1.0);
m.limb_speed += (target - m.limb_speed) * 0.4;
m.limb_position += m.limb_speed;
if m.species() == horizon_client::mobs::Species::Rabbit {
horizon_client::mobs::rabbit::post_tick(m);
}
}
for d in &mut self.dropped {
d.previous = d.position;
+7
View File
@@ -45,6 +45,7 @@ pub mod nether;
pub mod path;
pub mod phantom;
pub mod piglin;
pub mod rabbit;
pub mod raider;
pub mod ravager;
pub mod render;
@@ -818,6 +819,11 @@ pub struct Mob {
/// Events a mob tick asks the game to act on.
#[derive(Clone, Debug)]
pub enum MobEvent {
/// Rabbit entity event 1, sent only when a ground jump actually happens.
RabbitHop {
mob: u32,
at: [f64; 3],
},
Sound(&'static str, [f64; 3], f32, f32),
/// `ChestBlockEntity.startOpen` / `stopOpen` by a copper golem: the
/// chest's opener count goes up or down (interaction range 3).
@@ -1338,6 +1344,7 @@ pub struct MobWorld<'a> {
pub world: &'a World,
pub registry: &'a horizon_world::registry::BlockRegistry,
pub facts: &'a BlockFacts,
pub movement: &'a horizon_world::movement_properties::BoundMovementProperties,
pub collision: &'a BlockCollisionRegistry<'a>,
pub data: &'a MobData,
pub player: Option<PlayerView>,
+17 -4
View File
@@ -171,7 +171,12 @@ pub fn register(m: &mut Mob) {
Family::Undead => undead::register(m),
Family::Hostile => hostile::register(m),
Family::Aquatic => aquatic::register(m),
Family::Generic => generic(m),
Family::Generic => {
generic(m);
if m.species() == Species::Rabbit {
super::rabbit::register(m);
}
}
Family::Inert => {}
Family::Witch => super::witch::register(m),
Family::Tame if m.species() == Species::Cat => super::tame::register_cat(m),
@@ -271,8 +276,9 @@ fn generic(m: &mut Mob) {
m.ai.targets.add(2, NearestTarget::player(true));
} else {
g.add(0, Float);
g.add(1, Panic::new(1.25));
g.add(5, Stroll::avoiding_water(1.0));
let rabbit = m.kind.species == Species::Rabbit;
g.add(1, Panic::new(if rabbit { 2.2 } else { 1.25 }));
g.add(5, Stroll::avoiding_water(if rabbit { 0.6 } else { 1.0 }));
g.add(6, LookAtPlayer::new(6.0));
g.add(7, RandomLookAround::default());
}
@@ -352,6 +358,9 @@ pub fn tick(
}
super::warden::pre_tick(m, w, events);
base_tick(m, w, events);
if m.species() == Species::Rabbit {
super::rabbit::base_tick(m);
}
if m.death_time >= super::creaking::death_limit(m) {
// Creaking.tickDeath: a heart's creaking crumbles away.
if super::creaking::is_creaking(m) && super::creaking::tearing_down(m) {
@@ -362,6 +371,9 @@ pub fn tick(
if !m.no_ai {
ai_step(m, w, level_random, events);
}
if m.species() == Species::Rabbit {
super::rabbit::post_tick(m);
}
// Mob.tickHeadTurn -> BodyRotationControl.clientTick (a frozen
// creaking's waits).
if m.alive() && !(super::creaking::is_creaking(m) && !super::creaking::can_move(m)) {
@@ -605,7 +617,7 @@ fn ai_step(m: &mut Mob, w: &MobWorld, level_random: &mut LegacyRandom, events: &
m.ai.xxa = 0.0;
m.ai.zza = 0.0;
}
m.handle_jumping();
m.handle_jumping(w);
let input = Vec3::new(
f64::from(m.ai.xxa),
f64::from(m.ai.yya),
@@ -849,6 +861,7 @@ fn server_ai_step(
}
fn custom_server_ai_step(m: &mut Mob, cx: &mut Cx) {
match m.species() {
Species::Rabbit => super::rabbit::server_ai_step(m),
Species::Sheep => {}
Species::Zombie
| Species::Husk
@@ -132,6 +132,9 @@ impl Mob {
}
/// MoveControl.tick (and the flying / smooth-swimming variants).
pub fn move_control_tick(&mut self, w: &MobWorld, events: &mut Vec<super::MobEvent>) {
if self.species() == super::Species::Rabbit {
return super::rabbit::move_control(self, w);
}
let attr_speed = self.movement_speed();
match self.ai.mov.kind {
MoveKind::Custom => super::ai::custom_move_control(self, w, events),
@@ -376,6 +379,9 @@ impl Mob {
}
/// JumpControl.tick.
pub fn jump_control_tick(&mut self) {
if self.species() == super::Species::Rabbit {
return super::rabbit::jump_control(self);
}
self.ai.jumping = self.ai.jump;
self.ai.jump = false;
}
+7 -3
View File
@@ -723,7 +723,7 @@ impl Mob {
}
}
/// The jump part of LivingEntity.aiStep.
pub fn handle_jumping(&mut self) {
pub fn handle_jumping(&mut self, w: &MobWorld) {
if self.ai.jumping && self.affected_by_fluids() {
let (fluid_height, in_water_with_height) = if self.fluids.in_lava {
(self.fluids.lava, false)
@@ -739,7 +739,7 @@ impl Mob {
if (self.on_ground || in_water_with_height && fluid_height <= threshold)
&& self.ai.no_jump_delay == 0
{
self.jump_from_ground();
self.jump_from_ground(w);
self.ai.no_jump_delay = 10;
}
} else {
@@ -756,7 +756,11 @@ impl Mob {
fn jump_in_liquid(&mut self) {
self.velocity.y += if self.ai.nav.can_float { 0.04 } else { 0.3 };
}
pub fn jump_from_ground(&mut self) {
pub fn jump_from_ground(&mut self, w: &MobWorld) {
if self.species() == super::Species::Rabbit {
super::rabbit::jump(self, w);
return;
}
if matches!(
self.species(),
super::Species::Slime | super::Species::MagmaCube | super::Species::SulfurCube
+486
View File
@@ -0,0 +1,486 @@
//! Rabbit hopping controls and the clocks consumed by `RabbitModel`.
use super::{Mob, MobEvent, MobWorld, control::Operation};
use horizon_core::{
geometry::{Vec3, trig},
random::RandomSource,
};
// Rabbit's transient state in Extra (none of these clocks are saved).
const JUMP_TICKS: usize = 0;
const JUMP_DURATION: usize = 1;
const MOVE_DELAY: usize = 2;
const IDLE_TIMEOUT: usize = 3;
// Client counters start only when the actual ground jump emits entity event 1.
const CLIENT_JUMP_TICKS: usize = 4;
const CLIENT_JUMP_DURATION: usize = 5;
pub fn register(m: &mut Mob) {
m.ai.mov.kind = super::control::MoveKind::Custom;
m.ai.nav.can_float = true;
m.extra.ints[IDLE_TIMEOUT] = m.random.next_int_bound(40).unwrap_or(0) + 180;
}
/// Rabbit.baseTick: the idle timeout branch precedes the hop clock branch.
pub fn base_tick(m: &mut Mob) {
let age = m.age as f32;
let leashed = m.extra.leash.is_some();
if m.extra.ints[IDLE_TIMEOUT] <= 0 && !leashed && !m.no_ai {
m.extra.ints[IDLE_TIMEOUT] = m.random.next_int_bound(40).unwrap_or(0) + 180;
m.anim.states[1].start(age);
} else if m.extra.ints[CLIENT_JUMP_TICKS] > 0 {
m.anim.states[0].start_if_stopped(age);
m.anim.states[1].stop();
} else {
m.extra.ints[IDLE_TIMEOUT] -= 1;
m.anim.states[0].stop();
}
if leashed {
m.anim.states[1].stop();
}
}
fn start_jumping(m: &mut Mob) {
m.ai.jumping = true;
m.extra.ints[JUMP_DURATION] = 15;
m.extra.ints[JUMP_TICKS] = 0;
let pitch = ((m.random.next_float() - m.random.next_float()) * 0.2 + 1.0) * 0.8;
if !m.silent {
m.outbox.push(MobEvent::Sound(
"entity.rabbit.jump",
[m.position.x, m.position.y, m.position.z],
1.0,
pitch,
));
}
}
/// Rabbit.customServerAiStep: start a hop toward the current path waypoint.
pub fn server_ai_step(m: &mut Mob) {
// RabbitMoveControl.setWantedPosition applies the water override before landing checks.
if m.fluids.in_water && m.ai.mov.speed_modifier > 0.0 {
m.ai.mov.speed_modifier = 1.5;
}
if m.extra.ints[MOVE_DELAY] > 0 {
m.extra.ints[MOVE_DELAY] -= 1;
}
if m.on_ground {
if !m.extra.flag {
m.ai.jumping = false;
m.extra.ints[MOVE_DELAY] = if m.ai.mov.speed_modifier < 2.2 { 10 } else { 3 };
}
if !m.ai.jump && m.ai.mov.has_wanted() && m.extra.ints[MOVE_DELAY] == 0 {
let mut at = m.ai.mov.wanted;
if let Some(path) = m.ai.nav.path.as_ref().filter(|p| !p.is_done()) {
let p = path.entity_pos_at(path.next, m.width());
at = [p.x, p.y, p.z];
}
m.yaw = trig::atan2_degrees(at[2] - m.position.z, at[0] - m.position.x) - 90.0;
start_jumping(m);
}
}
m.extra.flag = m.on_ground;
}
/// RabbitMoveControl.tick: wait on the ground and restore the last wanted speed in flight.
pub fn move_control(m: &mut Mob, w: &MobWorld) {
prepare_move(m);
m.ground_move_tick(w, m.movement_speed());
}
fn prepare_move(m: &mut Mob) {
if m.ai.mov.speed_modifier > 0.0 {
m.extra.vector[0] = if m.fluids.in_water {
1.5
} else {
m.ai.mov.speed_modifier
};
}
if m.on_ground && !m.ai.jumping && !m.ai.jump {
m.ai.mov.speed_modifier = 0.0;
m.set_speed(0.0);
} else if m.ai.mov.has_wanted() || m.ai.mov.operation == Operation::Jumping {
m.ai.mov.speed_modifier = if m.fluids.in_water {
1.5
} else {
m.extra.vector[0]
};
}
}
/// RabbitJumpControl.tick: explicit jump requests do not wait for the landing cooldown.
pub fn jump_control(m: &mut Mob) {
if m.ai.jump {
start_jumping(m);
m.ai.jump = false;
}
}
/// Rabbit.aiStep runs after the living physics; the fifteenth tick still renders the hop.
pub fn post_tick(m: &mut Mob) {
for (ticks, duration) in [
(JUMP_TICKS, JUMP_DURATION),
(CLIENT_JUMP_TICKS, CLIENT_JUMP_DURATION),
] {
if m.extra.ints[ticks] != m.extra.ints[duration] {
m.extra.ints[ticks] += 1;
} else if m.extra.ints[duration] != 0 {
m.extra.ints[ticks] = 0;
m.extra.ints[duration] = 0;
if ticks == JUMP_TICKS {
m.ai.jumping = false;
}
}
}
}
fn jump_scale(m: &Mob) -> f32 {
let step =
m.ai.nav
.path
.as_ref()
.filter(|p| !p.is_done())
.is_some_and(|p| f64::from(p.next_node().y) > m.position.y + 0.5);
let high =
m.horizontal_collision || step || m.ai.jumping && m.ai.mov.wanted[1] > m.position.y + 0.5;
let base = if high {
0.5
} else if m.ai.mov.speed_modifier <= 0.6 {
0.2
} else {
0.3
};
base / 0.42
}
/// Rabbit.jumpFromGround: ordinary small hops, larger hops toward raised terrain.
pub fn jump(m: &mut Mob, w: &MobWorld) {
let power = jump_power(m, block_jump_factor(m, w));
apply_jump(m, power);
}
fn jump_power(m: &Mob, block_factor: f32) -> f32 {
let boost = m
.extra
.effects
.iter()
.find(|e| e.0 == "minecraft:jump_boost")
.map_or(0.0, |e| 0.1 * (e.2 + 1) as f32);
m.attrs.jump_strength as f32 * jump_scale(m) * block_factor + boost
}
fn apply_jump(m: &mut Mob, power: f32) {
if power > 1.0e-5 {
m.velocity.y = f64::from(power).max(m.velocity.y);
}
if m.ai.mov.speed_modifier > 0.0
&& m.velocity.x * m.velocity.x + m.velocity.z * m.velocity.z < 0.01
{
m.move_relative(
0.1,
Vec3::new(0.0, if m.is_baby() { 0.5 } else { 1.5 }, 1.0),
);
}
hop_event(m);
m.outbox.push(MobEvent::RabbitHop {
mob: m.id,
at: [m.position.x, m.position.y, m.position.z],
});
}
/// Rabbit.handleEntityEvent(1): reset the counter without starting the clock early.
pub fn hop_event(m: &mut Mob) {
m.extra.ints[CLIENT_JUMP_DURATION] = 15;
m.extra.ints[CLIENT_JUMP_TICKS] = 0;
}
fn block_jump_factor(m: &Mob, w: &MobWorld) -> f32 {
let properties = w.movement;
let current = w.world.block(
m.position.x.floor() as i32,
m.position.y.floor() as i32,
m.position.z.floor() as i32,
);
let below = m.on_pos(0.500_001);
// shortcut: use mobs' existing on_pos until they track supporting blocks like the player.
let lower = w.world.block(below[0], below[1], below[2]);
let current = properties
.get(current)
.expect("validated movement registry")
.coefficients
.jump_factor;
let lower = properties
.get(lower)
.expect("validated movement registry")
.coefficients
.jump_factor;
if current == 1.0 { lower } else { current }
}
#[cfg(test)]
mod tests {
use super::*;
use crate::mobs::{
Anim, Brain, Flags, MobType, Part, Species,
anim::{self, Poses},
body_anim,
keyframes::Animation,
};
use serde_json::json;
use std::{collections::HashMap, sync::Arc};
fn rabbit() -> Mob {
let model = Arc::new(Part::parse(
"root",
&json!({"children": {"head": {}, "left_hind_foot": {}}}),
));
let kind = Arc::new(MobType {
id: "minecraft:rabbit".into(),
species: Species::Rabbit,
width: 0.4,
height: 0.5,
eye_height: 0.4,
category: "creature".into(),
max_health: 3.0,
speed: 0.3,
flying_speed: 0.4,
attack_damage: 0.0,
attack_knockback: 0.0,
follow_range: 16.0,
step_height: 0.6,
armor: 0.0,
armor_toughness: 0.0,
knockback_resistance: 0.0,
jump_strength: 0.42,
attributes: Arc::default(),
gravity: 0.08,
safe_fall_distance: 3.0,
fall_damage_multiplier: 1.0,
water_efficiency: 0.0,
water_slowdown: 0.8,
air_speed: 0.02,
baby_scale: 0.5,
head_rot_speed: 10.0,
max_head_x_rot: 40.0,
max_head_y_rot: 75.0,
ambient_interval: 120,
flags: Flags {
animal: true,
..Default::default()
},
model,
layers: HashMap::new(),
texture: String::new(),
brain: Brain::Passive,
anim: Anim::Rabbit,
sounds: [""; 3],
step_sound: None,
food: Arc::default(),
tempt: Arc::default(),
});
Mob::new(1, kind, Vec3::ZERO, 0.0)
}
fn near(a: f64, b: f64) {
assert!((a - b).abs() < 1.0e-6, "{a} != {b}");
}
#[test]
fn summoned_age_selects_the_baby_model_and_texture() {
let mut template = rabbit();
let kind = Arc::make_mut(&mut template.kind);
kind.texture = "entity/rabbit/rabbit_brown".into();
kind.layers
.insert("rabbit_baby#main".into(), kind.model.clone());
let types = HashMap::from([(kind.id.clone(), template.kind.clone())]);
for (age, baby) in [(-24000, true), (-1, true), (0, false), (6000, false)] {
let (tag, _) = horizon_world::nbt::parse_snbt(&format!(
"{{id:\"minecraft:rabbit\",Pos:[0.0d,0.0d,0.0d],Age:{age}}}"
))
.unwrap();
let m = crate::entity_nbt::mob_from_nbt(&tag, &types, 2).unwrap();
assert_eq!(m.extra.age, age);
assert_eq!(m.is_baby(), baby);
assert_eq!(
crate::mobs::render::body(&m),
if baby {
(
"rabbit_baby#main".into(),
"entity/rabbit/rabbit_brown_baby".into(),
)
} else {
("rabbit#main".into(), "entity/rabbit/rabbit_brown".into())
}
);
}
}
#[test]
fn landing_waits_then_real_hop_clock_moves_the_model() {
let mut m = rabbit();
m.on_ground = true;
m.ai.mov.set_wanted(0.0, 0.0, 5.0, 0.6);
server_ai_step(&mut m);
assert_eq!(m.extra.ints[MOVE_DELAY], 10);
assert!(!m.ai.jumping);
for _ in 0..9 {
server_ai_step(&mut m);
}
assert!(!m.ai.jumping);
server_ai_step(&mut m);
assert!(m.ai.jumping);
assert_eq!(m.extra.ints[JUMP_DURATION], 15);
assert_eq!(m.anim.states[0].started, None);
apply_jump(&mut m, 0.2);
post_tick(&mut m);
m.age = 1;
base_tick(&mut m);
assert_eq!(m.anim.states[0].started, Some(1.0));
let curve = Animation::parse(&json!({"length": 0.75, "looping": true,
"bones": {"left_hind_foot": [{"target": "rotation", "keyframes": [[0,[0,0,0],[0,0,0],"linear"],[0.75,[1,0,0],[1,0,0],"linear"]]}]}}));
let animations = HashMap::from([("RabbitAnimation.HOP".into(), curve)]);
let mut poses = Poses::new(&m.kind.model);
let state = anim::state(&m, 0.5);
body_anim::rabbit(
&mut poses,
&state,
&m.anim.states[0],
&m.anim.states[1],
&animations,
);
assert!(poses.get("left_hind_foot")[3] > 0.0);
for _ in 1..15 {
post_tick(&mut m);
}
assert_eq!(m.extra.ints[JUMP_TICKS], 15);
assert!(m.ai.jumping);
post_tick(&mut m);
base_tick(&mut m);
assert!(!m.ai.jumping);
assert_eq!(m.anim.states[0].started, None);
}
#[test]
fn panic_and_explicit_requests_use_their_own_hop_timing() {
let mut m = rabbit();
m.on_ground = true;
m.ai.mov.set_wanted(0.0, 0.0, 5.0, 2.2);
server_ai_step(&mut m);
assert_eq!(m.extra.ints[MOVE_DELAY], 3);
m.ai.jump = true;
m.jump_control_tick();
assert!(m.ai.jumping);
assert!(!m.ai.jump);
assert_eq!(m.extra.ints[MOVE_DELAY], 3);
m.jump_control_tick();
assert!(m.ai.jumping);
}
#[test]
fn a_new_hop_preserves_a_running_clock_until_the_counter_finishes() {
let mut m = rabbit();
m.anim.states[0].start(4.0);
m.extra.ints[CLIENT_JUMP_TICKS] = 8;
hop_event(&mut m);
assert_eq!(m.anim.states[0].started, Some(4.0));
assert_eq!(m.extra.ints[CLIENT_JUMP_TICKS], 0);
assert_eq!(m.extra.ints[CLIENT_JUMP_DURATION], 15);
post_tick(&mut m);
m.age = 12;
base_tick(&mut m);
assert_eq!(m.anim.states[0].started, Some(4.0));
assert!(m.outbox.is_empty());
}
#[test]
fn deep_water_jump_requests_do_not_start_a_client_hop() {
let mut m = rabbit();
m.fluids.in_water = true;
m.fluids.water = 1.0;
m.ai.jump = true;
jump_control(&mut m);
assert!(m.ai.jumping);
assert_eq!(m.extra.ints[JUMP_DURATION], 15);
post_tick(&mut m);
base_tick(&mut m);
assert_eq!(m.extra.ints[JUMP_TICKS], 1);
assert_eq!(m.extra.ints[CLIENT_JUMP_DURATION], 0);
assert!(m.anim.states[0].started.is_none());
assert!(
!m.outbox
.iter()
.any(|e| matches!(e, MobEvent::RabbitHop { .. }))
);
hop_event(&mut m);
post_tick(&mut m);
base_tick(&mut m);
assert!(m.anim.states[0].started.is_some());
}
#[test]
fn grounded_movement_waits_and_water_uses_its_hop_speed() {
let mut m = rabbit();
m.on_ground = true;
m.ai.mov.set_wanted(0.0, 0.0, 5.0, 0.6);
prepare_move(&mut m);
assert_eq!(m.ai.mov.speed_modifier, 0.0);
assert_eq!(m.ai.zza, 0.0);
m.ai.jumping = true;
prepare_move(&mut m);
assert_eq!(m.ai.mov.speed_modifier, 0.6);
m.fluids.in_water = true;
prepare_move(&mut m);
assert_eq!(m.ai.mov.speed_modifier, 1.5);
assert_eq!(m.extra.vector[0], 1.5);
assert!(m.ai.nav.can_float);
m.extra.flag = false;
m.ai.mov.set_wanted(0.0, 0.0, 5.0, 2.2);
server_ai_step(&mut m);
assert_eq!(m.ai.mov.speed_modifier, 1.5);
assert_eq!(m.extra.ints[MOVE_DELAY], 10);
}
#[test]
fn jump_impulse_scales_strength_terrain_boost_and_baby_kick() {
let mut m = rabbit();
m.ai.mov.speed_modifier = 0.6;
near(f64::from(jump_power(&m, 1.0)), 0.2);
m.ai.mov.speed_modifier = 2.2;
near(f64::from(jump_power(&m, 1.0)), 0.3);
m.horizontal_collision = true;
near(f64::from(jump_power(&m, 1.0)), 0.5);
m.attrs.jump_strength = 0.84;
m.extra.effects.push(("minecraft:jump_boost", 100, 1));
near(f64::from(jump_power(&m, 0.5)), 0.7);
apply_jump(&mut m, 0.2);
near(m.velocity.z, 0.1 / 3.25_f64.sqrt());
near(m.velocity.y, 0.2 + 0.15 / 3.25_f64.sqrt());
m.extra.age = -100;
m.velocity = Vec3::ZERO;
apply_jump(&mut m, 0.2);
near(m.velocity.z, 0.1 / 1.25_f64.sqrt());
near(m.velocity.y, 0.2 + 0.05 / 1.25_f64.sqrt());
assert_eq!(m.extra.ints[CLIENT_JUMP_DURATION], 15);
}
#[test]
fn idle_timeout_hop_priority_no_ai_and_leash_follow_tick_order() {
let mut m = rabbit();
m.age = 7;
m.extra.ints[IDLE_TIMEOUT] = 0;
m.extra.ints[CLIENT_JUMP_TICKS] = 2;
base_tick(&mut m);
assert_eq!(m.anim.states[1].started, Some(7.0));
assert!(m.anim.states[0].started.is_none());
base_tick(&mut m);
assert_eq!(m.anim.states[0].started, Some(7.0));
assert!(m.anim.states[1].started.is_none());
m.extra.ints[CLIENT_JUMP_TICKS] = 0;
m.extra.ints[IDLE_TIMEOUT] = 0;
m.no_ai = true;
base_tick(&mut m);
assert_eq!(m.extra.ints[IDLE_TIMEOUT], -1);
assert!(m.anim.states[1].started.is_none());
m.no_ai = false;
base_tick(&mut m);
assert!(m.anim.states[1].started.is_some());
m.extra.leash = Some(super::super::leash::Holder::Knot([0, 0, 0]));
base_tick(&mut m);
assert!(m.anim.states[1].started.is_none());
}
}
+4
View File
@@ -169,6 +169,10 @@ pub fn body(m: &Mob) -> (String, String) {
"frog#main".into(),
format!("entity/frog/frog_{}", climate(m)),
),
S::Rabbit => (
baby_or(m, "rabbit#main", "rabbit_baby#main"),
b(&m.kind.texture),
),
S::Pig => {
let model = if baby {
"pig_baby#main".into()