Scale entity tracking range by entity-broadcast-range-percentage

The property was parsed and ignored. The tracking range of each entity type is now scaled by it on a dedicated server, like DedicatedServer.getScaledTrackingDistance.
This commit is contained in:
Kacpherek
2026-10-26 19:56:22 +01:00
parent 72e678be8c
commit e7e6e5bc07
3 changed files with 17 additions and 4 deletions
@@ -654,6 +654,9 @@ impl Game<'_> {
// DedicatedServer.initServer ends with saveEverything(false, true, true).
self.save_game()?;
self.log_saved_levels();
if let Some(host) = self.lan.as_mut() {
host.hub.entity_range_percent = props.entity_broadcast_range_percentage;
}
let mut state = ServerState {
lists,
console,
+10 -4
View File
@@ -611,8 +611,9 @@ pub struct Viewer<'a> {
}
/// One entity as this tick's range checks read it: where it is
/// horizontally, its id, its type's tracking range in chunks and the chunk
/// it is in (an index into the tick's chunks).
/// horizontally, its id, its tracking range in blocks (scaled by
/// `entity-broadcast-range-percentage`) and the chunk it is in (an index
/// into the tick's chunks).
#[derive(Clone, Copy)]
struct Probe {
x: f64,
@@ -627,7 +628,7 @@ struct Probe {
/// each of the tick's chunks whether the client has it (0: not looked up
/// yet, 1: no, 2: yes), so each chunk is looked up once per client.
fn sees(v: &Viewer, p: &Probe, chunks: &[(i32, i32)], held: &mut [u8]) -> bool {
let range = f64::from(p.range.min(v.view_distance) * 16);
let range = f64::from(p.range.min(v.view_distance * 16));
let (dx, dz) = (v.position[0] - p.x, v.position[2] - p.z);
dx * dx + dz * dz <= range * range && {
let held = &mut held[p.chunk as usize];
@@ -641,6 +642,9 @@ fn sees(v: &Viewer, p: &Probe, chunks: &[(i32, i32)], held: &mut [u8]) -> bool {
/// One level's tracked entities (ChunkMap.entityMap).
#[derive(Default)]
pub struct Entities {
/// `entity-broadcast-range-percentage` (None: 100), which scales every
/// type's tracking range (MinecraftServer.getScaledTrackingDistance).
pub range_percent: Option<i32>,
states: crate::fast_hash::FxHashMap<i32, ServerEntity>,
/// The level tick, stamped on every entity still in the level.
tick: u32,
@@ -732,7 +736,9 @@ impl Entities {
x: e.position[0],
z: e.position[2],
id: e.id,
range: s.range,
range: self
.range_percent
.map_or(s.range * 16, |p| p * (s.range * 16) / 100),
chunk,
});
}
+4
View File
@@ -168,6 +168,8 @@ pub struct Hub {
level_sync: std::collections::HashMap<String, LevelSync>,
/// Operators and their permission levels (dedicated servers).
pub ops: std::collections::HashMap<u128, u8>,
/// `entity-broadcast-range-percentage` (dedicated servers).
pub entity_range_percent: i32,
chat_type: i32,
dimension_type: i32,
clock_ids: Vec<i32>,
@@ -332,6 +334,7 @@ impl Hub {
ticking: (20.0, false),
stepping: 0,
ops: Default::default(),
entity_range_percent: 100,
weather: (false, 0.0, 0.0),
level_sync: Default::default(),
chat_type,
@@ -1678,6 +1681,7 @@ impl Hub {
out,
})
.collect();
level.range_percent = Some(self.entity_range_percent);
let (types, sync) = (&mut self.entity_types, &self.sync);
level.tick(&entities, &self.riding, &mut viewers, |kind| {
entity_type(types, sync, kind)