diff --git a/crates/horizon-client/src/creative.rs b/crates/horizon-client/src/creative.rs index a6e0f0b93..a262ad1d5 100644 --- a/crates/horizon-client/src/creative.rs +++ b/crates/horizon-client/src/creative.rs @@ -355,6 +355,19 @@ impl Creative { pub fn search_items(&self) -> &[ItemStack] { &self.search_items } + /// Opening the screen: vanilla rebuilds CreativeModeInventoryScreen, whose + /// init() makes a fresh search box and a zeroed scrollbar; only the tab + /// persists (its static selectedTab). selectTab on the reopened screen + /// takes the oldTab != tab branch, so it empties and refocuses the box. + pub fn reopen(&mut self) { + self.search.set_value(""); + self.release(); + self.scroll = 0.0; + self.search.focused = self.tab().search; + if self.search.focused { + self.search.reset_blink(); + } + } /// Indices into `search_items` that CreativeModeInventoryScreen.refreshSearchResults /// shows for `term`: the whole tab when empty, the tag tree after `#`, else /// the name tree, both over vanilla's suffix arrays (substring matches, diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 40b21a7c0..016b18620 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -12070,11 +12070,12 @@ impl Game<'_> { Screen::Playing => { // key.inventory while riding a tamed mount opens its inventory. if !self.open_ridden_mount_menu() { - self.screen = if self.creative { - Screen::Creative + if self.creative { + self.screen = Screen::Creative; + self.creative_screen.reopen(); } else { - Screen::Inventory - }; + self.screen = Screen::Inventory; + } self.capture(false); } } diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 3e0b5b455..3cf5b452c 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -5346,11 +5346,12 @@ impl Game<'_> { KeyCode::KeyE => { // The inventory opens without telling the server. self.recipe_ui.reset_screen(); - self.screen = if self.creative { - Screen::Creative + if self.creative { + self.screen = Screen::Creative; + self.creative_screen.reopen(); } else { - Screen::Inventory - }; + self.screen = Screen::Inventory; + } self.craft_size = 2; self.capture(false); Ok(true)