chore: some fixes

This commit is contained in:
Alexander Medvedev
2026-08-02 10:49:37 +02:00
parent 141b49f973
commit 98d4451fc9
22 changed files with 44571 additions and 143 deletions

View File

@@ -0,0 +1,42 @@
use proc_macro2::TokenStream;
use quote::quote;
const MAX_VIEW_DISTANCE: u8 = 32;
pub fn build() -> TokenStream {
let entries = (0..=MAX_VIEW_DISTANCE).map(|dist| {
if dist < 2 {
return quote! { &[] };
}
let mut positions = vec![];
let d = i64::from(dist);
for z in -(d + 2)..=(d + 2) {
for x in -(d + 2)..=(d + 2) {
let rel_x = (x.abs() - 2).max(0);
let rel_z = (z.abs() - 2).max(0);
if rel_x * rel_x + rel_z * rel_z < d * d {
positions.push((x as i8, z as i8));
}
}
}
positions.sort_by_key(|&(x, z)| i32::from(x).pow(2) + i32::from(z).pow(2));
let array_elems = positions.into_iter().map(|(x, z)| quote!((#x, #z)));
quote! {
&[ #(#array_elems),* ]
}
});
let array_len = MAX_VIEW_DISTANCE as usize + 1;
quote! {
/// The maximum supported view distance
pub const MAX_VIEW_DISTANCE: u8 = #MAX_VIEW_DISTANCE;
/// Static precomputed lookup table for relative chunk offsets by view distance (0..=32).
pub static CHUNK_VIEW_LUT: [&[(i8, i8)]; #array_len] = [ #(#entries),* ];
}
}

View File

@@ -18,6 +18,7 @@ mod block;
mod carver;
pub mod chest_loot;
mod chunk_gen_settings;
mod chunk_view_lut;
mod chunk_status;
mod composter_increase_chance;
mod configured_feature;
@@ -85,6 +86,7 @@ pub fn main() {
(meta_data_type::build, "meta_data_type.rs"),
(tracked_data::build, "tracked_data.rs"),
(chunk_status::build, "chunk_status.rs"),
(chunk_view_lut::build, "chunk_view_lut.rs"),
(game_event::build, "game_event.rs"),
(game_rules::build, "game_rules.rs"),
(registry::build, "registry.rs"),