2dd5792ae3
🤖 Agent: Gate check by Ludovic's AI agent (Claude). Checked against 26.3: `FallingBlockEntity` with a `BrushableBlock` breaks it where it lands (`onBrokenAfterFall`'s sound and level event). Left for later: the game event uses the block position, not the bounding-box centre. Gate: this wave's 50 PRs merged on main in one tree (union 9033a9c3b): fmt and clippy `-D warnings` clean, the horizon-client (1136 lib plus the integration tests), horizon-client-core (37), horizon-world (165) and horizon-protocol (100) tests pass, the fast build links, and the 140 harnesses `parity.py` picks for the tree's changed files pass on playhorizon (remote_fireworks, a known load flake there, passed on a rerun on a quiet Mac mini). `lan_e2e.py` passes 14 checks with the host on its server thread and in-frame (chest, xp, damage, kills, projectiles, mobs, drops, body, stopsound, digging, instant_digging, books, knockback, barter); `hurt` fails on main too when run after `damage` (check-order dependency, not this wave). Thanks @FusselTV!
137 lines
5.0 KiB
Rust
137 lines
5.0 KiB
Rust
//! Landing impacts for falling blocks, before their placement/drop decision.
|
|
use super::{FallingBlock, Game, Landing};
|
|
use horizon_client::{falling_block, items::ItemStack};
|
|
use horizon_core::{geometry::Vec3, position::BlockPos, random::RandomSource};
|
|
use horizon_world::level::LevelEvent;
|
|
|
|
impl Game<'_> {
|
|
pub(super) fn finish_falling_block(&mut self, mut block: FallingBlock, pos: [i32; 3]) {
|
|
let anvil = self.res.facts().get(block.state).name.ends_with("anvil");
|
|
if let Some(impact) = block.damage.impact(block.fall_distance) {
|
|
if impact.amount > 0.0 {
|
|
falling_block::hurt_mobs(&mut self.mobs, block.position, impact.amount);
|
|
let kind = if anvil {
|
|
"minecraft:falling_anvil"
|
|
} else {
|
|
"minecraft:falling_block"
|
|
};
|
|
self.falling_hurt_player(block.position, impact.amount, kind);
|
|
if let Some(mut host) = self.lan.take() {
|
|
let bounds = falling_block::bounds(block.position);
|
|
let conns = host
|
|
.hub
|
|
.guests
|
|
.iter()
|
|
.filter(|g| {
|
|
host.hub.here(g)
|
|
&& g.loaded
|
|
&& !g.dead
|
|
&& !g.creative()
|
|
&& !g.spectator()
|
|
&& bounds.intersects(super::lan_mobs::guest_bounds(g))
|
|
})
|
|
.map(|g| g.conn)
|
|
.collect::<Vec<_>>();
|
|
for conn in conns {
|
|
self.guest_hit_by(&mut host, conn, |g| {
|
|
g.falling_hurt_player(block.position, impact.amount, kind)
|
|
});
|
|
}
|
|
self.lan = Some(host);
|
|
}
|
|
}
|
|
if anvil
|
|
&& impact.wear_chance > 0.0
|
|
&& self.world.random.next_float() < impact.wear_chance
|
|
&& let Some(mut state) = self.pack.assets.registry.state(block.state).cloned()
|
|
{
|
|
if falling_block::wear_anvil(&mut state) {
|
|
block.state = self
|
|
.pack
|
|
.assets
|
|
.registry
|
|
.resolve(&state)
|
|
.unwrap_or(block.state);
|
|
} else {
|
|
block.damage.cancel_drop = true;
|
|
}
|
|
}
|
|
}
|
|
if block.damage.cancel_drop {
|
|
if anvil {
|
|
self.level_events.push(LevelEvent::LevelEvent {
|
|
id: 1029,
|
|
pos: BlockPos::new(pos[0], pos[1], pos[2]),
|
|
data: 0,
|
|
});
|
|
} else if self
|
|
.res
|
|
.facts()
|
|
.get(block.state)
|
|
.name
|
|
.starts_with("minecraft:suspicious_")
|
|
{
|
|
// BrushableBlock.onBrokenAfterFall.
|
|
let at = BlockPos::new(pos[0], pos[1], pos[2]);
|
|
self.level_events.push(LevelEvent::LevelEvent {
|
|
id: 2001,
|
|
pos: at,
|
|
data: block.state.0 as i32,
|
|
});
|
|
self.level_events.push(LevelEvent::GameEvent {
|
|
pos: at,
|
|
event: "minecraft:block_destroy",
|
|
state: None,
|
|
});
|
|
}
|
|
return;
|
|
}
|
|
let landing = self.with_level(|b, level, ticks| {
|
|
b.falling_block_landed(
|
|
level,
|
|
ticks,
|
|
BlockPos::new(pos[0], pos[1], pos[2]),
|
|
block.state,
|
|
false,
|
|
)
|
|
});
|
|
if matches!(landing, Landing::Broken)
|
|
&& block.drop_item
|
|
&& self.ui.rules.bool("entity_drops")
|
|
{
|
|
let item = self.res.facts().get(block.state).item.clone();
|
|
if &*item != "minecraft:air" {
|
|
self.pop_resource(
|
|
pos,
|
|
ItemStack {
|
|
item,
|
|
count: 1,
|
|
damage: 0,
|
|
extra: None,
|
|
},
|
|
);
|
|
}
|
|
}
|
|
}
|
|
fn falling_hurt_player(&mut self, position: Vec3, amount: f32, kind: &str) {
|
|
if self.creative || self.spectator() {
|
|
return;
|
|
}
|
|
if self.player.as_ref().is_none_or(|p| {
|
|
p.health.dead_or_dying() || !falling_block::bounds(position).intersects(p.bounds())
|
|
}) {
|
|
return;
|
|
}
|
|
let amount = if self.armor[0].is_some() {
|
|
amount * 0.75
|
|
} else {
|
|
amount
|
|
};
|
|
if let Some(p) = self.player.as_mut()
|
|
&& let Some(id) = self.motion.health.damage.id(kind)
|
|
{
|
|
let _ = p.hurt(&self.motion.health, self.world.health_rules, id, amount);
|
|
}
|
|
}
|
|
}
|