diff --git a/crates/horizon-client/src/game/campfire_douse.rs b/crates/horizon-client/src/game/campfire_douse.rs index 04accb2d3..e3a990b27 100644 --- a/crates/horizon-client/src/game/campfire_douse.rs +++ b/crates/horizon-client/src/game/campfire_douse.rs @@ -2,8 +2,60 @@ //! shovels) put on a lit campfire puts it out. use super::Game; use horizon_client::{Result, animate_tick::make_campfire_smoke, items::ItemStack}; +use horizon_core::position::BlockPos; +use horizon_world::chunk::BlockState; +use winit::keyboard::KeyCode; impl Game<'_> { + /// The lit campfire at `pos` that `held` puts out, when the item is in + /// `#minecraft:douses_campfires` (`CampfireBlock.useItemOn`). + fn campfire_to_douse(&self, pos: [i32; 3], held: Option<&ItemStack>) -> Option { + held.filter(|s| { + self.res + .items() + .item_tags + .get("minecraft:douses_campfires") + .is_some_and(|members| members.contains(&*s.item)) + })?; + self.pack + .assets + .registry + .state(self.world.block(pos[0], pos[1], pos[2])) + .filter(|s| matches!(&*s.name, "minecraft:campfire" | "minecraft:soul_campfire")) + .filter(|s| s.properties.get("lit").map(String::as_str) == Some("true")) + .cloned() + } + + /// `CampfireBlock.useItemOn` as this client runs it before the server's + /// answer (`MultiPlayerGameMode.useItemOn`): the twenty smoke puffs of + /// `CampfireBlock.douse` and the campfire gone out, kept as predicted + /// under `seq`. The level event's sound comes from the server. True when + /// it doused (SUCCESS), which ends the click for both hands. + pub(super) fn predict_campfire_douse( + &mut self, + pos: [i32; 3], + held: Option<&ItemStack>, + seq: i32, + ) -> bool { + // Player.isSecondaryUseActive: a held item means both hands count. + if self.keys.contains(&KeyCode::ShiftLeft) { + return false; + } + let Some(mut state) = self.campfire_to_douse(pos, held) else { + return false; + }; + let signal = state.properties.get("signal_fire").map(String::as_str) == Some("true"); + for _ in 0..20 { + make_campfire_smoke(&mut self.particles, pos, signal, true); + } + state.properties.insert("lit".into(), "false".into()); + if let Ok(unlit) = self.pack.assets.registry.resolve(&state) { + let at = BlockPos::new(pos[0], pos[1], pos[2]); + self.predict_blocks(&vec![(at, unlit)], seq); + } + true + } + /// `CampfireBlock.useItemOn` with `held` in the hand that acts, the block /// at `pos` clicked: true when it doused a lit campfire (SUCCESS). pub(super) fn use_campfire_douse( @@ -11,24 +63,11 @@ impl Game<'_> { pos: [i32; 3], held: Option<&ItemStack>, ) -> Result { - let Some(tool) = held.filter(|s| { - self.res - .items() - .item_tags - .get("minecraft:douses_campfires") - .is_some_and(|members| members.contains(&*s.item)) - }) else { - return Ok(false); - }; - let registry = self.pack.assets.registry; - let Some(mut state) = registry - .state(self.world.block(pos[0], pos[1], pos[2])) - .filter(|s| matches!(&*s.name, "minecraft:campfire" | "minecraft:soul_campfire")) - .filter(|s| s.properties.get("lit").map(String::as_str) == Some("true")) - .cloned() + let (Some(used), Some(mut state)) = (held.cloned(), self.campfire_to_douse(pos, held)) else { return Ok(false); }; + let registry = self.pack.assets.registry; // Level event 1009 (SOUND_EXTINGUISH_FIRE) goes to every player. self.level_event_at(1009, pos, 0); // CampfireBlock.douse: the acting client's own smoke (twenty puffs), @@ -44,7 +83,6 @@ impl Game<'_> { if let Ok(unlit) = registry.resolve(&state) { self.level_set(pos, unlit)?; } - let used = tool.clone(); self.damage_held(1); // ServerPlayerGameMode.useItemOn: the action was consumed. self.trigger_block("minecraft:item_used_on_block", pos, &used); diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 3cfbd15e3..9a6d19b72 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -4063,6 +4063,11 @@ impl Game<'_> { } if reacts { self.predict_use(&changes, seq); + } else if self.predict_campfire_douse(hit.pos, held.as_ref(), seq) { + // CampfireBlock.useItemOn succeeded: this hand swings and the + // click ends, so a shield in the other hand is not raised. + self.with_hand(hand, Game::swing_arm); + return true; } else if let Some(stack) = held.as_ref() && self.predict_item_on_block(stack, &hit) { @@ -4230,7 +4235,7 @@ impl Game<'_> { /// predicted under the use's sequence until the server acknowledges it /// (`BlockStatePredictionHandler.retainKnownServerState`): a use the /// server refused goes back. - fn predict_blocks(&mut self, changes: &DryChanges, seq: i32) { + pub(super) fn predict_blocks(&mut self, changes: &DryChanges, seq: i32) { for &(p, state) in changes { let pos = [p.x, p.y, p.z]; let before = self.world.block(p.x, p.y, p.z);