diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 36ad6633b..27a2523ab 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -1546,6 +1546,8 @@ struct Game<'a> { sleep_timer: u32, dim: Dim, world_root: PathBuf, + /// The world is superflat (`ServerLevel.isFlat`, for every dimension). + world_flat: bool, /// A player carried through a portal, re-placed once the destination loads. travelling: Option<(PlayerMotion, Vec3)>, /// A server's players on their way to another level, each waiting for @@ -8685,6 +8687,7 @@ impl Game<'_> { book.to_be_displayed.retain(|r| index.contains(r)); self.dim = dim; self.world_root = save_root.clone(); + self.world_flat = horizon_client::save::WorldGen::read(&save_root).is_some_and(|w| w.flat); self.block_ticks = Ticks::new(self.level.seed as i32); self.tick_chunks.clear(); self.clear_entities(); @@ -13361,6 +13364,7 @@ impl<'a> Game<'a> { sleep_timer: 0, dim: Dim::Overworld, world_root: PathBuf::new(), + world_flat: false, travelling: None, server_trips: Vec::new(), level_teleports: Vec::new(), diff --git a/crates/horizon-client/src/game/lan.rs b/crates/horizon-client/src/game/lan.rs index 21a1630c2..e3aab3071 100644 --- a/crates/horizon-client/src/game/lan.rs +++ b/crates/horizon-client/src/game/lan.rs @@ -1014,7 +1014,8 @@ impl Game<'_> { let host_uuid = host.unwrap_or(0); self.next_entity += 1; let host_entity = self.next_entity as i32; - let hub = Hub::new(lan, sync, encoder, config); + let mut hub = Hub::new(lan, sync, encoder, config); + hub.flat_world = self.world_flat; let port = hub.lan.port; self.world.block_log = Some(Vec::new()); self.world.light_log = Some(Default::default()); diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index b35f164a9..75c0e8690 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -119,7 +119,7 @@ pub(super) struct Remote { pub(super) entity_id: i32, /// The item the player's use began with (`LivingEntity.useItem`). pub(super) use_item: Option>, - dimension: DimensionType, + pub(super) dimension: DimensionType, /// What chunk packets decode with (the dimension's height and sky, the /// biome registry); replaced whenever one of them changes. pub(super) chunk_format: Arc, @@ -202,6 +202,8 @@ pub(super) struct Remote { pub(super) pending_keys: Vec, stop_mining: bool, placing: Option<([i32; 3], u64)>, + /// `CommonPlayerSpawnInfo.isFlat`: the level is a superflat one. + pub(super) flat: bool, death_message: Option, /// `LocalPlayer.showDeathScreen`: off with `immediate_respawn`. show_death_screen: bool, @@ -497,6 +499,7 @@ impl Game<'_> { pending_keys: Vec::new(), stop_mining: false, placing: None, + flat: false, death_message: None, show_death_screen: true, player_type, @@ -1018,6 +1021,7 @@ impl Game<'_> { r.chunk_format = Arc::new(r.chunk_format.with_dimension(&dimension)); r.dimension = dimension; r.game_mode = spawn.game_type; + r.flat = spawn.flat; r.loaded_sent = false; // A replacement LocalPlayer has a fresh sendPosition baseline. r.position_sender = Default::default(); diff --git a/crates/horizon-client/src/game/render_tick.rs b/crates/horizon-client/src/game/render_tick.rs index fecb58615..2b214a491 100644 --- a/crates/horizon-client/src/game/render_tick.rs +++ b/crates/horizon-client/src/game/render_tick.rs @@ -92,9 +92,8 @@ impl Game<'_> { distant_terrain: self.lod.is_some(), cloud_range_chunks: self.settings.cloud_range, camera_y: camera.y, - // level.getMinY(): the Nether and the End start at y 0. - min_y: if self.dim == Dim::Overworld { MIN_Y } else { 0 }, - flat: false, + min_y: self.level_min_y(), + flat: self.level_flat(), forward: forward.map(|c| c as f32), rain, thunder, @@ -108,9 +107,30 @@ impl Game<'_> { }, ) } - /// `SkyRenderer.shouldRenderDarkDisc`: eye below the horizon (y 63) and not under water. + /// `ClientLevelData.isFlat`: on the server thread, the world-wide flag. + fn level_flat(&self) -> bool { + match self.remote.as_ref() { + Some(r) => r.flat, + None => self.world_flat, + } + } + /// `Level.getMinY`: the current dimension type's minimum y. + fn level_min_y(&self) -> i32 { + match self.remote.as_ref() { + Some(r) => r.dimension.min_y, + None => self.dim.min_y(), + } + } + /// `SkyRenderer.shouldRenderDarkDisc`: eye below the horizon and not under + /// water. `ClientLevelData.getHorizonHeight`: the bottom of a flat world, + /// otherwise y 63. pub(super) fn dark_disc(&self, camera: glam::DVec3) -> bool { - camera.y < 63.0 + let horizon = if self.level_flat() { + f64::from(self.level_min_y()) + } else { + 63.0 + }; + camera.y < horizon && fog_type( &self.world, self.res.facts(), diff --git a/crates/horizon-client/src/lan/hub.rs b/crates/horizon-client/src/lan/hub.rs index 12967d778..70b9babe0 100644 --- a/crates/horizon-client/src/lan/hub.rs +++ b/crates/horizon-client/src/lan/hub.rs @@ -178,6 +178,9 @@ pub struct Hub { /// An integrated server's owner (`MinecraftServer.isSingleplayerOwner`), /// whose moves are never checked. pub singleplayer_owner: Option, + /// The world is superflat (`ServerLevel.isFlat`, a world-wide flag, sent as + /// `CommonPlayerSpawnInfo.isFlat` in every dimension). + pub flat_world: bool, /// Who rides what, set by the game before each tick. pub riding: super::entity::Riding, /// The scoreboard's teams, set by the game each tick, for players' @@ -358,6 +361,7 @@ impl Hub { immediate_respawn: false, movement_checks: (true, true), singleplayer_owner: None, + flat_world: false, riding: Default::default(), last_clock: i64::MIN, last_rate: 0.0, @@ -610,7 +614,7 @@ impl Hub { game_type: game_mode, previous_game_type: None, debug: false, - flat: false, + flat: self.flat_world, last_death: None, portal_cooldown: 0, sea_level: 63,