Merge pull request #2526 from kacpherek/fix/mob-freeze-strider-shake
🤖 Agent: Merged by Ludovic's AI agent (Claude, contrib-gate-19). Thanks @kacpherek: Freeze mobs in powder snow and shake frozen mobs and cold striders. I checked it against vanilla 26.3, and it passed every harness it reaches in a union with your other PRs, plus lan_e2e in both modes.
This commit is contained in:
@@ -119,6 +119,7 @@ impl Game<'_> {
|
||||
"magic" | "indirect_magic" | "dragon_breath" => DamageKind::Magic,
|
||||
"sting" => DamageKind::Sting,
|
||||
"cactus" | "sweet_berry_bush" => DamageKind::Cactus,
|
||||
"freeze" => DamageKind::Freeze,
|
||||
"in_wall" => DamageKind::InWall,
|
||||
"thorns" => DamageKind::Thorns,
|
||||
_ => DamageKind::Generic,
|
||||
|
||||
@@ -3802,6 +3802,7 @@ pub(super) fn damage_type(kind: horizon_client::mobs::DamageKind, player: bool)
|
||||
K::InWall => "minecraft:in_wall",
|
||||
K::Thorns => "minecraft:thorns",
|
||||
K::SonicBoom => "minecraft:sonic_boom",
|
||||
K::Freeze => "minecraft:freeze",
|
||||
K::OutOfWorld => "minecraft:out_of_world",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -412,6 +412,26 @@ fn mob_meta(
|
||||
}
|
||||
}
|
||||
|
||||
/// What a client shakes a mob by: Entity.DATA_TICKS_FROZEN (7), whose full
|
||||
/// count is `isFullyFrozen`, and Strider.DATA_SUFFOCATING (19, after
|
||||
/// AgeableMob's two and DATA_BOOST_TIME).
|
||||
fn mob_freeze_meta(
|
||||
m: &Mob,
|
||||
meta: &mut Vec<(u8, i32, Value)>,
|
||||
defaults: &mut Vec<(u8, i32, Value)>,
|
||||
) {
|
||||
if m.ticks_frozen > 0 {
|
||||
meta.push((7, serializer::INT, Value::Int(m.ticks_frozen)));
|
||||
}
|
||||
defaults.push((7, serializer::INT, Value::Int(0)));
|
||||
if m.kind.id == "minecraft:strider" {
|
||||
if m.extra.flag {
|
||||
meta.push((19, serializer::BOOLEAN, Value::Bool(true)));
|
||||
}
|
||||
defaults.push((19, serializer::BOOLEAN, Value::Bool(false)));
|
||||
}
|
||||
}
|
||||
|
||||
/// The equipment a mob shows (ClientboundSetEquipmentPacket slots: main hand,
|
||||
/// off hand, feet, legs, chest, head, body, saddle).
|
||||
fn mob_equipment(
|
||||
@@ -930,6 +950,7 @@ impl Game<'_> {
|
||||
e.velocity = [m.velocity.x, m.velocity.y, m.velocity.z];
|
||||
e.needs_sync = m.needs_sync;
|
||||
mob_meta(m, hub, player_entity, &mut e.meta, &mut e.defaults);
|
||||
mob_freeze_meta(m, &mut e.meta, &mut e.defaults);
|
||||
mob_equipment(m, hub, &mut e.equipment);
|
||||
self.mob_attributes(m, &mut e.attributes);
|
||||
e.leash = leash;
|
||||
|
||||
@@ -1954,6 +1954,22 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32) {
|
||||
for (index, _, value) in &p.values {
|
||||
match (index, value) {
|
||||
// Entity.DATA_TICKS_FROZEN: isFullyFrozen shakes it.
|
||||
(7, Value::Int(ticks)) => m.ticks_frozen = *ticks,
|
||||
// Strider.DATA_SUFFOCATING (after AgeableMob's two
|
||||
// and DATA_BOOST_TIME): a cold strider shakes.
|
||||
(19, Value::Bool(cold))
|
||||
if m.species() == horizon_client::mobs::Species::Strider =>
|
||||
{
|
||||
m.extra.flag = *cold;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
// LivingEntity.DATA_LIVING_ENTITY_FLAGS: for another player
|
||||
// too, remote_mob_data's apply reads index 8 above.
|
||||
let mannequin = self
|
||||
|
||||
@@ -527,6 +527,8 @@ pub enum DamageKind {
|
||||
InWall,
|
||||
Thorns,
|
||||
SonicBoom,
|
||||
/// `freeze`: a fully frozen mob in powder snow.
|
||||
Freeze,
|
||||
/// `fell_out_of_world`: below the world's floor.
|
||||
OutOfWorld,
|
||||
}
|
||||
@@ -596,6 +598,7 @@ impl Damage {
|
||||
| DamageKind::InWall
|
||||
| DamageKind::Generic
|
||||
| DamageKind::SonicBoom
|
||||
| DamageKind::Freeze
|
||||
| DamageKind::OutOfWorld
|
||||
)
|
||||
}
|
||||
@@ -620,6 +623,7 @@ impl Damage {
|
||||
| DamageKind::Cactus
|
||||
| DamageKind::Generic
|
||||
| DamageKind::InWall
|
||||
| DamageKind::Freeze
|
||||
| DamageKind::OutOfWorld
|
||||
)
|
||||
}
|
||||
@@ -1361,6 +1365,10 @@ impl Mob {
|
||||
.max((f64::from(ticks) * self.burning_time()).ceil() as i32);
|
||||
self.ticks_frozen = 0;
|
||||
}
|
||||
/// `Entity.isFullyFrozen`.
|
||||
pub fn is_fully_frozen(&self) -> bool {
|
||||
self.ticks_frozen >= crate::motion::PlayerMotion::TICKS_REQUIRED_TO_FREEZE
|
||||
}
|
||||
|
||||
/// What other mobs see of this one this tick (`player`: the player's
|
||||
/// UUID, which villagers' reputation is keyed by).
|
||||
@@ -1839,6 +1847,15 @@ impl Mob {
|
||||
{
|
||||
amount *= 0.75;
|
||||
}
|
||||
// LivingEntity.hurtServer: `#freeze_hurts_extra_types` take five times.
|
||||
if source.kind == DamageKind::Freeze
|
||||
&& matches!(
|
||||
self.species(),
|
||||
Species::Strider | Species::Blaze | Species::MagmaCube
|
||||
)
|
||||
{
|
||||
amount *= 5.0;
|
||||
}
|
||||
let (worn, worn_toughness) = self.worn_armor();
|
||||
if !source.bypasses_armor() && self.kind.armor + worn > 0.0 {
|
||||
// CombatRules.getDamageAfterAbsorb
|
||||
|
||||
@@ -586,6 +586,7 @@ fn base_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
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);
|
||||
}
|
||||
tick_effects(m);
|
||||
if m.species() == Species::Illusioner {
|
||||
@@ -615,6 +616,57 @@ fn base_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
// Entity.baseTick ends with Leashable.tickLeash.
|
||||
super::leash::tick(m, w, events);
|
||||
}
|
||||
/// `LivingEntity.aiStep`'s "freezing" with `InsideBlockEffectType.FREEZE`:
|
||||
/// powder snow builds `ticks_frozen` up, anywhere else it melts twice as
|
||||
/// fast, and a fully frozen mob takes one freeze damage every 40 ticks.
|
||||
fn freeze_tick(m: &mut Mob, w: &MobWorld) {
|
||||
let in_snow = in_powder_snow(m, w);
|
||||
if !in_snow && m.ticks_frozen == 0 {
|
||||
return;
|
||||
}
|
||||
let can_freeze = can_freeze(m, w);
|
||||
if in_snow && can_freeze {
|
||||
m.ticks_frozen =
|
||||
(m.ticks_frozen + 1).min(crate::motion::PlayerMotion::TICKS_REQUIRED_TO_FREEZE);
|
||||
} else {
|
||||
m.ticks_frozen = (m.ticks_frozen - 2).max(0);
|
||||
}
|
||||
if m.age.is_multiple_of(40) && m.is_fully_frozen() && can_freeze {
|
||||
m.damage(1.0, Damage::of(DamageKind::Freeze));
|
||||
}
|
||||
}
|
||||
/// Whether the mob's box (shrunk by `1.0E-5`, as in `Entity.checkInsideBlocks`)
|
||||
/// touches powder snow.
|
||||
fn in_powder_snow(m: &Mob, w: &MobWorld) -> bool {
|
||||
let b = m.bounds().deflate(Vec3::new(1e-5, 1e-5, 1e-5));
|
||||
let (min, max) = (b.min_position(), b.max_position());
|
||||
for x in min.x.floor() as i32..=max.x.floor() as i32 {
|
||||
for y in min.y.floor() as i32..=max.y.floor() as i32 {
|
||||
for z in min.z.floor() as i32..=max.z.floor() as i32 {
|
||||
if &*w.facts.get(w.world.block(x, y, z)).name == "minecraft:powder_snow" {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
/// `LivingEntity.canFreeze`: not a `#freeze_immune_entity_types` mob and no
|
||||
/// worn piece in `#freeze_immune_wearables`.
|
||||
fn can_freeze(m: &Mob, w: &MobWorld) -> bool {
|
||||
if w.data
|
||||
.entity_has("minecraft:freeze_immune_entity_types", &m.kind.id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let immune = w
|
||||
.items
|
||||
.and_then(|i| i.item_tags.get("minecraft:freeze_immune_wearables"));
|
||||
![&m.extra.head, &m.extra.chest, &m.extra.legs, &m.extra.feet]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.any(|item| immune.is_some_and(|t| t.contains(&**item)))
|
||||
}
|
||||
/// `Mob.playAmbientSound` on demand: a spawn egg or a mob bucket just placed `m`.
|
||||
pub fn ambient_sound(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
play_ambient(m, w, events);
|
||||
|
||||
@@ -833,10 +833,15 @@ pub fn base_transform_at(m: &Mob, alpha: f32, origin: glam::Mat4) -> glam::Mat4
|
||||
base *= species_scale(m, alpha);
|
||||
base * glam::Mat4::from_translation(glam::Vec3::new(0.0, -1.501, 0.0))
|
||||
}
|
||||
/// `LivingEntityRenderer.isShaking`: converting zombies, piglins and
|
||||
/// hoglins, and a zombie villager being cured.
|
||||
/// `LivingEntityRenderer.isShaking`: a fully frozen mob (the skeleton's own
|
||||
/// `isShaking` is its stray conversion only), converting zombies, piglins
|
||||
/// and hoglins, a zombie villager being cured and a cold strider.
|
||||
fn shaking(m: &Mob) -> bool {
|
||||
if m.is_fully_frozen() && m.species() != Species::Skeleton {
|
||||
return true;
|
||||
}
|
||||
match m.species() {
|
||||
Species::Strider => super::strider::suffocating(m),
|
||||
Species::ZombieVillager => super::zombie_villager::is_converting(m),
|
||||
Species::Zombie | Species::Husk => m.extra.counter2 > 0,
|
||||
Species::Piglin | Species::PiglinBrute | Species::Hoglin => {
|
||||
|
||||
@@ -297,6 +297,7 @@ pub fn accepts_damage(m: &mut Mob, source: &Damage, amount: f32) -> bool {
|
||||
| DamageKind::Fall
|
||||
| DamageKind::Sting
|
||||
| DamageKind::Cactus
|
||||
| DamageKind::Freeze
|
||||
);
|
||||
if immune {
|
||||
if let Some(from) = source.from {
|
||||
|
||||
Reference in New Issue
Block a user