Shulker bullet split: draw the failure chance from the level's random

Shulker.hitByShulkerBullet tests level().getRandom().nextFloat() against
the crowding chance, not the shulker's own random.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-26 15:27:12 +01:00
parent 4aa7838d1b
commit 7fbfbb5e2b
2 changed files with 24 additions and 8 deletions
+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),
+16 -5
View File
@@ -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;
@@ -173,20 +173,30 @@ pub fn hit_by_bullet(m: &mut Mob) {
}
}
/// The deferred teleport of `after_hurt` and `hitByShulkerBullet`.
pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
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, events);
hit_by_shulker_bullet(m, w, level_random, 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>) {
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 m.extra.counter == 0 || !teleport(m, w, events) {
@@ -201,7 +211,8 @@ fn hit_by_shulker_bullet(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>)
})
.count();
let failure_chance = others as f32 / 5.0;
if m.random.next_float() < failure_chance {
// 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);