Files
horizon-airdef/crates/horizon-client/src/game/falling_damage.rs
T
Ludovic Marie a67a323959 Server: one level per dimension, so players can be in different dimensions
A server (the dedicated server and single player's server thread) now
holds a level per dimension, like vanilla's `MinecraftServer.levels`. Each
server tick runs every level with players in it, one at a time, by swapping
its fields into place (game/levels.rs), so the world tick code runs
unchanged. Before this, a portal did nothing while two or more players were
online.

- Levels: the parked levels keep the world, streaming, save, block ticks,
  entities, block entity state, raids, sculk and creaking scans. The
  Overworld stays loaded; another level is saved and closed after 300 ticks
  with nobody in it. Saving saves every level.
- Hub: `tick` is split into `poll` (the network, once per tick),
  `tick_level` (the packets, chunks, block changes, containers and entities
  of the players in the level in place) and `end_tick` (latency). Each guest
  has a dimension; time, weather, sounds and events reach only the players
  in their level, and the clock and weather last sent are kept per level.
- Travel: every player has their own portal state; a portal moves only that
  player into the destination's level (`ServerPlayer.teleport` packets as
  before). Respawning brings a player back to the Overworld's level.
- Player data saves and loads each player's dimension, and a returning
  player is placed in their own level.
- tools/lan_e2e.py --server-thread --check portals: the guest goes to the
  Nether while the host stays, then the host goes to the End while the guest
  is in the Nether, and both come back.

The in-frame game keeps its one level that follows its player.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 14:46:03 +02:00

124 lines
4.5 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,
});
}
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
};
let hurt = if let Some(p) = self.player.as_mut()
&& let Some(id) = self.motion.health.damage.id(kind)
{
p.hurt(&self.motion.health, self.world.health_rules, id, amount)
.unwrap_or(false)
} else {
false
};
if hurt {
self.hurt_armor(amount);
}
}
}