diff --git a/crates/horizon-client/src/game/end.rs b/crates/horizon-client/src/game/end.rs index bed204b50..41c4e1628 100644 --- a/crates/horizon-client/src/game/end.rs +++ b/crates/horizon-client/src/game/end.rs @@ -659,7 +659,9 @@ impl Game<'_> { /// EnderDragonFight without a dragon: once the centre of the main island /// is loaded, place the active exit portal (EndPodiumFeature) and the - /// first gateway (spawnNewGateway) if the portal is not there yet. + /// first gateway (spawnNewGateway) if the portal is not there yet. Like + /// scanState and spawnExitPortal, only while the fight has no exit portal + /// location: a podium that is later broken stays broken. fn ensure_exit_portal(&mut self) -> Result<()> { if self.travelling.is_some() || !(-1..=0).all(|cz| (-1..=0).all(|cx| self.streaming.is_lit(cx, cz))) @@ -669,8 +671,14 @@ impl Game<'_> { } let won = self.fight.previously_killed; let gateway = self.first_gateway(); - if (0..256).any(|y| &*self.block_name([0, y, 0]) == "minecraft:bedrock") { - // The podium exists; the gateway may have been out of range when it was placed. + if self.exit_portal().is_none() { + // findExitPortal remembers the location of a podium that is already there. + if let Some(level) = self.podium_level() { + self.set_exit_portal([0, level, 0]); + } + } + if self.exit_portal().is_some() { + // The gateway may have been out of range when it was placed. if won && self.world.loaded(gateway[0], gateway[2]) && &*self.block_name(gateway) != "minecraft:end_gateway" @@ -701,17 +709,40 @@ impl Game<'_> { } Ok(()) } + /// The portal level of the podium around the centre column, read from the + /// bedrock that EndPodiumFeature places (rim at the portal level, disc + /// below it, the torch column) so a broken column does not hide it. + fn podium_level(&self) -> Option { + let mut offsets: Vec<[i32; 3]> = (0..4).map(|dy| [0, dy, 0]).collect(); + for z in -4..=4i32 { + for x in -4..=4i32 { + let flat = f64::from(x * x + z * z); + if (6.25..12.25).contains(&flat) { + offsets.push([x, 0, z]); + } else if flat + 1.0 < 6.25 { + offsets.push([x, -1, z]); + } + } + } + (1..253) + .map(|y| { + let score = offsets + .iter() + .filter(|o| &*self.block_name([o[0], y + o[1], o[2]]) == "minecraft:bedrock") + .count(); + (score, y) + }) + .filter(|&(score, _)| score >= 3) + .max() + .map(|(_, y)| y) + } /// `spawnExitPortal(true)` after the dragon dies. pub(super) fn activate_exit_portal(&mut self) -> Result<()> { let origin = match self.exit_portal() { Some(o) => o, None => { - // The rim's level: the top of the bedrock column minus three. - let top = (0..256) - .rev() - .find(|&y| &*self.block_name([0, y, 0]) == "minecraft:bedrock") - .unwrap_or(64); - [0, top - 3, 0] + // The rim's level, found without assuming the centre column is intact. + [0, self.podium_level().unwrap_or(61), 0] } }; self.place_podium(origin, true)