Shulker bullets make open shulkers teleport and duplicate
An open shulker hit by a shulker bullet teleports and may leave a new shulker of its colour behind, like Shulker.hitByShulkerBullet. Levitation from the bullet now needs the hit to have hurt the player.
This commit is contained in:
@@ -2364,12 +2364,14 @@ impl Game<'_> {
|
||||
// ShulkerBullet.onHitEntity: 4 damage, then levitation for 10 s.
|
||||
(ProjectileKind::ShulkerBullet { .. }, Hit::Entity { who, .. }) => match who {
|
||||
Who::Player => {
|
||||
if !self.creative {
|
||||
self.mob_hits_player(
|
||||
// Only a hit that hurt (`wasHurt`) brings the levitation.
|
||||
if !self.creative
|
||||
&& self.mob_hits_player(
|
||||
4.0,
|
||||
[p.previous.x, p.previous.y, p.previous.z],
|
||||
"minecraft:mob_projectile",
|
||||
);
|
||||
)
|
||||
{
|
||||
self.give_player_effect("minecraft:levitation", 200, 0);
|
||||
}
|
||||
}
|
||||
@@ -2378,6 +2380,8 @@ impl Game<'_> {
|
||||
&& m.damage(4.0, source)
|
||||
{
|
||||
m.extra.levitation = 200;
|
||||
// Shulker.hurtServer: a shulker hit by a bullet.
|
||||
horizon_client::mobs::shulker::hit_by_bullet(m);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! their face is lost or when badly hurt, and shrugging off arrows while
|
||||
//! closed.
|
||||
use super::{
|
||||
Damage, DamageKind, Mob, MobEvent, MobWorld, Who,
|
||||
Damage, DamageKind, Mob, MobEvent, MobWorld, Species, Who,
|
||||
anim::{Poses, State},
|
||||
goals::{
|
||||
Cx, Goal, HurtByTarget, LOOK, LookAtPlayer, MOVE, NearestTarget, RandomLookAround,
|
||||
@@ -164,12 +164,49 @@ pub fn after_hurt(m: &mut Mob) {
|
||||
m.extra.flag = true;
|
||||
}
|
||||
}
|
||||
/// The deferred teleport of `after_hurt`.
|
||||
/// `Shulker.hurtServer` after a shulker bullet's damage: unless the
|
||||
/// low-health teleport was drawn instead (`else if`), `hitByShulkerBullet`
|
||||
/// runs on the next tick.
|
||||
pub fn hit_by_bullet(m: &mut Mob) {
|
||||
if m.species() == Species::Shulker && !m.extra.flag {
|
||||
m.extra.flag2 = true;
|
||||
}
|
||||
}
|
||||
/// The deferred teleport of `after_hurt` and `hitByShulkerBullet`.
|
||||
pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
if m.extra.flag {
|
||||
m.extra.flag = false;
|
||||
teleport(m, w, events);
|
||||
}
|
||||
if m.extra.flag2 {
|
||||
m.extra.flag2 = false;
|
||||
hit_by_shulker_bullet(m, w, events);
|
||||
}
|
||||
}
|
||||
/// `Shulker.hitByShulkerBullet`: an open shulker teleports, and leaves a
|
||||
/// new one of its colour behind unless shulkers crowd the place (one in
|
||||
/// five fewer chances for every other shulker within 8 blocks).
|
||||
fn hit_by_shulker_bullet(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
let old_position = m.position;
|
||||
let old_box = m.bounds();
|
||||
if m.extra.counter == 0 || !teleport(m, w, events) {
|
||||
return;
|
||||
}
|
||||
let area = old_box.inflate(Vec3::new(8.0, 8.0, 8.0));
|
||||
// The shulker itself stands within reach of its old box, so it counts.
|
||||
let others = w
|
||||
.others_near(area)
|
||||
.filter(|s| {
|
||||
s.alive && s.species == Species::Shulker && s.id != m.id && s.bounds.intersects(area)
|
||||
})
|
||||
.count();
|
||||
let failure_chance = others as f32 / 5.0;
|
||||
if m.random.next_float() < failure_chance {
|
||||
return;
|
||||
}
|
||||
let mut baby = Mob::new(0, m.kind.clone(), old_position, 0.0);
|
||||
baby.extra.color = m.extra.color;
|
||||
events.push(MobEvent::Spawn(Box::new(baby)));
|
||||
}
|
||||
/// A ProjectileWorld over the mob world, for aiming a new bullet.
|
||||
struct Probe<'a, 'w> {
|
||||
|
||||
Reference in New Issue
Block a user