Carry the exploding mob's kind with its blast and anger bees at guests too

This commit is contained in:
Kacpherek
2026-10-26 18:09:01 +01:00
parent cc39d57e07
commit e8ae26c270
7 changed files with 41 additions and 11 deletions
@@ -580,7 +580,7 @@ fn player_hurt(player: Option<&PlayerView>, e: &MobEvent) -> bool {
match e {
MobEvent::AttackPlayer(amount, _) | MobEvent::DamagePlayer { amount, .. } => *amount > 0.0,
// ServerExplosion.hurtEntities: within twice the radius every hit does damage.
MobEvent::Explode(at, radius) => {
MobEvent::Explode(at, radius, _) => {
let d = Vec3::new(at[0], at[1], at[2])
.distance_squared(p.position)
.sqrt();
+30 -4
View File
@@ -195,7 +195,8 @@ impl Game<'_> {
self.anger_nearby_bees(at);
}
/// `BeehiveBlock.angerNearbyBees`: bees within 8 blocks (6 up and down)
/// without a target go for a player in the same box.
/// without a target go for a random player in the same box, the window's
/// own or a guest (`None` is the window's player).
pub(super) fn anger_nearby_bees(&mut self, at: [i32; 3]) {
let min = Vec3::new(
f64::from(at[0]) - 8.0,
@@ -203,10 +204,24 @@ impl Game<'_> {
f64::from(at[2]) - 8.0,
);
let area = Aabb::new(min, Vec3::new(min.x + 17.0, min.y + 13.0, min.z + 17.0));
if !self
let mut players: Vec<Option<u32>> = Vec::new();
if self
.player_view()
.is_some_and(|p| p.bounds.intersects(area))
{
players.push(None);
}
if let Some(host) = self.lan.as_ref() {
players.extend(
host.hub
.guests
.iter()
.filter(|g| host.hub.here(g) && g.loaded && !g.dead)
.filter(|g| super::lan_mobs::guest_bounds(g).intersects(area))
.map(|g| Some(g.conn)),
);
}
if players.is_empty() {
return;
}
let mut bees: Vec<usize> = (0..self.mobs.len())
@@ -219,9 +234,20 @@ impl Game<'_> {
.collect();
bees.retain(|&i| self.mobs[i].ai.target.is_none());
for i in bees {
// Util.getRandom over the one player.
let _ = self.world.random.next_int_bound(1);
// Util.getRandom over the players.
let pick = self
.world
.random
.next_int_bound(players.len() as i32)
.unwrap_or(0) as usize;
self.mobs[i].ai.target = Some(Who::Player);
// The player a mob sees is its guest binding, else the window's.
if let Some(host) = self.lan.as_mut() {
match players[pick] {
Some(conn) => host.mob_players.insert(self.mobs[i].id, conn),
None => host.mob_players.remove(&self.mobs[i].id),
};
}
}
}
}
+4 -5
View File
@@ -901,7 +901,7 @@ impl Game<'_> {
owner,
} => self.add_fangs(at, yaw, delay, owner),
MobEvent::Shoot(..) => {}
MobEvent::Explode(at, radius) => {
MobEvent::Explode(at, radius, species) => {
// The exploding mob causes the damage (Creeper.explodeCreeper).
let source_mob = self
.mobs
@@ -916,10 +916,9 @@ impl Game<'_> {
}
self.combat.explosion_source = source_mob;
// Only a creeper or a wither empties the hives it blows up.
let empties_hives = source_mob
.and_then(|id| self.mobs.iter().find(|m| m.id == id))
.is_some_and(|m| matches!(m.species(), Species::Creeper | Species::Wither));
let result = if empties_hives {
// The creeper is already gone from the list, so the event
// carries its kind.
let result = if matches!(species, Species::Creeper | Species::Wither) {
self.with_hive_emptying_blast(|g| g.explode(at, radius))
} else {
self.explode(at, radius)
+3 -1
View File
@@ -965,7 +965,9 @@ pub enum MobEvent {
owner: u32,
},
Shoot([f64; 3], [f64; 3]),
Explode([f64; 3], f32),
/// The centre, the radius and the kind of the mob blowing up (it may be
/// gone from the list by the time the blast is handled).
Explode([f64; 3], f32, Species),
/// Melee or ranged damage to another mob.
AttackMob {
target: u32,
@@ -180,6 +180,7 @@ pub fn creeper_tick(m: &mut Mob, events: &mut Vec<MobEvent>) {
events.push(MobEvent::Explode(
[m.position.x, m.position.y, m.position.z],
radius,
m.species(),
));
m.removed = true;
}
@@ -370,6 +370,7 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
events.push(MobEvent::Explode(
[m.position.x, m.position.y + 0.0625, m.position.z],
power,
m.species(),
));
m.removed = true;
return;
+1
View File
@@ -221,6 +221,7 @@ pub fn custom_server_ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEven
events.push(MobEvent::Explode(
[m.position.x, m.eye_y(), m.position.z],
7.0,
m.species(),
));
// Global level event 1023.
if !m.silent {