Merge main into fix/server-mob-animation-sync

Brings main in so the branch has one merge base with it (GitHub saw a
conflict through the criss-cross bases; the merge itself is clean).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-27 12:08:05 +01:00
144 changed files with 7145 additions and 867 deletions
+57 -18
View File
@@ -185,6 +185,18 @@ pub fn register(m: &mut Mob) {
if m.species() == Species::Rabbit {
super::rabbit::register(m);
}
if m.species() == Species::Frog {
// `Frog()`: SmoothSwimmingMoveControl(85, 10, 0.02, 0.1, true).
// The speed attribute is 1.0, so the controller's scaling is
// what keeps a frog at a walking pace on land.
m.ai.mov.kind = super::control::MoveKind::SmoothSwimming {
max_turn_x: 85.0,
max_turn_y: 10.0,
in_water: 0.02,
outside: 0.1,
gravity: true,
};
}
if m.species() == Species::Turtle {
super::turtle::register(m);
}
@@ -321,6 +333,20 @@ fn generic(m: &mut Mob) {
m.ai.targets.add(1, HurtByTarget::new());
m.ai.targets.add(2, NearestTarget::player(true));
} else {
if m.kind.species == Species::Goat {
// GoatAi's idle and core behaviours (the ram and long jump
// activities are not here): panic 2.0, AnimalMakeLove, tempting
// with goat_food and baby follow at 1.25, then stroll.
g.add(0, Float);
g.add(1, Panic::new(2.0));
g.add(2, Breed::new(1.0));
g.add(3, Tempt::new(1.25, m.kind.food.clone(), false));
g.add(4, FollowParent::new(1.25));
g.add(5, Stroll::avoiding_water(1.0));
g.add(6, LookAtPlayer::new(6.0));
g.add(7, RandomLookAround::default());
return;
}
g.add(0, Float);
let rabbit = m.kind.species == Species::Rabbit;
g.add(1, Panic::new(if rabbit { 2.2 } else { 1.25 }));
@@ -462,6 +488,16 @@ pub fn tick_swing(m: &mut Mob) {
}
m.anim.attack_anim = m.ai.swing_time as f32 / 6.0;
}
/// `Entity.isInRain`: rain at the block position, or at the top of the box.
pub(super) fn in_rain(m: &Mob, w: &MobWorld) -> bool {
let (x, y, z) = (
m.position.x.floor() as i32,
m.position.y.floor() as i32,
m.position.z.floor() as i32,
);
let top = (m.position.y + f64::from(m.height())).floor() as i32;
w.raining_at(x, y, z) || w.raining_at(x, top, z)
}
/// `LivingEntity.baseTick` refills a breather's air by 4, then
/// `Axolotl.handleAirSupply` (unless the mob has no AI): water or rain fills
/// it, anywhere else it runs down from the pre-tick value, and at -20 the
@@ -472,15 +508,7 @@ fn axolotl_air_supply(m: &mut Mob, w: &MobWorld) {
if m.no_ai {
return;
}
// Entity.isInRain: rain at the block, or at the top of the box.
let (x, y, z) = (
m.position.x.floor() as i32,
m.position.y.floor() as i32,
m.position.z.floor() as i32,
);
let top = (m.position.y + f64::from(m.height())).floor() as i32;
let in_rain = w.raining_at(x, y, z) || w.raining_at(x, top, z);
if m.fluids.in_water || in_rain {
if m.fluids.in_water || in_rain(m, w) {
m.air = super::axolotl::MAX_AIR;
} else {
m.air = before - 1;
@@ -508,8 +536,9 @@ fn base_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
);
m.damage(fire, Damage::of(DamageKind::InFire));
}
// Fire: water extinguishes, lava ignites, burning hurts every second.
if m.fluids.in_water && m.fire_ticks > 0 {
// Fire: water or rain (Entity.isInRain) extinguishes, lava ignites,
// burning hurts every second.
if m.fire_ticks > 0 && (m.fluids.in_water || in_rain(m, w)) {
m.fire_ticks = 0;
events.push(MobEvent::Sound(
"entity.generic.extinguish_fire",
@@ -580,9 +609,7 @@ fn base_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
m.air = (m.air + 4).min(300);
}
if m.kind.flags.water_sensitive
&& (m.fluids.in_water || w.raining && w.can_see_sky(ex, ey, ez))
{
if m.kind.flags.water_sensitive && (m.fluids.in_water || in_rain(m, w)) {
m.damage(1.0, Damage::of(DamageKind::Drown));
}
freeze_tick(m, w);
@@ -608,7 +635,7 @@ fn base_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
let t = m.ambient_timer;
m.ambient_timer += 1;
if roll < t {
m.ambient_timer = -m.kind.ambient_interval;
m.ambient_timer = -m.ambient_interval();
play_ambient(m, w, events);
}
}
@@ -970,7 +997,7 @@ fn sun_burn_tick(m: &mut Mob, w: &MobWorld) -> bool {
m.position.z.floor() as i32,
);
let br = w.brightness(x, y, z);
let wet = m.fluids.in_water || w.raining && w.can_see_sky(x, y, z);
let wet = m.fluids.in_water || in_rain(m, w);
br > 0.5 && m.random.next_float() * 30.0 < (br - 0.4) * 2.0 && !wet && w.can_see_sky(x, y, z)
}
/// Mob.serverAiStep
@@ -1757,8 +1784,20 @@ pub fn step_sound(
S::Husk => quiet("entity.husk.step"),
S::Drowned => quiet("entity.drowned.step"),
S::ZombieVillager => quiet("entity.zombie_villager.step"),
S::CamelHusk => Some(("entity.camel_husk.step", 0.4, 1.0)),
S::Camel => Some(("entity.camel.step", 1.0, 1.0)),
// Camel.playStepSound and CamelHusk.playStepSound: sand and concrete
// powder have their own step.
S::CamelHusk | S::Camel => {
let sand = w.has_tag(
"minecraft:camel_sand_step_sound_blocks",
&w.facts.get(state).name,
);
Some(match (m.species(), sand) {
(S::Camel, true) => ("entity.camel.step_sand", 1.0, 1.0),
(S::Camel, false) => ("entity.camel.step", 1.0, 1.0),
(_, true) => ("entity.camel_husk.step_sand", 0.4, 1.0),
(_, false) => ("entity.camel_husk.step", 0.4, 1.0),
})
}
S::IronGolem => Some(("entity.iron_golem.step", 1.0, 1.0)),
// CopperGolem.playStepSound: its oxidation level's step.
S::CopperGolem => Some((super::copper_golem::sound(m, "step"), 1.0, 1.0)),
+1 -1
View File
@@ -259,7 +259,7 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
}
S::Dolphin => {
// Dolphin.tick: moisture out of water, hop on land.
if m.fluids.in_water || w.raining {
if m.fluids.in_water || super::ai::in_rain(m, w) {
m.extra.counter = 2400;
} else {
m.extra.counter -= 1;
+16 -9
View File
@@ -323,12 +323,19 @@ pub fn sting(m: &mut Mob, who: Who, cx: &mut Cx) {
match who {
Who::Player => {
cx.events.push(MobEvent::AttackPlayer(amount, from));
let seconds = if cx.w.difficulty.hard { 18 } else { 10 };
cx.events.push(MobEvent::EffectPlayer {
effect: "minecraft:poison",
ticks: seconds * 20,
amplifier: 0,
});
// Poison only on normal (10 s) and hard (18 s).
let seconds = match cx.w.difficulty.id {
2 => 10,
3 => 18,
_ => 0,
};
if seconds > 0 {
cx.events.push(MobEvent::EffectPlayer {
effect: "minecraft:poison",
ticks: seconds * 20,
amplifier: 0,
});
}
}
Who::Mob(id) => cx.events.push(MobEvent::AttackMob {
target: id,
@@ -421,10 +428,10 @@ pub fn drop_off_nectar(m: &mut Mob) {
set_has_nectar(m, false);
st(m).crops_grown = 0;
}
/// `Bee.setStayOutOfHiveCountdown`, which in 26.3 only resets the time
/// without nectar.
/// `Bee.setStayOutOfHiveCountdown`: the bee will not enter a hive for 400
/// ticks (the hive passes that when a sedated hive lets its bees out).
pub fn set_stay_out_of_hive_countdown(m: &mut Mob) {
st(m).ticks_without_nectar = 0;
st(m).stay_out_of_hive = 400;
}
fn drop_hive(m: &mut Mob) {
let b = st(m);
+2 -1
View File
@@ -980,9 +980,10 @@ pub fn anim(m: &Mob, s: &State, p: &mut Poses, a: &Animations) -> bool {
Species::Parrot => {
let flap = m.anim.flap_o + (m.anim.flap - m.anim.flap_o) * s.partial;
let speed = m.anim.flap_speed_o + (m.anim.flap_speed - m.anim.flap_speed_o) * s.partial;
// `Parrot.isFlying` is `!onGround`, in water too.
let pose = if m.extra.sitting {
ParrotPose::Sitting
} else if !m.on_ground && !m.fluids.in_water {
} else if !m.on_ground {
ParrotPose::Flying
} else {
ParrotPose::Standing
+5 -4
View File
@@ -24,12 +24,13 @@ pub fn register(m: &mut Mob) {
m.extra.tame = true;
let tempt = m.kind.tempt.clone();
let g = &mut m.ai.goals;
// CamelAi speed modifiers (times the 0.09 movement speed attribute).
g.add(0, Float);
g.add(1, CamelPanic(Panic::new(4.0 * 0.25)));
g.add(1, CamelPanic(Panic::new(4.0)));
g.add(2, Breed::new(1.0));
g.add(3, Tempt::new(2.5 * 0.25, tempt, false));
g.add(4, FollowParent::new(2.5 * 0.25));
g.add(5, Stroll::new(2.0 * 0.25));
g.add(3, Tempt::new(2.5, tempt, false));
g.add(4, FollowParent::new(2.5));
g.add(5, Stroll::new(2.0));
g.add(5, RandomSitting);
g.add(6, LookAtPlayer::new(6.0));
g.add(7, RandomLookAround::default());
+10 -2
View File
@@ -1,6 +1,6 @@
//! Mob controls: `MoveControl` (with the flying and smooth-swimming
//! variants), `LookControl`, `JumpControl` and `BodyRotationControl`.
use super::{Mob, MobWorld, living::wrap};
use super::{Mob, MobWorld, Species, living::wrap};
use horizon_core::geometry::trig;
/// `2.5000003E-7F` widened: the squared distance controls treat as arrived.
@@ -116,8 +116,16 @@ pub struct BodyRotation {
last_stable_head: f32,
}
impl Mob {
/// `Mob.getMaxHeadXRot`, with `Wolf`'s 20 degrees while sitting.
pub fn max_head_x_rot(&self) -> f32 {
if self.species() == Species::Wolf && self.extra.sitting {
20.0
} else {
self.kind.max_head_x_rot
}
}
pub fn look_at(&mut self, at: [f64; 3]) {
let (y, x) = (self.kind.head_rot_speed, self.kind.max_head_x_rot);
let (y, x) = (self.kind.head_rot_speed, self.max_head_x_rot());
self.ai.look.set_look_at(at, y, x);
}
pub fn look_at_speed(&mut self, at: [f64; 3], y_speed: f32, x_max: f32) {
+22
View File
@@ -403,6 +403,15 @@ pub fn die(m: &mut Mob, d: &Death, sequences: &mut RandomSequences) -> (Vec<Drop
out.push(Drop::Item(stack));
clear_slot(m, "mainhand");
}
// Allay: what it carries (`ints[1]` of the held item) is its inventory.
let allay_load = (s == Species::Allay)
.then(|| {
m.extra
.main_hand
.clone()
.map(|item| (item, m.extra.ints[1]))
})
.flatten();
let drops_loot = d.mob_drops && (is_monster(s) || !m.is_baby());
if drops_loot {
let table = format!(
@@ -459,6 +468,19 @@ pub fn die(m: &mut Mob, d: &Death, sequences: &mut RandomSequences) -> (Vec<Drop
out.push(Drop::Item(loot_stack("minecraft:nether_star", 1)));
}
}
// Allay.dropEquipment: its inventory, then the main-hand item unless it
// prevents equipment drops.
if let Some((item, carried)) = allay_load {
if carried > 0 {
out.push(Drop::Item(loot_stack(&item, carried)));
}
if let Some(stack) = slot_item(m, "mainhand")
&& !d.loot.prevents_equipment_drop(&stack)
{
out.push(Drop::Item(stack));
clear_slot(m, "mainhand");
}
}
// Piglin.dropCustomDeathLoot: everything in its inventory.
if s == Species::Piglin {
for stack in m.extra.inventory.drain(..) {
+1 -9
View File
@@ -184,15 +184,7 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
}
}
}
if (m.fluids.in_water
|| w.raining
&& w.can_see_sky(
m.position.x.floor() as i32,
m.eye_y().floor() as i32,
m.position.z.floor() as i32,
))
&& m.alive()
{
if (m.fluids.in_water || super::ai::in_rain(m, w)) && m.alive() {
// Hurt by water: teleport away.
m.extra.counter2 = m.extra.counter2.max(1);
}
+2 -2
View File
@@ -1778,7 +1778,7 @@ impl Goal for Tempt {
}
fn tick(&mut self, m: &mut Mob, cx: &mut Cx) {
let Some(p) = cx.w.player.clone() else { return };
let (y, x) = (m.kind.max_head_y_rot + 20.0, m.kind.max_head_x_rot);
let (y, x) = (m.kind.max_head_y_rot + 20.0, m.max_head_x_rot());
m.look_at_speed(p.eye, y, x);
if m.distance_sqr(p.position) < self.stop_distance * self.stop_distance {
m.nav_stop();
@@ -1887,7 +1887,7 @@ impl Goal for Breed {
let Some(p) = self.partner.and_then(|p| cx.w.seen(p)).cloned() else {
return;
};
let x = m.kind.max_head_x_rot;
let x = m.max_head_x_rot();
m.look_at_speed([p.position.x, p.eye_y, p.position.z], 10.0, x);
m.nav_move_to_entity(
cx.w,
@@ -544,14 +544,15 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld) {
m.ai.home = Some((here, radius));
}
}
// continuousHeal: a point every 30 seconds, every second in rain.
// continuousHeal: a point every 30 seconds, every second in rain or snow
// (Level.precipitationAt).
if m.alive() && m.death_time == 0 && m.health < m.attrs.max_health {
let (x, y, z) = (
m.position.x.floor() as i32,
m.position.y.floor() as i32,
m.position.z.floor() as i32,
);
let wet = w.raining && w.can_see_sky(x, y, z);
let wet = w.precipitation_at(x, y, z).is_some();
let interval = if wet { 20 } else { 600 };
if m.age.is_multiple_of(interval) {
m.health = (m.health + 1.0).min(m.attrs.max_health);
+150 -2
View File
@@ -9,8 +9,15 @@ use crate::{
};
use horizon_core::{
geometry::{Aabb, Vec3, trig},
position::BlockPos,
random::RandomSource,
};
use horizon_world::{
entity_fluid::{CurrentAccumulator, CurrentTarget},
fluid::{FluidKind, FluidState},
fluid_flow::{FluidFlowWorld, flow_at},
registry::BlockStateId,
};
/// `Entity.moveDist`, `flyDist` and `nextStep`.
#[derive(Clone, Copy, Debug)]
@@ -36,6 +43,50 @@ pub struct Fluids {
pub in_lava: bool,
pub eye_in_water: bool,
}
/// `FluidFlowWorld` over the mob's scene: the neighbours a flow vector reads.
struct FlowScene<'a, 'w>(&'a MobWorld<'w>);
impl FluidFlowWorld for FlowScene<'_, '_> {
type Error = std::convert::Infallible;
type Block = BlockStateId;
fn fluid(&mut self, p: BlockPos) -> Result<FluidState, Self::Error> {
Ok(self.0.fluid_tables.fluid(self.0.world.block(p.x, p.y, p.z)))
}
fn block(&mut self, p: BlockPos) -> Result<BlockStateId, Self::Error> {
Ok(self.0.world.block(p.x, p.y, p.z))
}
fn blocks_fluid_flow(&self, s: BlockStateId) -> bool {
self.0.fluid_tables.blocks_flow(s)
}
fn is_ice_class(&self, s: BlockStateId) -> bool {
self.0.fluid_tables.ice(s)
}
fn is_face_sturdy(
&mut self,
s: BlockStateId,
_: BlockPos,
d: horizon_core::geometry::Direction,
) -> Result<bool, Self::Error> {
Ok(self.0.fluid_tables.sturdy(s, d))
}
}
/// The mob's velocity, for `CurrentAccumulator::apply_to`.
struct Pushed<'a>(&'a mut Vec3);
impl CurrentTarget for Pushed<'_> {
type Error = std::convert::Infallible;
fn is_player_class(&self) -> bool {
false
}
fn velocity(&mut self) -> Result<Vec3, Self::Error> {
Ok(*self.0)
}
fn add_delta_movement(&mut self, delta: Vec3) -> Result<(), Self::Error> {
let sum = Vec3::new(self.0.x + delta.x, self.0.y + delta.y, self.0.z + delta.z);
if delta.is_finite() && sum.is_finite() {
*self.0 = sum;
}
Ok(())
}
}
pub fn wrap(a: f32) -> f32 {
let mut a = a % 360.0;
if a >= 180.0 {
@@ -140,6 +191,40 @@ impl MobWorld<'_> {
}
out
}
/// Entity.updateFluidHeightAndDoFluidPushing's currents over the deflated
/// box: the flow of every water and lava block it touches, summed (a thin
/// fluid layer scales its flow down), as (water, lava).
fn fluid_currents(&self, bounds: Aabb) -> (CurrentAccumulator, CurrentAccumulator) {
let base_y = bounds.min_position().y;
let b = bounds.deflate(Vec3::new(0.001, 0.001, 0.001));
let (lo, hi) = (b.min_position(), b.max_position());
let mut scene = FlowScene(self);
let (mut water, mut lava) = (CurrentAccumulator::default(), CurrentAccumulator::default());
for x in lo.x.floor() as i32..=(hi.x.ceil() as i32 - 1) {
for y in lo.y.floor() as i32..=(hi.y.ceil() as i32 - 1) {
for z in lo.z.floor() as i32..=(hi.z.ceil() as i32 - 1) {
let p = BlockPos::new(x, y, z);
let state = self.fluid_tables.fluid(self.world.block(x, y, z));
let current = match state.kind() {
FluidKind::Empty => continue,
FluidKind::Water | FluidKind::FlowingWater => &mut water,
FluidKind::Lava | FluidKind::FlowingLava => &mut lava,
};
let surface = f64::from(y) + self.fluid_height(x, y, z).1;
if surface < lo.y {
continue;
}
current.height = current.height.max(surface - base_y);
let mut flow = flow_at(&mut scene, state, p).unwrap_or(Vec3::ZERO);
if current.height < 0.4 {
flow = flow.scale(current.height);
}
current.accumulate(flow);
}
}
}
(water, lava)
}
/// `BlockState.getCollisionShape(level, pos)` (the empty collision
/// context) as boxes in the world.
pub fn block_collision_boxes(&self, x: i32, y: i32, z: i32) -> Vec<Aabb> {
@@ -301,6 +386,15 @@ impl Mob {
return (f64::from(0.2_f32), f64::from(0.2_f32), f64::from(0.2_f32));
}
let k = &self.kind;
// Avatar.POSES: a player's or mannequin's box follows its pose.
if matches!(&*k.id, "minecraft:player" | "minecraft:mannequin") {
let d = self.extra.avatar_pose.dimensions(1.0);
return (
f64::from(d.width),
f64::from(d.height),
f64::from(d.eye_height),
);
}
let (mut w, mut h, mut e) = (k.width as f32, k.height as f32, k.eye_height as f32);
// Sniffer.DIGGING_DIMENSIONS: 0.4 lower, its eyes at 0.81.
if k.species == super::Species::Sniffer && super::sniffer::digging(self) {
@@ -354,6 +448,27 @@ impl Mob {
pub fn is_in_liquid(&self) -> bool {
self.fluids.in_water || self.fluids.in_lava
}
/// `Entity.isPushedByFluid`: water animals, turtles, axolotls, frogs and
/// nautiluses keep their own course.
fn pushed_by_fluid(&self) -> bool {
use super::Species as S;
!matches!(
self.species(),
S::Tadpole
| S::Cod
| S::Salmon
| S::TropicalFish
| S::Pufferfish
| S::Squid
| S::GlowSquid
| S::Dolphin
| S::Turtle
| S::Axolotl
| S::Frog
| S::Nautilus
| S::ZombieNautilus
)
}
fn affected_by_fluids(&self) -> bool {
true
}
@@ -448,6 +563,17 @@ impl Mob {
// Entity.checkSupportingBlock
self.supporting = self.supporting_block(w, moved);
self.movement_emission(w, moved, events);
// Entity.applyEffectsFromBlocks: bubble columns push the mob.
if crate::motion::bubble_column_push(
w.world,
w.registry,
w.facts,
w.collision,
self.bounds(),
&mut self.velocity,
) {
self.fall_distance = 0.0;
}
}
/// LivingEntity.checkFallDamage: the fluid state refreshed out of water
/// (touching water resets the fall), then Entity.checkFallDamage.
@@ -470,6 +596,22 @@ impl Mob {
pub(super) fn update_fluids(&mut self, w: &MobWorld, events: &mut Vec<MobEvent>) {
let was_touching_water = self.fluids.in_water;
self.fluids = w.fluids(self.bounds(), self.eye_y());
// EntityFluidInteraction.applyCurrentTo: the flow pushes the mob.
if (self.fluids.in_water || self.fluids.in_lava) && self.pushed_by_fluid() {
let (water, lava) = w.fluid_currents(self.bounds());
let lava_scale = if w.nether {
0.007
} else {
0.0023333333333333335
};
let mut pushed = Pushed(&mut self.velocity);
if water.height > 0.0 {
let _ = water.apply_to(&mut pushed, 0.014);
}
if lava.height > 0.0 {
let _ = lava.apply_to(&mut pushed, lava_scale);
}
}
if self.fluids.in_water {
self.fall_distance = 0.0;
if !was_touching_water && !self.first_tick {
@@ -549,13 +691,15 @@ impl Mob {
}
}
/// `Entity.nextStep`: the next whole metre walked; a warden's steps come
/// every 0.55, a strider's every 0.6.
/// every 0.55, a strider's every 0.6, a turtle's every 0.15.
fn next_step(&self) -> f32 {
let walked = self.ai.steps.move_dist;
if self.kind.species == super::Species::Warden {
walked + 0.55
} else if self.kind.species == super::Species::Strider {
walked + 0.6
} else if self.kind.species == super::Species::Turtle {
walked + 0.15
} else {
(walked as i32).wrapping_add(1) as f32
}
@@ -649,7 +793,11 @@ impl Mob {
return;
}
let power = self.fall_distance + 1.0e-6 - self.kind.safe_fall_distance;
let damage = (power * self.kind.fall_damage_multiplier).floor();
let mut damage = (power * self.kind.fall_damage_multiplier).floor();
// Frog.calculateFallDamage: five points less than the base damage.
if self.species() == super::Species::Frog {
damage -= 5.0;
}
if damage > 0.0 {
let at = [self.position.x, self.position.y, self.position.z];
let sound = if damage > 4.0 {
@@ -1137,6 +1137,7 @@ struct Quarry {
position: Vec3,
head_yaw: f32,
height: f64,
passenger: bool,
}
fn quarry(w: &MobWorld, who: Who) -> Option<Quarry> {
let t = w.target_info(who)?;
@@ -1148,6 +1149,7 @@ fn quarry(w: &MobWorld, who: Who) -> Option<Quarry> {
position: t.position,
head_yaw,
height: t.bounds.max_position().y - t.bounds.min_position().y,
passenger: t.passenger,
})
}
/// `BreezeUtil.randomPointBehindTarget`.
@@ -1233,7 +1235,8 @@ fn shoot_tick(m: &mut Mob, cx: &mut Bx) {
let firing = super::breeze::firing_y(m);
let (xd, yd, zd) = (
q.position.x - m.position.x,
q.position.y + q.height * 0.3 - firing,
// target.getY(target.isPassenger() ? 0.8 : 0.3).
q.position.y + q.height * if q.passenger { 0.8 } else { 0.3 } - firing,
q.position.z - m.position.z,
);
let start = Vec3::new(m.position.x, firing, m.position.z);
@@ -1242,14 +1245,19 @@ fn shoot_tick(m: &mut Mob, cx: &mut Bx) {
start,
Some(Who::Mob(m.id)),
);
// The new entity's own random spreads the shot (5 - difficulty * 4 at
// normal): not the breeze's.
// The new entity's own random spreads the shot (5 - difficulty id * 4):
// not the breeze's.
let mut own = LegacyRandom::new(
cx.now
.wrapping_mul(0x5DEE_CE66)
.wrapping_add(i64::from(m.id)),
);
p.shoot(&mut own, [xd, yd, zd], 0.7, -3.0);
p.shoot(
&mut own,
[xd, yd, zd],
0.7,
5.0 - f32::from(cx.w.difficulty.id) * 4.0,
);
cx.events.push(MobEvent::Projectile(p));
breeze_sound(m, cx, "entity.breeze.shoot", 1.5);
}
+74 -4
View File
@@ -177,8 +177,71 @@ 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"),
// RabbitRenderer.getTextureLocation: the Toast name tag, else the
// variant (the killer bunny's id is 99).
S::Rabbit => {
let name = if m.custom_name.as_deref() == Some("Toast") {
"toast"
} else {
match m.extra.variant {
1 => "white",
2 => "black",
3 => "white_splotched",
4 => "gold",
5 => "salt",
99 => "caerbannog",
_ => "brown",
}
};
(
baby_or(m, "rabbit#main", "rabbit_baby#main"),
b(&format!("entity/rabbit/rabbit_{name}")),
)
}
// ParrotRenderer.getVariantTexture.
S::Parrot => {
let name = ["red_blue", "blue", "green", "yellow_blue", "grey"]
[usize::from(m.extra.variant).min(4)];
(m.kind.model_key(), format!("entity/parrot/parrot_{name}"))
}
// AxolotlRenderer.getTextureLocation.
S::Axolotl => {
let name =
["lucy", "wild", "gold", "cyan", "blue"][usize::from(m.extra.variant).min(4)];
(
baby_or(m, "axolotl#main", "axolotl_baby#main"),
b(&format!("entity/axolotl/axolotl_{name}")),
)
}
// SalmonRenderer.submit: the model of the salmon's size.
S::Salmon => {
let model = match m.extra.variant {
0 => "salmon_small#main",
2 => "salmon_large#main",
_ => "salmon#main",
};
(model.into(), "entity/fish/salmon".into())
}
// The baby models and textures of AgeableMobRenderer's other
// subclasses.
S::Goat => (
baby_or(m, "goat#main", "goat_baby#main"),
b(&m.kind.texture),
),
S::PolarBear => (
baby_or(m, "polar_bear#main", "polar_bear_baby#main"),
b(&m.kind.texture),
),
S::Ocelot => (
baby_or(m, "ocelot#main", "ocelot_baby#main"),
b(&m.kind.texture),
),
S::Turtle => (
baby_or(m, "turtle#main", "turtle_baby#main"),
b(&m.kind.texture),
),
S::Armadillo => (
baby_or(m, "armadillo#main", "armadillo_baby#main"),
b(&m.kind.texture),
),
S::Pig => {
@@ -241,7 +304,7 @@ pub fn body(m: &Mob) -> (String, String) {
),
S::ZombieVillager => (
baby_or(m, "zombie_villager#main", "zombie_villager_baby#main"),
"entity/zombie_villager/zombie_villager".into(),
b("entity/zombie_villager/zombie_villager"),
),
S::Villager => (
baby_or(m, "villager#main", "villager_baby#main"),
@@ -765,7 +828,14 @@ pub fn base_transform_at(m: &Mob, alpha: f32, origin: glam::Mat4) -> glam::Mat4
let rotation = match sleep {
// setupRotations for Pose.SLEEPING, with the head moved toward the pillow.
Some((angle, step)) => {
let head = (m.eye_y() - m.position.y) as f32 - 0.1;
// The eye height of the standing pose (LivingEntityRenderer
// extracts `getEyeHeight(Pose.STANDING)` for a bed).
let eye = if avatar(m) {
m.kind.eye_height as f32
} else {
(m.eye_y() - m.position.y) as f32
};
let head = eye - 0.1;
glam::Mat4::from_translation(glam::Vec3::new(-step[0] * head, 0.0, -step[1] * head))
* glam::Mat4::from_rotation_y(angle.to_radians())
* glam::Mat4::from_rotation_z(90.0_f32.to_radians())
@@ -39,6 +39,8 @@ pub struct LocalDifficulty {
pub normal: bool,
/// The world difficulty is hard.
pub hard: bool,
/// `Difficulty.getId`: 0 peaceful to 3 hard.
pub id: u8,
}
/// `DimensionType.MOON_BRIGHTNESS_PER_PHASE`.
pub const MOON_BRIGHTNESS: [f32; 8] = [1.0, 0.75, 0.5, 0.25, 0.0, 0.25, 0.5, 0.75];
@@ -53,6 +55,7 @@ impl LocalDifficulty {
effective: 0.0,
normal,
hard,
id: base,
};
}
let global = ((total as f32 - 72000.0) / 1_440_000.0).clamp(0.0, 1.0) * 0.25;
@@ -66,6 +69,7 @@ impl LocalDifficulty {
effective: f32::from(base) * (0.75 + global + local),
normal,
hard,
id: base,
}
}
/// `getSpecialMultiplier`.
+12 -3
View File
@@ -1447,7 +1447,6 @@ impl Def {
| S::IronGolem
| S::Cat
| S::Ocelot
| S::Frog
| S::Slime
| S::MagmaCube
| S::Wither
@@ -1500,7 +1499,7 @@ impl Def {
),
// Nautilus.handleAirSupply: it dries out on land.
needs_water: aquatic || s == S::Nautilus,
water_sensitive: matches!(s, S::Enderman | S::Blaze | S::SnowGolem),
water_sensitive: matches!(s, S::Enderman | S::Blaze | S::SnowGolem | S::Strider),
animal: !matches!(s, S::Bat | S::SulfurCube | S::Mannequin)
&& !self.hostile_class()
&& !aquatic
@@ -1581,7 +1580,7 @@ impl Def {
S::Bee => "bee_food",
S::Turtle => "turtle_food",
S::Armadillo => "armadillo_food",
S::Frog => "frog_food",
S::Frog | S::Tadpole => "frog_food",
S::Axolotl => "axolotl_food",
S::Hoglin => "hoglin_food",
S::Strider => "strider_food",
@@ -1629,6 +1628,7 @@ impl Def {
match self.species {
Species::Dolphin | Species::Axolotl => 1.0,
Species::Slime | Species::MagmaCube | Species::SulfurCube => 0.0,
Species::Guardian | Species::ElderGuardian | Species::Shulker => 180.0,
_ => 40.0,
}
}
@@ -1640,6 +1640,9 @@ impl Def {
Species::Sniffer => 50.0,
Species::Goat => 15.0,
Species::Armadillo => 32.0,
Species::Ravager => 45.0,
Species::Camel | Species::CamelHusk => 30.0,
Species::Shulker => 180.0,
_ => 75.0,
}
}
@@ -1658,6 +1661,12 @@ impl Def {
| S::Camel
| S::CamelHusk => 400,
S::Ocelot => 900,
// Guardian.getAmbientSoundInterval (the elder too).
S::Guardian | S::ElderGuardian => 160,
// Hoglin extends Animal; Shulker extends AbstractGolem.
S::Hoglin | S::Shulker => 120,
// Allay is a PathfinderMob: the Mob default.
S::Allay => 80,
S::Squid
| S::GlowSquid
| S::Cod
+3 -16
View File
@@ -360,7 +360,7 @@ impl Goal for FollowOwner {
};
let far = m.distance_sqr(at) >= 144.0;
if !far {
let max = max_head_x_rot(m);
let max = m.max_head_x_rot();
m.look_at_speed([at.x, eye, at.z], 10.0, max);
}
self.recalc -= 1;
@@ -507,7 +507,7 @@ impl Goal for Beg {
}
fn tick(&mut self, m: &mut Mob, cx: &mut Cx) {
if let Some(p) = &cx.w.player {
let max = max_head_x_rot(m);
let max = m.max_head_x_rot();
m.look_at_speed([p.position.x, p.eye[1], p.position.z], 10.0, max);
}
self.ticks -= 1;
@@ -529,12 +529,7 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
let v = &mut m.anim.v;
v[INTEREST] += (goal - v[INTEREST]) * 0.4;
// isWet (extra.flag2), isShaking (counter2 > 0).
let rain = w.raining
&& w.can_see_sky(
m.position.x.floor() as i32,
(m.position.y + f64::from(m.height())).floor() as i32,
m.position.z.floor() as i32,
);
let rain = super::ai::in_rain(m, w);
let shaking = m.extra.counter2 > 0;
if m.fluids.in_water || rain {
m.extra.flag2 = true;
@@ -683,14 +678,6 @@ pub fn texture(m: &Mob) -> String {
let baby = if m.is_baby() { "_baby" } else { "" };
format!("entity/wolf/{file}{state}{baby}")
}
/// `Wolf.getMaxHeadXRot`: 20 degrees while sitting.
fn max_head_x_rot(m: &Mob) -> f32 {
if m.extra.sitting {
20.0
} else {
m.kind.max_head_x_rot
}
}
/// Cat variants (`CatVariants`): registry name, texture file.
pub const CAT_VARIANTS: [&str; 11] = [
+1 -1
View File
@@ -96,7 +96,7 @@ pub fn make_invulnerable(m: &mut Mob) {
pub fn powered(m: &Mob) -> bool {
m.health <= m.attrs.max_health / 2.0
}
fn head_pos(m: &Mob, i: usize) -> [f64; 3] {
pub fn head_pos(m: &Mob, i: usize) -> [f64; 3] {
if i == 0 {
return [m.position.x, m.position.y + 3.0, m.position.z];
}
+20 -10
View File
@@ -25,6 +25,8 @@ pub struct TargetInfo {
pub can_be_seen_as_enemy: bool,
pub is_player: bool,
pub creative: bool,
/// `isPassenger`.
pub passenger: bool,
}
impl MobWorld<'_> {
/// The biome's base temperature at a position.
@@ -206,18 +208,24 @@ impl MobWorld<'_> {
}
self.world.light(x, y, z) >> 4 == 15
}
/// Level.isRainingAt: raining, open to the sky, nothing motion blocking
/// above, and the biome's precipitation at the position is rain, not snow
/// Level.precipitationAt: raining, open to the sky, nothing motion
/// blocking above, then the biome's precipitation at the position:
/// `Some(true)` rain, `Some(false)` snow, `None` nothing.
pub fn precipitation_at(&self, x: i32, y: i32, z: i32) -> Option<bool> {
if !self.raining || !self.can_see_sky(x, y, z) || self.motion_blocking_height(x, z) > y {
return None;
}
let chunk = self.world.chunks.get(&(x >> 4, z >> 4))?;
let biome = self.biomes.get(chunk.biome(x, y, z));
if !biome.precipitation {
return None;
}
Some(biome.temperature_at(BlockPos::new(x, y, z), self.sea_level) >= 0.15)
}
/// Level.isRainingAt: the precipitation at the position is rain, not snow
/// or none.
pub fn raining_at(&self, x: i32, y: i32, z: i32) -> bool {
if !self.raining || !self.can_see_sky(x, y, z) || self.motion_blocking_height(x, z) > y {
return false;
}
let Some(chunk) = self.world.chunks.get(&(x >> 4, z >> 4)) else {
return false;
};
let biome = self.biomes.get(chunk.biome(x, y, z));
biome.precipitation && biome.temperature_at(BlockPos::new(x, y, z), self.sea_level) >= 0.15
self.precipitation_at(x, y, z) == Some(true)
}
/// Level.getLightLevelDependentMagicValue: the dimension's brightness curve
/// at the raw (sky darkened) light level.
@@ -243,6 +251,7 @@ impl MobWorld<'_> {
can_be_seen_as_enemy: true,
is_player: true,
creative: p.creative,
passenger: p.passenger,
}),
Who::Mob(id) => self.seen(id).map(|s| TargetInfo {
position: s.position,
@@ -252,6 +261,7 @@ impl MobWorld<'_> {
can_be_seen_as_enemy: !s.playing_dead,
is_player: false,
creative: false,
passenger: s.passenger,
}),
}
}