From 72de6e0b70aece450db738b421222b4ec9b6bd78 Mon Sep 17 00:00:00 2001 From: vlesmentie <129341611+vlesmentie@users.noreply.github.com> Date: Sun, 25 Oct 2026 17:25:48 -0300 Subject: [PATCH] Water cauldrons put out a burning player and lose a level On top of the lava cauldron's inside test: water and powder snow cauldrons are no longer skipped. Their entity-inside shape is the cauldron's or their content, Block.column(12, 4, 6 + 3 per level), and LayeredCauldronBlock.entityInside applies: on a server, a burning player first asks for handleEntityOnFireInside (runBefore EXTINGUISH), which lowers the fill level (lowerFillLevel, a powder snow cauldron turning to water of its level first, block_change with no source); then EXTINGUISH (Entity.clearFire) puts the fire out. Fixes #1330. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/cauldron.rs | 34 +++++ crates/horizon-client/src/game.rs | 30 +++++ crates/horizon-client/src/game/lan_actions.rs | 6 + crates/horizon-client/src/motion.rs | 120 +++++++++++++++--- 4 files changed, 173 insertions(+), 17 deletions(-) diff --git a/crates/horizon-client/src/cauldron.rs b/crates/horizon-client/src/cauldron.rs index 9fbe1179f..03fb0676d 100644 --- a/crates/horizon-client/src/cauldron.rs +++ b/crates/horizon-client/src/cauldron.rs @@ -87,6 +87,19 @@ fn filled(player: &mut dyn Player, new: ItemStack, limit_creative: bool) { } } +/// `LayeredCauldronBlock.handleEntityOnFireInside`: a burning entity in a +/// water cauldron lowers it a level; a powder snow cauldron becomes a water +/// cauldron of its level first, then lowers. +pub fn extinguished(cauldron: &BlockState) -> BlockState { + if cauldron.name == "minecraft:powder_snow_cauldron" { + let mut water = cauldron.clone(); + water.name = "minecraft:water_cauldron".into(); + lowered(&water) + } else { + lowered(cauldron) + } +} + /// `LayeredCauldronBlock.lowerFillLevel`. fn lowered(cauldron: &BlockState) -> BlockState { let level: u8 = cauldron @@ -296,3 +309,24 @@ pub fn interact( _ => pass(), } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn a_burning_entity_lowers_water_and_melts_powder_snow() { + let water = |l| state("minecraft:water_cauldron", Some(l)); + assert_eq!(extinguished(&water(3)), water(2)); + assert_eq!(extinguished(&water(1)), state("minecraft:cauldron", None)); + // Powder snow turns to water of its level, then lowers. + assert_eq!( + extinguished(&state("minecraft:powder_snow_cauldron", Some(3))), + water(2) + ); + assert_eq!( + extinguished(&state("minecraft:powder_snow_cauldron", Some(1))), + state("minecraft:cauldron", None) + ); + } +} diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 699468651..f75064d76 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -4289,6 +4289,7 @@ impl Game<'_> { MotionEvent::Snowflake { position, velocity } => self.snowflake(position, velocity), MotionEvent::EnterBlock { state } => self.trigger_enter_block(state), MotionEvent::InsidePortal { pos } => self.player_inside_nether_portal(pos), + MotionEvent::CauldronExtinguish { pos } => self.cauldron_extinguish(pos), MotionEvent::SmashLanding { state, position, @@ -8354,6 +8355,35 @@ impl Game<'_> { self.level_set(pos, id)?; Ok(true) } + /// `LayeredCauldronBlock.handleEntityOnFireInside` for a burning player + /// in the cauldron at `pos` (`mayInteract`: not a spectator): the fill + /// level drops (`lowerFillLevel`, a `block_change` with no source). A + /// server's cauldron is the server's. + pub(super) fn cauldron_extinguish(&mut self, pos: BlockPos) { + if self.remote.is_some() { + return; + } + let at = [pos.x, pos.y, pos.z]; + let registry = self.pack.assets.registry; + let Some(old) = registry + .state(self.world.block(at[0], at[1], at[2])) + .filter(|s| { + matches!( + s.name.as_str(), + "minecraft:water_cauldron" | "minecraft:powder_snow_cauldron" + ) + }) + .cloned() + else { + return; + }; + let Ok(new) = registry.resolve(&horizon_client::cauldron::extinguished(&old)) else { + return; + }; + if self.level_set(at, new).is_ok() { + self.post_block_game_event("minecraft:block_change", at, None, Some(new)); + } + } fn damage_held(&mut self, amount: u32) { if self.creative { return; diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index 2c7019c73..6090fb896 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -2010,6 +2010,12 @@ impl Game<'_> { let _ = w.apply_fire_contact(); let _ = w.server_hazards_tick(in_wall); let mut events = std::mem::take(&mut w.player.events); + // LayeredCauldronBlock.handleEntityOnFireInside along those moves. + for event in &events { + if let MotionEvent::CauldronExtinguish { pos } = event { + game.cauldron_extinguish(*pos); + } + } // ServerGamePacketListenerImpl.handleMovePlayer: // Player.checkMovementStatistics for each move. for d in travelled { diff --git a/crates/horizon-client/src/motion.rs b/crates/horizon-client/src/motion.rs index 8637ead1f..5835c4629 100644 --- a/crates/horizon-client/src/motion.rs +++ b/crates/horizon-client/src/motion.rs @@ -167,6 +167,11 @@ pub enum MotionEvent { InsidePortal { pos: BlockPos, }, + /// `LayeredCauldronBlock.handleEntityOnFireInside`: a burning player in + /// a water or powder snow cauldron; the server lowers its fill level. + CauldronExtinguish { + pos: BlockPos, + }, /// `ServerPlayer.checkFallDamage` after a mace smash: block particles /// from the landing block, more the further the fall. SmashLanding { @@ -1259,22 +1264,31 @@ impl MotionWorld<'_, '_, '_> { continue; } let powder_snow = name == "minecraft:powder_snow"; - let lava_cauldron = name == "minecraft:lava_cauldron"; + // A filled cauldron's content top in blocks: the lava's 15/16 + // (LavaCauldronBlock.FILLED_SHAPE), or a layered cauldron's + // getPixelContentHeight, 6 + 3 per level (FILLED_SHAPES). + let content_top = match name { + "minecraft:lava_cauldron" => Some(15.0 / 16.0), + "minecraft:water_cauldron" | "minecraft:powder_snow_cauldron" => { + let level = self + .assets + .registry + .state(state) + .and_then(|s| s.properties.get("level")) + .and_then(|l| l.parse::().ok()) + .unwrap_or(1); + Some((6.0 + 3.0 * f64::from(level)) / 16.0) + } + _ => None, + }; // getEntityInsideCollisionShape is the whole block but for powder // snow (its collision shape, the whole block when it is empty), // filled cauldrons, end portals and tripwires; Horizon doesn't - // follow the player into the water and powder snow cauldrons, end - // portals or tripwires yet. - if matches!( - name, - "minecraft:water_cauldron" - | "minecraft:powder_snow_cauldron" - | "minecraft:end_portal" - | "minecraft:tripwire" - ) { + // follow the player into those last two. + if matches!(name, "minecraft:end_portal" | "minecraft:tripwire") { continue; } - let inside = !(powder_snow || lava_cauldron) || { + let inside = !(powder_snow || content_top.is_some()) || { let context = self.context(); let binding = self.collision_binding; let shape = binding.collision_shape_with_context( @@ -1287,12 +1301,12 @@ impl MotionWorld<'_, '_, '_> { || { let offset = Vec3::new(f64::from(p.x), f64::from(p.y), f64::from(p.z)); let mut boxes: Vec<_> = shape.moved(offset).boxes().to_vec(); - if lava_cauldron { - // LavaCauldronBlock.FILLED_SHAPE: the cauldron's - // shape or its lava, Block.column(12, 4, 15). + if let Some(top) = content_top { + // The cauldron's shape or its content, + // Block.column(12, 4, top). boxes.push(Aabb::new( Vec3::new(2.0 / 16.0, 4.0 / 16.0, 2.0 / 16.0).add_vector(offset), - Vec3::new(14.0 / 16.0, 15.0 / 16.0, 14.0 / 16.0).add_vector(offset), + Vec3::new(14.0 / 16.0, top, 14.0 / 16.0).add_vector(offset), )); } self.player @@ -1302,11 +1316,14 @@ impl MotionWorld<'_, '_, '_> { } }; if inside && visited.insert(p.pack()) { - // CactusBlock, CampfireBlock and LavaCauldronBlock.entityInside - // (`entity.hurt`). + // CactusBlock, CampfireBlock and the cauldrons' entityInside + // (`entity.hurt`, the fire and the fill level). match name { "minecraft:cactus" => self.environment_hurt("minecraft:cactus", 1.0)?, "minecraft:lava_cauldron" => self.lava_cauldron_inside()?, + "minecraft:water_cauldron" | "minecraft:powder_snow_cauldron" => { + self.layered_cauldron_inside(p); + } "minecraft:campfire" | "minecraft:soul_campfire" => { let lit = self .assets @@ -1372,6 +1389,18 @@ impl MotionWorld<'_, '_, '_> { self.player.ignite_for_ticks(300)?; self.environment_hurt("minecraft:lava", 4.0) } + /// `LayeredCauldronBlock.entityInside`: on a server, a burning player + /// asks for the cauldron's `handleEntityOnFireInside` (runBefore + /// EXTINGUISH, so while still burning), then EXTINGUISH + /// (`Entity.clearFire`) puts the fire out. + fn layered_cauldron_inside(&mut self, pos: BlockPos) { + if self.player.fire_ticks > 0 && !self.player.spectator { + self.player + .events + .push(MotionEvent::CauldronExtinguish { pos }); + } + self.player.fire_ticks = self.player.fire_ticks.min(0); + } /// `WebBlock.entityInside`: stuck at a quarter of the speed, half with /// the Weaving effect. fn web_inside(&mut self) { @@ -2434,6 +2463,63 @@ mod tests { assert!(away.fire_ticks <= 0); } + #[test] + fn a_water_cauldron_puts_out_a_burning_player() { + let root = std::env::var_os("HORIZON_TEST_RESOURCES") + .map(std::path::PathBuf::from) + .unwrap_or_else(|| { + Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION) + }); + if !root.join("movement-properties.nbt").exists() { + return; + } + let assets = Assets::load(&root).unwrap(); + let render = assets.reload(&root).unwrap(); + let binding = crate::collisions::load(&root, assets.registry).unwrap(); + let resources = MotionResources::load(&root, &assets).unwrap(); + let mut scene = World::test_scene(&assets, &render, 1).unwrap(); + let water = assets + .registry + .resolve(&horizon_world::chunk::BlockState { + name: "minecraft:water_cauldron".into(), + properties: [("level".to_owned(), "3".to_owned())].into(), + }) + .unwrap(); + scene.set(20, 4, 20, water).unwrap(); + let mut tick = |player: &mut PlayerMotion| { + MotionWorld { + entities: &[], + player, + scene: &mut scene, + assets: &assets, + collision_binding: &binding, + resources: &resources, + } + .controlled_simulation_tick(Default::default()) + .unwrap(); + }; + let asks = |player: &PlayerMotion| { + player + .events + .iter() + .filter(|e| matches!(e, MotionEvent::CauldronExtinguish { .. })) + .count() + }; + // Burning, on the cauldron's floor in its water: put out, and the + // server is asked to lower the water. + let mut burning = PlayerMotion::new(&resources, Vec3::new(20.5, 4.25, 20.5)).unwrap(); + burning.fire_ticks = 100; + tick(&mut burning); + assert!(burning.fire_ticks <= 0, "the water must put the fire out"); + assert_eq!(asks(&burning), 1); + // Not burning: nothing to lower. + let mut dry = PlayerMotion::new(&resources, Vec3::new(20.5, 4.25, 20.5)).unwrap(); + tick(&mut dry); + assert_eq!(asks(&dry), 0); + } + #[test] fn server_travel_moves_only_the_velocity() { let root = Path::new(env!("CARGO_MANIFEST_DIR"))