Merge pull request #2187 from kacpherek/fix/shulker-bullet-duplication

🤖 Agent: Gate check by Ludovic's AI agent (Claude). Checked against 26.3: `Shulker.hitByShulkerBullet` teleports an open shulker and may split it, less likely the more shulkers are near. I pushed one fix: the split roll uses the level's random, as vanilla's `level.getRandom()` does. Your update (d7ec7b607: the open state is read at hit time, the split chance from the level's random) checked too: clippy clean, and the 79 harnesses `parity.py --changed-files` picks pass apart from the campfire cases #2316 fixes. Gate: this wave's 55 PRs merged on main in one tree: clippy `-D warnings` clean, 1186 horizon-client and 163 horizon-world tests pass, and of the 101 harnesses `parity.py --changed-files` picked, 100 pass (`block_removal` failed on one spawner case from #2199's orb merging, fixed there). `lan_e2e.py` passes 24 checks with the host on its server thread and in-frame (chest, xp, pvp, doors, villagers, beds, frames, projectiles, arrows, fishing, damage, mobs, blast, drops, elytra, breath, predict, cracks, barter, kills, hurt, contacts, underwater, plates), plus forced-levels on the server thread. Thanks @kacpherek!
This commit is contained in:
Ludovic Marie
2026-10-26 20:24:29 +01:00
committed by GitHub
3 changed files with 69 additions and 10 deletions
+7 -3
View File
@@ -2465,12 +2465,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);
}
}
@@ -2479,6 +2481,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);
}
}
},
+8 -3
View File
@@ -746,7 +746,7 @@ fn ai_step(m: &mut Mob, w: &MobWorld, level_random: &mut LegacyRandom, events: &
if m.kind.flags.burns_in_day && m.alive() && sun_burn_tick(m, w) && m.extra.head.is_none() {
m.ignite_for_ticks(160);
}
species_ai_step(m, w, events);
species_ai_step(m, w, level_random, events);
}
impl Mob {
/// LivingEntity.isPushable (and the push it takes from `Entity.push(Entity)`):
@@ -955,7 +955,12 @@ fn custom_server_ai_step(m: &mut Mob, cx: &mut Cx) {
_ => {}
}
}
fn species_ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
fn species_ai_step(
m: &mut Mob,
w: &MobWorld,
level_random: &mut LegacyRandom,
events: &mut Vec<MobEvent>,
) {
if family(m.species()) == Family::Aquatic {
aquatic::ai_step(m, w, events);
}
@@ -988,7 +993,7 @@ fn species_ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
}
Species::Shulker => {
super::shulker::tick(m, w, events);
super::shulker::ai_step(m, w, events);
super::shulker::ai_step(m, w, level_random, events);
}
Species::SnowGolem => super::golem::snow_ai_step(m, w, events),
Species::CopperGolem => super::copper_golem::ai_step(m, w, events),
+54 -4
View File
@@ -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,
@@ -14,7 +14,7 @@ use crate::projectiles::{Projectile, ProjectileWorld, STEPS};
use horizon_core::geometry::trig::Mth;
use horizon_core::{
geometry::{Aabb, Vec3},
random::RandomSource,
random::{LegacyRandom, RandomSource},
};
use std::f32::consts::PI;
@@ -164,12 +164,62 @@ pub fn after_hurt(m: &mut Mob) {
m.extra.flag = true;
}
}
/// The deferred teleport of `after_hurt`.
pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
/// `Shulker.hurtServer` after a shulker bullet's damage: unless the
/// low-health teleport was drawn instead (`else if`), `hitByShulkerBullet`
/// runs on the next tick. Whether the shell is open is read here, at hurt
/// time, so a goal opening it before that tick cannot change the outcome.
pub fn hit_by_bullet(m: &mut Mob) {
if m.species() == Species::Shulker && !m.extra.flag && m.extra.counter != 0 {
m.extra.flag2 = true;
}
}
/// The deferred teleport of `after_hurt` and `hitByShulkerBullet`.
pub fn ai_step(
m: &mut Mob,
w: &MobWorld,
level_random: &mut LegacyRandom,
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, level_random, events);
}
}
/// `Shulker.hitByShulkerBullet` (only queued by an open shulker): it
/// 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,
level_random: &mut LegacyRandom,
events: &mut Vec<MobEvent>,
) {
let old_position = m.position;
let old_box = m.bounds();
if !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;
// The level's random, not the shulker's.
if level_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> {