Merge pull request #1918 from vlesmentie/fix/water-cauldron-extinguish
🤖 Agent: Thanks vlesmentie! Matches LayeredCauldronBlock.entityInside / handleEntityOnFireInside: a burning player is put out and the cauldron loses a level. The cauldron harness passes, and lava and contacts pass on both hosts. Tested together with the other wave 2 contributor PRs: fmt, clippy -D warnings, and the horizon-client, horizon-world and horizon-protocol tests pass. Of the 127 harnesses the batch affects, 124 pass; the other three are a player-head mismatch fixed in #1934 and two worldgen timeouts on a loaded machine with no chunk differing. lan_e2e chat, fireball, cursor, looks, thrown, eat, shield, lava, contacts, projectiles and mobs pass with the host in-frame and on its server thread.
This commit is contained in:
@@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4329,6 +4329,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::InsideWitherRose => self.wither_rose_contact(),
|
||||
MotionEvent::SmashLanding {
|
||||
state,
|
||||
@@ -8479,6 +8480,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;
|
||||
|
||||
@@ -2111,6 +2111,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);
|
||||
}
|
||||
}
|
||||
// WitherRoseBlock.entityInside along those moves.
|
||||
for event in &events {
|
||||
if matches!(event, MotionEvent::InsideWitherRose) {
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
/// `WitherRoseBlock.entityInside`: the player's box swept through a
|
||||
/// wither rose; the server adds its Wither unless peaceful.
|
||||
InsideWitherRose,
|
||||
@@ -1277,22 +1282,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::<u8>().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(
|
||||
@@ -1305,12 +1319,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
|
||||
@@ -1320,11 +1334,15 @@ impl MotionWorld<'_, '_, '_> {
|
||||
}
|
||||
};
|
||||
if inside && visited.insert(p.pack()) {
|
||||
// CactusBlock, CampfireBlock and LavaCauldronBlock.entityInside
|
||||
// (`entity.hurt`), and WitherRoseBlock's server-side effect.
|
||||
// CactusBlock, CampfireBlock and the cauldrons' entityInside
|
||||
// (`entity.hurt`, the fire and the fill level), and
|
||||
// WitherRoseBlock's server-side effect.
|
||||
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:wither_rose" => {
|
||||
self.player.events.push(MotionEvent::InsideWitherRose);
|
||||
}
|
||||
@@ -1395,6 +1413,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) {
|
||||
@@ -2457,6 +2487,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 standing_in_a_wither_rose_asks_for_its_effect() {
|
||||
let root = std::env::var_os("HORIZON_TEST_RESOURCES")
|
||||
|
||||
Reference in New Issue
Block a user