Merge pull request #1850 from rdbtCVS/t3/fix-end-crystal-explosion

🤖 Agent: thank you! Merged after the contribution gate (checked against vanilla 26.3; one integration branch of main + its batch: clippy -D warnings, tests, the affected parity harnesses (111/112, all pass), in game on the server thread and in-frame, lan_e2e in both host modes) and this head's verify.
This commit is contained in:
Ludovic Marie
2026-10-25 21:47:00 +01:00
committed by GitHub
2 changed files with 70 additions and 12 deletions
+20 -12
View File
@@ -336,6 +336,12 @@ enum StrafeRequest {
/// Anything else: the player nearest the crystal.
Nearest(Vec3),
}
/// Whether `EndCrystal.hurtServer` creates a blast before notifying the fight.
#[derive(Clone, Copy, PartialEq)]
enum CrystalDamage {
Direct,
Explosion,
}
/// What `EnderDragon.hurt` made of a hit.
#[derive(Clone, Copy, Debug, PartialEq)]
pub(super) enum Hurt {
@@ -867,27 +873,29 @@ impl Game<'_> {
}
}
}
/// A crystal took damage: `EndCrystal.hurtServer` blows it up (power 6).
fn destroy_crystal(&mut self, index: usize, by: Option<FightWho>) {
/// `EndCrystal.hurtServer`: remove it, blast only for non-explosion damage,
/// then notify the dragon fight even when no blast was created.
fn destroy_crystal(&mut self, index: usize, by: Option<FightWho>, damage: CrystalDamage) {
if index >= self.crystals.len() || self.crystals[index].invulnerable {
return;
}
let c = self.crystals.remove(index);
if self.fight.respawn.is_some()
// Read before the blast, which can take other respawn crystals.
let respawn_crystal = self.fight.respawn.is_some()
&& self
.fight
.respawn_crystals
.iter()
.any(|p| p.distance_squared(c.position) < 0.01)
{
.any(|p| p.distance_squared(c.position) < 0.01);
if damage == CrystalDamage::Direct {
let at = [c.position.x, c.position.y, c.position.z];
let _ =
self.server_explode(at, 6.0, super::explosion::BlockInteraction::Destroy, false);
}
if respawn_crystal {
self.abort_respawn();
return;
}
let at = [c.position.x, c.position.y, c.position.z];
let _ = self.server_explode(at, 6.0, super::explosion::BlockInteraction::Destroy, false);
// EnderDragonFight.onCrystalDestroyed.
self.count_crystals();
if let Some(d) = self.dragon.as_mut() {
@@ -962,7 +970,7 @@ impl Game<'_> {
return Hurt::Refused;
}
let by = by_player.then(|| self.acting_player());
self.destroy_crystal(index, by);
self.destroy_crystal(index, by, CrystalDamage::Direct);
Hurt::Landed { full: true }
} else if id >= SPECIAL {
self.hurt_dragon((id - SPECIAL) as usize, amount, by_player, arrow)
@@ -2634,8 +2642,8 @@ impl Crystal {
}
}
impl Game<'_> {
/// `ServerExplosion.hurtEntities` on the end crystals (each in reach
/// blows up in turn) and the dragon (explosions always hurt dragons).
/// `ServerExplosion.hurtEntities`: crystals in reach are removed without
/// another blast; explosions always hurt dragons.
pub(super) fn explosion_hits_special(&mut self, center: [f64; 3], radius: f32) {
let diameter = f64::from(radius * 2.0);
let in_reach = |p: Vec3| {
@@ -2651,9 +2659,9 @@ impl Game<'_> {
.map(|c| c.position)
.collect();
for at in crystals {
// One blowing up may already have taken the next.
// Look up the current index after each removal.
if let Some(i) = self.crystals.iter().position(|c| c.position == at) {
self.destroy_crystal(i, None);
self.destroy_crystal(i, None, CrystalDamage::Explosion);
}
}
let Some(d) = self.dragon.as_ref() else {
+50
View File
@@ -6252,6 +6252,56 @@ CHECKS += ['crystals']
CHECK_FNS.update(crystals=check_crystals)
def check_crystal_blast(host, guest, out):
"""#1533: TNT removes a crystal without a blast; a punched crystal blasts once.
Both clients must see the surviving distant and invulnerable crystals."""
spots = apart(host, guest)
seen = {}
for label, player, other in (('host', host, guest), ('guest', guest, host)):
x, y, z = spots[label]
y += 32
player('command', command='gamemode creative')
for offset, cause in enumerate(('tnt', 'melee')):
# Leave survivors in separate arenas; the scratch world is discarded.
z = spots[label][2] + (0 if label == 'host' else 80) + offset * 40
case = f'{label}-{cause}'
host('command', command=f'fill {x - 3} {y - 1} {z - 3} {x + 25} {y - 1} {z + 5} minecraft:bedrock')
host('command', command=f'fill {x - 3} {y} {z - 3} {x + 25} {y + 4} {z + 5} minecraft:air')
positions = [[x + dx, y, z + dz] for dx, dz in ((2.5, 0.5), (12.5, 0.5), (22.5, 0.5), (4.5, 3.5))]
def remaining(game):
crystals = [p for p in game('status')['projectiles'] if p['kind'] == 'minecraft:end_crystal']
return [i for i, at in enumerate(positions)
if any(math.dist(p['position'], at) < 0.01 for p in crystals)]
for i, at in enumerate(positions):
host('command', command=f'summon minecraft:end_crystal {at[0]} {at[1]} {at[2]} {{Invulnerable:{1 if i == 3 else 0}b}}')
player('command', command=f'tp @s {x + 0.5} {y} {z + 0.5}')
other('command', command='gamemode creative')
other('command', command=f'tp @s {x + 0.5} {y} {z + 4.5}')
player('command', command='clear @s')
player.wait(20)
for game in (host, guest):
assert remaining(game) == [0, 1, 2, 3], f'{case}: crystals not tracked on {game.name}'
if cause == 'tnt':
player('command', command=f'summon minecraft:tnt {x + 0.5} {y} {z + 0.5} {{fuse:10s}}')
else:
player.raw('look-at', positions[0][0], y + 1, positions[0][2])
player.raw('mouse', 'left', 'click')
player.wait(80)
result = {game.name: remaining(game) for game in (host, guest)}
seen[case] = result
# TNT reaches the first crystal only. A direct crystal blast reaches
# the second too, but that crystal must not detonate the third.
expected = [1, 2, 3] if cause == 'tnt' else [2, 3]
assert all(ids == expected for ids in result.values()), f'{case}: expected {expected}, got {result}'
return seen
CHECKS += ['crystal_blast']
CHECK_FNS.update(crystal_blast=check_crystal_blast)
def check_boat_dismount_pose(host, guest, out):
"""Removing a boat detaches its mobs on the server and every observing client."""
x, y, z = map(math.floor, pos_of(host))