Make clippy pass with -D warnings

Apply clippy's fixes, fix the remaining lints by hand and allow, for the
whole workspace, the lints that one-to-one ports of vanilla's Java
naturally trip (argument counts, index loops, nested types, large enum
variants).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-09 00:32:50 +02:00
parent df14adbfba
commit 488f8bd030
35 changed files with 150 additions and 121 deletions
+8
View File
@@ -7,6 +7,14 @@ edition = "2024"
license = "MIT"
rust-version = "1.85"
# Ports mirror vanilla's Java signatures, index loops and nested generic types
# one to one so they can be checked against the decompiled sources.
[workspace.lints.clippy]
too_many_arguments = "allow"
type_complexity = "allow"
needless_range_loop = "allow"
large_enum_variant = "allow"
[profile.release]
lto = "thin"
codegen-units = 1
+3
View File
@@ -10,3 +10,6 @@ description = "Horizon version-specific model and resource decoding"
horizon-core = { path = "../horizon-core" }
serde = "1.0.229"
serde_json = { version = "1.0.151", features = ["raw_value"] }
[lints]
workspace = true
+3
View File
@@ -22,3 +22,6 @@ serde_json = { version = "1.0.151", features = ["raw_value"] }
cpal = "0.16"
symphonia = { version = "0.5", default-features = false, features = ["ogg", "vorbis"] }
miniz_oxide = "0.8"
[lints]
workspace = true
@@ -276,7 +276,7 @@ fn incremental(
let top = (0..384)
.rev()
.find(|y| world[&(cx, cz)].get(x & 15, MIN_Y + y, z & 15) != 0)
.unwrap_or(100) as i32
.unwrap_or(100)
+ MIN_Y;
let y = top - 3 + next(6) as i32;
let state = palette[next(palette.len() as u64) as usize];
@@ -36,7 +36,7 @@ fn main() -> Result<()> {
}
let assets = assets::Assets::load(&resources)?;
let world = world::World::test_scene(&assets, radius)?;
let binding = collisions::load(&resources, &assets.registry)?;
let binding = collisions::load(&resources, assets.registry)?;
let mut scene = collisions::SceneCollisions {
world: &world,
binding: &binding,
@@ -186,7 +186,7 @@ fn main() -> Result<()> {
let dir = PathBuf::from(&args[1]);
let assets = Assets::load(&root)?;
let mut scene = World::test_scene(&assets, 1)?;
let binding = collisions::load(&root, &assets.registry)?;
let binding = collisions::load(&root, assets.registry)?;
let resources = MotionResources::load(&root, &assets)?;
fs::write(
dir.join("scene.json"),
+5 -5
View File
@@ -263,11 +263,11 @@ impl Ambience {
}
}
for (sound, chance) in &sounds.additions {
if self.random.next_double() < *chance {
if let Some(id) = out.play_tracked(sound, 1.0, false) {
// forAmbientAddition: a one-shot nobody ticks.
let _ = id;
}
if self.random.next_double() < *chance
&& let Some(id) = out.play_tracked(sound, 1.0, false)
{
// forAmbientAddition: a one-shot nobody ticks.
let _ = id;
}
}
let Some(mood) = &sounds.mood else { return };
+1 -1
View File
@@ -192,7 +192,7 @@ impl AnimateTables {
.map(|id| {
registry
.state(BlockStateId(id))
.is_some_and(|s| names.is_some_and(|n| n.iter().any(|t| *t == s.name)))
.is_some_and(|s| names.is_some_and(|n| n.contains(&s.name)))
})
.collect()
};
@@ -85,7 +85,7 @@ pub fn diffuse(normal: Vec3, lights: (Vec3, Vec3)) -> f32 {
}
/// Packed vertex light from the level's packed `sky << 4 | block` byte.
pub fn vertex_light(packed: u8) -> u32 {
u32::from(packed >> 4) * 16 | (u32::from(packed & 15) * 16) << 8
(u32::from(packed >> 4) * 16) | ((u32::from(packed & 15) * 16) << 8)
}
fn pack_color(rgb: u32, alpha: u32, brightness: f32) -> u32 {
let c = |shift: u32| (((rgb >> shift) & 255) as f32 * brightness) as u32;
+5 -2
View File
@@ -47,7 +47,10 @@ impl CommandError {
pub fn context(&self) -> Option<String> {
let input = self.input.as_ref()?;
let cursor = self.cursor.min(input.len());
let start = input.floor_char_boundary(cursor.saturating_sub(10));
let start = (0..=cursor.saturating_sub(10))
.rev()
.find(|&i| input.is_char_boundary(i))
.unwrap_or(0);
let mut out = String::new();
if cursor > 10 {
out.push_str("...");
@@ -490,7 +493,7 @@ pub fn merge_suggestions(input: &str, list: Vec<Suggestion>) -> (Range, Vec<Sugg
out.push(expanded);
}
}
out.sort_by(|a, b| a.text.to_lowercase().cmp(&b.text.to_lowercase()));
out.sort_by_key(|a| a.text.to_lowercase());
((start, end), out)
}
+1 -1
View File
@@ -63,7 +63,7 @@ impl ItemEntity {
self.velocity.y -= 0.04;
}
let horizontal = self.velocity.x * self.velocity.x + self.velocity.z * self.velocity.z;
if !self.on_ground || horizontal > 1.0e-5 || (self.age + self.id) % 4 == 0 {
if !self.on_ground || horizontal > 1.0e-5 || (self.age + self.id).is_multiple_of(4) {
let mut scene = SceneCollisions {
world,
binding: collision,
+1 -3
View File
@@ -121,9 +121,7 @@ fn camera_fluid_height(world: &World, facts: &BlockFacts, b: [i32; 3]) -> Option
}
let above = facts.get(world.block(b[0], b[1] + 1, b[2]));
let source = s.fluid_level >= 8 && !s.fluid_falling;
let height = if source && above.full_collision {
1.0
} else if above.fluid == s.fluid {
let height = if (source && above.full_collision) || above.fluid == s.fluid {
1.0
} else {
f64::from(s.fluid_level) / 9.0
+1 -1
View File
@@ -193,7 +193,7 @@ impl Font {
let name = file
.trim_start_matches("minecraft:")
.trim_end_matches(".png");
let name = format!("{}", name);
let name = name.to_string();
let Some(rect) = sprites.get(&name).copied() else {
continue;
};
+32 -26
View File
@@ -1070,7 +1070,7 @@ impl Game<'_> {
}
LevelEvent::DropResources { pos, state } => {
let drops = self.res.items.block_drops(
&self.res.assets.registry,
self.res.assets.registry,
state,
None,
&mut self.world.random,
@@ -1288,7 +1288,7 @@ impl Game<'_> {
|| self.res.items.correct_for_drops(held.as_ref(), &facts.name);
if harvest {
let drops = self.res.items.block_drops(
&self.res.assets.registry,
self.res.assets.registry,
state,
held.as_ref(),
&mut self.world.random,
@@ -1840,7 +1840,7 @@ impl Game<'_> {
self.world.weather.tick(&mut self.world.random);
}
self.tick_weather_effects();
if self.ticks % 6000 == 0 {
if self.ticks.is_multiple_of(6000) {
self.save_game()?;
}
self.advance_clock();
@@ -2855,10 +2855,10 @@ impl Game<'_> {
let max = |items: &Items, s: &ItemStack| items.get(&s.item).map_or(64, |i| i.max_stack);
let shift =
self.keys.contains(&KeyCode::ShiftLeft) || self.keys.contains(&KeyCode::ShiftRight);
if slot >= 300 {
if let Some(key) = self.container {
self.world.modified.insert((key.0 >> 4, key.2 >> 4));
}
if slot >= 300
&& let Some(key) = self.container
{
self.world.modified.insert((key.0 >> 4, key.2 >> 4));
}
let is_furnace = matches!(self.container_kind(), Some(BlockEntity::Furnace(_)));
if is_furnace && slot == 302 {
@@ -3031,7 +3031,7 @@ impl Game<'_> {
(q.y + 0.1).floor() as i32,
q.z.floor() as i32,
);
let packed = u32::from(light >> 4) * 16 | (u32::from(light & 15) * 16) << 8;
let packed = (u32::from(light >> 4) * 16) | ((u32::from(light & 15) * 16) << 8);
let center = pos.as_vec3() + glam::Vec3::new(0.0, bob + 0.125, 0.0);
let rot = glam::Mat3::from_rotation_y(spin);
let icon = self.icon(&item.stack.item);
@@ -3302,8 +3302,8 @@ impl Game<'_> {
o.position.y.floor() as i32,
o.position.z.floor() as i32,
);
let packed =
u32::from(light >> 4).max(10) * 16 | (u32::from(light & 15).max(10) * 16) << 8;
let packed = (u32::from(light >> 4).max(10) * 16)
| ((u32::from(light & 15).max(10) * 16) << 8);
let c = p.as_vec3();
let s = 0.15;
for (k, uv) in [(-1.0, -1.0), (1.0, -1.0), (1.0, 1.0), (-1.0, 1.0)]
@@ -3340,7 +3340,7 @@ impl Game<'_> {
f.position.y.floor() as i32 + 1,
f.position.z.floor() as i32,
);
let packed = u32::from(light >> 4) * 16 | (u32::from(light & 15) * 16) << 8;
let packed = (u32::from(light >> 4) * 16) | ((u32::from(light & 15) * 16) << 8);
let v = |x: f32, y: f32, z: f32| o + glam::Vec3::new(x, y, z);
let faces = [
(
@@ -3470,7 +3470,7 @@ impl Game<'_> {
uv,
layer: 0,
color: 0xB4FF_FFFF,
light: 15 * 16 | (15 * 16) << 8,
light: (15 * 16) | ((15 * 16) << 8),
});
}
}
@@ -3733,7 +3733,7 @@ impl Game<'_> {
pos: p.to_array(),
uv,
layer: 2,
color: color,
color,
light: 0,
});
}
@@ -3832,7 +3832,7 @@ impl Game<'_> {
let c = sky.cloud_color;
let color = |shade: f32| {
let ch = |v: f32| ((v * shade).clamp(0.0, 1.0) * 255.0) as u32;
ch(c[3].max(0.0).min(1.0)) << 24 | ch(c[2]) << 16 | ch(c[1]) << 8 | ch(c[0])
ch(c[3].clamp(0.0, 1.0)) << 24 | ch(c[2]) << 16 | ch(c[1]) << 8 | ch(c[0])
};
let light = 240 | 240 << 8;
for dz in -radius..=radius {
@@ -4098,7 +4098,7 @@ impl Game<'_> {
.map(|c| self.with_entities(c))
.collect();
self.save
.save(&chunks, &self.res.assets.registry, &self.res.biomes)?;
.save(&chunks, self.res.assets.registry, &self.res.biomes)?;
self.save_dimension_entities()?;
// Coordinates scale by 8 between the Overworld and the Nether.
let scale = match (self.dim, target) {
@@ -5147,7 +5147,7 @@ impl Game<'_> {
eye[1].floor() as i32,
eye[2].floor() as i32,
);
let packed = u32::from(light >> 4) * 16 | (u32::from(light & 15) * 16) << 8;
let packed = (u32::from(light >> 4) * 16) | ((u32::from(light & 15) * 16) << 8);
let deg = |d: f32| d.to_radians();
let sqrt_attack = attack.sqrt();
match self.hand_item.clone() {
@@ -5476,7 +5476,7 @@ impl Game<'_> {
let a = (fade.clamp(0.0, 1.0) * 255.0) as u32;
let color = a << 24 | 0xFF_FFFF;
let light = self.world.light(x, top.max(cy), z);
let packed = u32::from(light >> 4) * 16 | (u32::from(light & 15) * 16) << 8;
let packed = (u32::from(light >> 4) * 16) | ((u32::from(light & 15) * 16) << 8);
let (b, t) = (
(f64::from(y0) - camera.y) as f32,
(f64::from(y1) - camera.y) as f32,
@@ -5842,7 +5842,7 @@ impl Game<'_> {
.map(|c| self.with_entities(c))
.collect();
self.save
.save(&chunks, &self.res.assets.registry, &self.res.biomes)?;
.save(&chunks, self.res.assets.registry, &self.res.biomes)?;
self.save_entities()?;
self.level.selected_slot = self.selected as i32;
let level = &mut self.level;
@@ -6207,7 +6207,7 @@ impl Game<'_> {
if !modified.is_empty()
&& let Err(e) = self
.save
.save(&modified, &self.res.assets.registry, &self.res.biomes)
.save(&modified, self.res.assets.registry, &self.res.biomes)
{
eprintln!("Horizon: failed to save unloaded chunks: {e}");
}
@@ -6627,19 +6627,19 @@ pub fn run() -> Result<()> {
format!("{e}\nPrepare resources with: python3 tools/prepare_native_client.py --prepare")
})?);
eprintln!("load assets: {:.2}s", started.elapsed().as_secs_f32());
let facts = BlockFacts::load(&root, &assets.registry)?;
let facts = BlockFacts::load(&root, assets.registry)?;
let mob_data = horizon_client::mobs::MobData::load(&root, &facts);
eprintln!("load facts: {:.2}s", started.elapsed().as_secs_f32());
let items = Items::load(&root, &assets.registry, &facts)?;
let items = Items::load(&root, assets.registry, &facts)?;
eprintln!("load items: {:.2}s", started.elapsed().as_secs_f32());
let recipes = Recipes::load(&root, &items)?;
let biomes = Arc::new(Biomes::load(&root)?);
let environment = Environment::load(&root)?;
eprintln!("load biomes+env: {:.2}s", started.elapsed().as_secs_f32());
let visibility = models::load_visibility(&root, &assets.registry)?;
let visibility = models::load_visibility(&root, assets.registry)?;
eprintln!("load visibility: {:.2}s", started.elapsed().as_secs_f32());
let tables = Arc::new(MeshTables::new(&assets, &facts, visibility)?);
let light = Arc::new(LightTables::load(&root, &assets.registry, &facts)?);
let light = Arc::new(LightTables::load(&root, assets.registry, &facts)?);
eprintln!("load tables: {:.2}s", started.elapsed().as_secs_f32());
let atlas = HudAtlas::build(&root)?;
horizon_client::ui::load_metadata(&root);
@@ -6654,7 +6654,7 @@ pub fn run() -> Result<()> {
.map(|(name, layer)| (*layer, name.trim_start_matches("minecraft:").to_owned()))
.collect();
let registry_owner = assets.clone();
let collision = collisions::load(&root, &registry_owner.registry)?;
let collision = collisions::load(&root, registry_owner.registry)?;
let motion = MotionResources::load(&root, &registry_owner)?;
eprintln!(
"load collision+motion: {:.2}s",
@@ -6712,7 +6712,7 @@ pub fn run() -> Result<()> {
providers: Providers::load(&root),
block_entity_render: horizon_client::block_entity_render::BlockEntityRenderer::load(
&root,
&registry_owner.registry,
registry_owner.registry,
)?,
animate,
fog,
@@ -6726,7 +6726,13 @@ pub fn run() -> Result<()> {
clouds: horizon_client::hud::decode(
&root.join("assets/minecraft/textures/environment/clouds.png"),
)
.map(|(w, h, px)| (w, h, px.chunks_exact(4).map(|p| p[3] > 0).collect()))
.map(|(w, h, px)| {
(
w,
h,
px.as_chunks::<4>().0.iter().map(|p| p[3] > 0).collect(),
)
})
.unwrap_or((1, 1, vec![false])),
mob_types: MobTypes::load(&root)?
.types
+13 -8
View File
@@ -81,7 +81,10 @@ impl Game<'_> {
if cursor > 10 {
context.push("...");
}
let start = input.floor_char_boundary(cursor.saturating_sub(10));
let start = (0..=cursor.saturating_sub(10))
.rev()
.find(|&i| input.is_char_boundary(i))
.unwrap_or(0);
context.push(&input[start..cursor]);
if cursor < input.len() {
context.push(
@@ -279,13 +282,12 @@ impl Game<'_> {
return None;
}
}
if let Some((lo, hi)) = s.level {
if t != Target::Player
if let Some((lo, hi)) = s.level
&& (t != Target::Player
|| lo.is_some_and(|l| level < l)
|| hi.is_some_and(|h| level > h)
{
return None;
}
|| hi.is_some_and(|h| level > h))
{
return None;
}
for (mode, neg) in &s.gamemodes {
let current = if creative { "creative" } else { "survival" };
@@ -504,7 +506,10 @@ impl Game<'_> {
&[mode_name],
));
} else {
self.system_message(Text::translate("gameMode.changed", &[mode_name.clone()]));
self.system_message(Text::translate(
"gameMode.changed",
std::slice::from_ref(&mode_name),
));
self.feedback(Text::translate(
"commands.gamemode.success.other",
&[Text::literal(PLAYER_NAME), mode_name],
+17 -15
View File
@@ -301,8 +301,8 @@ impl Game<'_> {
let w = self.mob_world_base(&[]);
spawning::placement_ok(kind.species, &w, x, y, z) && {
let mut r = self.world.random.clone();
let rules = spawning::spawn_rules_ok(kind.species, &w, &mut r, x, y, z);
rules
spawning::spawn_rules_ok(kind.species, &w, &mut r, x, y, z)
}
};
if ok {
@@ -571,7 +571,8 @@ impl Game<'_> {
self.spawn_item(d, pos, [0.0, 0.2, 0.0], 10);
}
}
for item in [&m.extra.main_hand] {
{
let item = &m.extra.main_hand;
// Equipment drop chance 8.5% (+ player kill only).
if let Some(item) = item
&& by_player
@@ -714,7 +715,7 @@ impl Game<'_> {
self.destroy_particles(pos, old);
if drop {
let drops = self.res.items.block_drops(
&self.res.assets.registry,
self.res.assets.registry,
old,
None,
&mut self.world.random,
@@ -1206,7 +1207,7 @@ impl Game<'_> {
let mut sound: Option<&str> = None;
let mut handled = true;
let mut drops: Vec<(String, u32)> = Vec::new();
let is_food = m.kind.food.iter().any(|f| *f == item);
let is_food = m.kind.food.contains(&item);
match species {
Species::Cow | Species::Mooshroom if item == "minecraft:bucket" && !m.is_baby() => {
give = Some("minecraft:milk_bucket");
@@ -1304,12 +1305,13 @@ impl Game<'_> {
self.audio
.play(&format!("minecraft:{s}"), Some(center), 1.0, pitch);
}
if consume && !creative {
if let Some(stack) = self.inventory[selected].as_mut() {
stack.count -= 1;
if stack.count == 0 {
self.inventory[selected] = None;
}
if consume
&& !creative
&& let Some(stack) = self.inventory[selected].as_mut()
{
stack.count -= 1;
if stack.count == 0 {
self.inventory[selected] = None;
}
}
if let Some(g) = give {
@@ -1459,9 +1461,9 @@ impl Game<'_> {
(mob.position.y + mob.eye_height()).floor() as i32,
mob.position.z.floor() as i32,
);
let mut packed = u32::from(light >> 4) * 16 | (u32::from(light & 15) * 16) << 8;
let mut packed = (u32::from(light >> 4) * 16) | ((u32::from(light & 15) * 16) << 8);
if mob.fire_ticks > 0 || matches!(mob.species(), Species::Blaze | Species::MagmaCube) {
packed = 15 * 16 | (15 * 16) << 8;
packed = (15 * 16) | ((15 * 16) << 8);
}
horizon_client::mobs::render::render(
mob,
@@ -1494,9 +1496,9 @@ impl Game<'_> {
a.position.y.floor() as i32,
a.position.z.floor() as i32,
);
let mut packed = u32::from(light >> 4) * 16 | (u32::from(light & 15) * 16) << 8;
let mut packed = (u32::from(light >> 4) * 16) | ((u32::from(light & 15) * 16) << 8);
if a.is_fireball() {
packed = 15 * 16 | (15 * 16) << 8;
packed = (15 * 16) | ((15 * 16) << 8);
}
if a.is_arrow() {
let Some(r) = atlas.sprites.get("entity/projectiles/arrow").copied() else {
+3 -3
View File
@@ -940,7 +940,7 @@ impl Game<'_> {
pub(super) fn end_geometry(&self, camera: glam::DVec3, out: &mut Vec<Vertex>) {
let atlas = &self.res.atlas;
if let Some(r) = atlas.sprites.get("entity/end_portal/end_portal").copied() {
let full = 15 * 16 | (15 * 16) << 8;
let full = (15 * 16) | ((15 * 16) << 8);
// Each block shows a quarter of the texture so neighbours join up.
let quarter = |a: i32, b: i32| {
let (fa, fb) = (a.rem_euclid(4) as f32 / 4.0, b.rem_euclid(4) as f32 / 4.0);
@@ -1106,7 +1106,7 @@ impl Game<'_> {
feet.y.floor() as i32,
feet.z.floor() as i32,
);
let packed = u32::from(light >> 4) * 16 | (u32::from(light & 15) * 16) << 8;
let packed = (u32::from(light >> 4) * 16) | ((u32::from(light & 15) * 16) << 8);
// poseStack.scale(2) then translate(0, -0.5, 0); outer_glass at y 24 px + bob.
let center = rel.as_vec3() + glam::Vec3::new(0.0, 2.0 * (24.0 / 16.0 - 0.5) + bob, 0.0);
let outer = spin * tilt;
@@ -1301,7 +1301,7 @@ impl Game<'_> {
pitch.cos(),
yaw.cos() * pitch.sin(),
) * 0.25;
let full = 15 * 16 | (15 * 16) << 8;
let full = (15 * 16) | ((15 * 16) << 8);
for eye in &self.end.eyes {
let p = eye.previous + (eye.position - eye.previous) * alpha - camera;
let c = p.as_vec3();
+2 -6
View File
@@ -156,11 +156,7 @@ fn mip_chain(pixels: &[u8], size: u32, layers: u32) -> (Vec<u8>, u32) {
}
let o = &mut next[(y * n + x) * 4..][..4];
for c in 0..3 {
o[c] = if weight > 0 {
(acc[c] / weight) as u8
} else {
0
};
o[c] = acc[c].checked_div(weight).unwrap_or(0) as u8;
}
o[3] = (acc[3] / 4) as u8;
}
@@ -965,7 +961,7 @@ impl Renderer {
// (section, entered face, directions travelled)
queue.push_back((from, None::<usize>, 0u8));
self.reachable.insert(from);
let sections = (crate::chunk::HEIGHT / 16) as i32;
let sections = crate::chunk::HEIGHT / 16;
while let Some((key, entered, travelled)) = queue.pop_front() {
let vis = self
.visibility
+4 -8
View File
@@ -366,10 +366,8 @@ fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
}
}
// Mob.aiStep: undead burn in daylight.
if m.kind.flags.burns_in_day && m.alive() && sun_burn_tick(m, w) {
if m.extra.head.is_none() {
m.fire_ticks = m.fire_ticks.max(160);
}
if m.kind.flags.burns_in_day && m.alive() && sun_burn_tick(m, w) && m.extra.head.is_none() {
m.fire_ticks = m.fire_ticks.max(160);
}
species_ai_step(m, w, events);
}
@@ -434,10 +432,8 @@ fn species_ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
}
match m.species() {
Species::Chicken => farm::chicken_ai_step(m, w, events),
Species::Sheep => {
if m.extra.anim_ticks > 0 {
m.extra.anim_ticks -= 1;
}
Species::Sheep if m.extra.anim_ticks > 0 => {
m.extra.anim_ticks -= 1;
}
_ => {}
}
+2 -2
View File
@@ -147,8 +147,8 @@ impl Mob {
v.z * f64::from(speed),
);
let (s, c) = (
f64::from(self.yaw.to_radians().sin() as f32),
f64::from(self.yaw.to_radians().cos() as f32),
f64::from(self.yaw.to_radians().sin()),
f64::from(self.yaw.to_radians().cos()),
);
self.velocity = Vec3::new(
self.velocity.x + (v.x * c - v.z * s),
+7 -5
View File
@@ -135,7 +135,7 @@ impl Mob {
return 3;
}
let mut sacrifice = (self.health - self.attrs.max_health * 0.33) as i32;
sacrifice -= (3 - 2) * 4;
sacrifice -= 4;
sacrifice.max(0) + 3
}
pub fn malus(&self, t: PathType) -> f32 {
@@ -449,13 +449,15 @@ impl Mob {
let zd = (self.position.z - (f64::from(n.z) + 0.5)).abs();
let max = f64::from(self.ai.nav.max_distance_to_waypoint);
let close = xd < max && zd < max && yd < vertical;
if close || Navigation::can_cut_corner(n.kind) && self.should_target_next_node(w, mob_pos) {
if let Some(p) = &mut self.ai.nav.path {
p.advance();
}
if (close || Navigation::can_cut_corner(n.kind) && self.should_target_next_node(w, mob_pos))
&& let Some(p) = &mut self.ai.nav.path
{
p.advance();
}
self.do_stuck_detection(w, mob_pos);
}
// Vanilla's NaN-sensitive `!(a < b)` form.
#[allow(clippy::neg_cmp_op_on_partial_ord)]
fn should_target_next_node(&self, w: &MobWorld, mob: Vec3) -> bool {
let Some(path) = &self.ai.nav.path else {
return false;
+7 -7
View File
@@ -96,7 +96,7 @@ impl MobWorld<'_> {
/// WalkNodeEvaluator.getPathTypeStatic.
pub fn path_type_static(&self, x: i32, y: i32, z: i32) -> PathType {
let t = self.path_type_from_state(x, y, z);
if t == PathType::Open && y >= MIN_Y + 1 {
if t == PathType::Open && y > MIN_Y {
match self.path_type_from_state(x, y - 1, z) {
PathType::Open | PathType::Water | PathType::Lava | PathType::Walkable => {
PathType::Open
@@ -345,7 +345,7 @@ impl<'a, 'w> Finder<'a, 'w> {
fn state(&self, x: i32, y: i32, z: i32) -> data::StateData {
self.w.data.state(self.w.world.block(x, y, z))
}
fn from_state(&self, x: i32, y: i32, z: i32) -> PathType {
fn type_from_state(&self, x: i32, y: i32, z: i32) -> PathType {
self.w.path_type_from_state(x, y, z)
}
fn fluid(&self, x: i32, y: i32, z: i32) -> Fluid {
@@ -389,7 +389,7 @@ impl<'a, 'w> Finder<'a, 'w> {
match self.eval {
Evaluator::Fly => self.fly_path_type(x, y, z),
Evaluator::Amphibious { .. } => {
let t = self.from_state(x, y, z);
let t = self.type_from_state(x, y, z);
if t == PathType::Water {
for (dx, dy, dz) in [
(0, -1, 0),
@@ -399,7 +399,7 @@ impl<'a, 'w> Finder<'a, 'w> {
(-1, 0, 0),
(1, 0, 0),
] {
if self.from_state(x + dx, y + dy, z + dz) == PathType::Blocked {
if self.type_from_state(x + dx, y + dy, z + dz) == PathType::Blocked {
return PathType::WaterBorder;
}
}
@@ -418,9 +418,9 @@ impl<'a, 'w> Finder<'a, 'w> {
self.w.check_neighbours(x, y, z, t)
}
fn fly_path_type(&self, x: i32, y: i32, z: i32) -> PathType {
let mut t = self.from_state(x, y, z);
if t == PathType::Open && y >= MIN_Y + 1 {
let below = self.from_state(x, y - 1, z);
let mut t = self.type_from_state(x, y, z);
if t == PathType::Open && y > MIN_Y {
let below = self.type_from_state(x, y - 1, z);
t = match below {
PathType::Fire | PathType::Lava => PathType::Fire,
PathType::Damaging => PathType::Damaging,
+1 -4
View File
@@ -49,10 +49,7 @@ pub fn register(m: &mut Mob) {
let mut hurt = HurtByTarget::new().alert();
hurt.alert_except = vec![S::ZombifiedPiglin];
t.add(1, hurt);
t.add(
2,
NearestTarget::player(false).when(|m, w| drowned_can_attack(m, w)),
);
t.add(2, NearestTarget::player(false).when(drowned_can_attack));
t.add(
3,
NearestTarget::species(&[S::Villager, S::WanderingTrader], false),
+1 -1
View File
@@ -58,7 +58,7 @@ impl MotionResources {
)?
.0
.tag;
let properties = MovementProperties::from_nbt(&data, &assets.registry)?;
let properties = MovementProperties::from_nbt(&data, assets.registry)?;
let bundle: BTreeMap<String, String> =
serde_json::from_slice(&fs::read(root.join("block-tags.json"))?)?;
let mut definitions = TagDefinitions::default();
+1 -3
View File
@@ -893,9 +893,7 @@ impl ParticleEngine {
* f64::from(scale)) as i32)
.max(1);
q.has_physics = physics;
if ty == T::WhiteSmoke {
q.set_color(0.729_411_8, 0.694_117_67, 0.760_784_3);
} else if ty == T::WhiteAsh {
if matches!(ty, T::WhiteSmoke | T::WhiteAsh) {
q.set_color(186.0 / 255.0, 177.0 / 255.0, 194.0 / 255.0);
}
q.size_curve = Size::GrowIn;
+2 -2
View File
@@ -97,7 +97,7 @@ impl TestTerrain {
};
chunk.set(x, y, z, b);
}
if h > 63 && hash(wx, wz) % 13 == 0 {
if h > 63 && hash(wx, wz).is_multiple_of(13) {
chunk.set(x, h + 1, z, self.short_grass);
}
}
@@ -107,7 +107,7 @@ impl TestTerrain {
for x in 2..14 {
let (wx, wz) = (cx * 16 + x, cz * 16 + z);
let h = Self::height(wx, wz);
if h <= 64 || hash(wx, wz) % 97 != 0 {
if h <= 64 || !hash(wx, wz).is_multiple_of(97) {
continue;
}
for y in h + 1..h + 6 {
+2 -2
View File
@@ -91,7 +91,7 @@ pub fn list_worlds(saves: &Path) -> Vec<WorldEntry> {
})
})
.collect();
worlds.sort_by(|a, b| b.modified.cmp(&a.modified));
worlds.sort_by_key(|w| std::cmp::Reverse(w.modified));
worlds
}
impl Title {
@@ -272,7 +272,7 @@ impl Title {
let title = "Create New World";
let tw = HudBatch::text_width(atlas, title);
batch.text(atlas, title, (w - tw) / 2.0, 8.0, u32::MAX, true);
let blink = (self.started.elapsed().as_millis() / 300) % 2 == 0;
let blink = (self.started.elapsed().as_millis() / 300).is_multiple_of(2);
for (i, (label, value)) in [
("World Name", name),
(
+3 -2
View File
@@ -727,8 +727,9 @@ impl EditBox {
let displayed: String = rest.chars().take(shown_len).collect();
let rel_cursor = self.cursor as isize - self.display as isize;
let on_screen = rel_cursor >= 0 && rel_cursor as usize <= shown_len;
let show_cursor =
self.focused && (self.focused_at.elapsed().as_millis() / 300) % 2 == 0 && on_screen;
let show_cursor = self.focused
&& (self.focused_at.elapsed().as_millis() / 300).is_multiple_of(2)
&& on_screen;
let styled = |from: usize, to: usize| -> Text {
match format {
Some(t) => t.slice(self.display + from, self.display + to),
+3
View File
@@ -29,3 +29,6 @@ path = "src/bin/density_parity.rs"
[[bin]]
name = "horizon-float-log-parity"
path = "src/bin/float_log_parity.rs"
[lints]
workspace = true
+3
View File
@@ -10,3 +10,6 @@ description = "Horizon's Minecraft Java Edition 26.3 network protocol (version 7
horizon-world = { path = "../horizon-world" }
flate2 = { version = "1.1.10", default-features = false, features = ["rust_backend"] }
serde_json = "1.0.151"
[lints]
workspace = true
+3
View File
@@ -21,3 +21,6 @@ path = "src/main.rs"
[[bin]]
name = "horizon-worldgen-parity"
path = "src/bin/worldgen_parity.rs"
[lints]
workspace = true
@@ -275,7 +275,7 @@ fn main() -> Result<(), Error> {
}
println!("decoration order sensitivity (raster vs reverse): {total} blocks differ");
let mut sorted: Vec<_> = pairs.into_iter().collect();
sorted.sort_by(|a, b| b.1.cmp(&a.1));
sorted.sort_by_key(|p| std::cmp::Reverse(p.1));
for ((v, r), n) in sorted.iter().take(limit) {
println!("{n:>9} {v} <-> {r}");
}
@@ -406,7 +406,7 @@ fn main() -> Result<(), Error> {
differ as f64 * 100.0 / compared.max(1) as f64
);
let mut sorted: Vec<_> = pairs.into_iter().collect();
sorted.sort_by(|a, b| b.1.cmp(&a.1));
sorted.sort_by_key(|p| std::cmp::Reverse(p.1));
for ((v, r), n) in sorted.iter().take(limit) {
println!("{n:>9} vanilla {v} -> rust {r}");
}
@@ -425,7 +425,7 @@ fn main() -> Result<(), Error> {
})
.filter(|(n, _)| *n > 0)
.collect();
net.sort_by(|a, b| b.0.cmp(&a.0));
net.sort_by_key(|p| std::cmp::Reverse(p.0));
println!("one-sided differences:");
for (n, (v, r)) in net.iter().take(limit) {
println!("{n:>9} vanilla {v} -> rust {r}");
@@ -433,7 +433,7 @@ fn main() -> Result<(), Error> {
let clean = per_chunk.iter().filter(|(_, n)| *n == 0).count();
println!("chunks identical: {clean}/{}", per_chunk.len());
let mut worst = per_chunk.clone();
worst.sort_by(|a, b| b.1.cmp(&a.1));
worst.sort_by_key(|p| std::cmp::Reverse(p.1));
for ((x, z), n) in worst.iter().take(8).filter(|(_, n)| *n > 0) {
println!(" chunk {x} {z}: {n}");
}
@@ -604,6 +604,8 @@ impl<R: RandomSource> Placer<'_, R> {
let start_dir = direction;
loop {
let (dx, dz) = step(dir);
let (cx, cz) = step(counter_clockwise(dir));
let inner_corner = is_house(grid, gx + dx + cx, gy + dz + cz);
if !is_house(grid, gx + dx, gy + dz) {
data.position = rel(data.position, data.rotation, Direction::South, -1);
self.add("wall_corner", data.position, data.rotation, Mirror::None);
@@ -614,10 +616,7 @@ impl<R: RandomSource> Placer<'_, R> {
if gx != end_x || gy != end_y || start_dir != dir {
self.wall_piece(data);
}
} else if {
let (cx, cz) = step(counter_clockwise(dir));
is_house(grid, gx + dx + cx, gy + dz + cz)
} {
} else if inner_corner {
data.position = rel(data.position, data.rotation, Direction::South, 6);
data.position = rel(data.position, data.rotation, Direction::East, 8);
data.rotation = data.rotation.get_rotated(Rotation::Counterclockwise90);
@@ -233,7 +233,7 @@ impl Builder {
Some(piece)
}
/// StrongholdPieces.generatePieceFromSmallDoor.
fn from_small_door(
fn piece_from_small_door(
&mut self,
r: &mut impl RandomSource,
foot: [i32; 3],
@@ -312,7 +312,7 @@ impl Builder {
if (foot[0] - start.min[0]).abs() > 112 || (foot[2] - start.min[2]).abs() > 112 {
return;
}
if let Some(piece) = self.from_small_door(r, foot, d, depth + 1) {
if let Some(piece) = self.piece_from_small_door(r, foot, d, depth + 1) {
self.pieces.push(piece);
self.pending.push(self.pieces.len() - 1);
}
+3
View File
@@ -8,3 +8,6 @@ rust-version.workspace = true
[[bin]]
name = "voxel-bench"
path = "src/main.rs"
[lints]
workspace = true