Stop jockey spiders attacking and shove hoglin targets like vanilla
This commit is contained in:
@@ -1324,6 +1324,8 @@ pub struct Seen {
|
||||
pub sitting: bool,
|
||||
/// `Entity.isVehicle` or `isPassenger`.
|
||||
pub ridden: bool,
|
||||
/// `Attributes.KNOCKBACK_RESISTANCE`.
|
||||
pub knockback_resistance: f64,
|
||||
/// The active effects, without namespace (`slowness`, `poison`...).
|
||||
pub effects: Vec<&'static str>,
|
||||
}
|
||||
@@ -1406,6 +1408,7 @@ impl Mob {
|
||||
],
|
||||
sitting: m.extra.sitting,
|
||||
ridden: m.rider.is_some() || m.extra.rider.is_some() || m.extra.mount.is_some(),
|
||||
knockback_resistance: m.attrs.knockback_resistance,
|
||||
effects: m
|
||||
.extra
|
||||
.effects
|
||||
|
||||
@@ -77,7 +77,8 @@ impl Goal for SpiderAttack {
|
||||
self.0.flags()
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
self.0.can_use(m, cx)
|
||||
// SpiderAttackGoal.canUse: not while it carries a rider.
|
||||
self.0.can_use(m, cx) && m.extra.rider.is_none()
|
||||
}
|
||||
fn can_continue(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
if mob_brightness(m, cx.w) >= 0.5 && m.random.next_int_bound(100).unwrap_or(1) == 0 {
|
||||
|
||||
@@ -466,6 +466,35 @@ fn find_piglin_repellent(m: &Mob, w: &MobWorld) -> Option<[i32; 3]> {
|
||||
|| w.prop(p[0], p[1], p[2], "lit") == Some("true"))
|
||||
})
|
||||
}
|
||||
/// `HoglinBase.throwTarget`: a shove away and up of the attack knockback less
|
||||
/// the target's knockback resistance (none at all when that is used up).
|
||||
fn throw_target(m: &mut Mob, who: Who, cx: &mut Cx) {
|
||||
let resistance = match who {
|
||||
Who::Mob(id) => cx.w.seen(id).map_or(0.0, |s| s.knockback_resistance),
|
||||
Who::Player => 0.0,
|
||||
};
|
||||
let power = m.kind.attack_knockback - resistance;
|
||||
let Some(t) = cx.w.target_info(who) else {
|
||||
return;
|
||||
};
|
||||
if power <= 0.0 {
|
||||
return;
|
||||
}
|
||||
let away = Vec3::new(
|
||||
t.position.x - m.position.x,
|
||||
0.0,
|
||||
t.position.z - m.position.z,
|
||||
);
|
||||
// `yRot` takes the random whole number of degrees as radians, as vanilla does.
|
||||
let angle = (m.random.next_int_bound(21).unwrap_or(10) - 10) as f32;
|
||||
let scale = power * f64::from(m.random.next_float() * 0.5 + 0.2);
|
||||
let push = away.normalize().scale(scale).rotate_y(angle);
|
||||
let up = power * f64::from(m.random.next_float()) * 0.5;
|
||||
cx.events.push(MobEvent::Push {
|
||||
target: who,
|
||||
velocity: [push.x, up, push.z],
|
||||
});
|
||||
}
|
||||
/// `HoglinBase.hurtAndThrowTarget`.
|
||||
pub fn hoglin_hurt_target(m: &mut Mob, who: Who, cx: &mut Cx) {
|
||||
m.extra.anim_ticks = 10;
|
||||
@@ -485,11 +514,7 @@ pub fn hoglin_hurt_target(m: &mut Mob, who: Who, cx: &mut Cx) {
|
||||
}),
|
||||
}
|
||||
if !m.is_baby() {
|
||||
// throwTarget: a strong shove up and away.
|
||||
cx.events.push(MobEvent::Launch {
|
||||
target: who,
|
||||
up: 0.5 * f64::from(m.random.next_float()) + 0.3,
|
||||
});
|
||||
throw_target(m, who, cx);
|
||||
}
|
||||
let sound = if m.species() == Species::Zoglin {
|
||||
"entity.zoglin.attack"
|
||||
|
||||
Reference in New Issue
Block a user