From ae3f129c8eded1b0efb7bef2f3f303064d050f54 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 11 Oct 2026 16:54:06 +0200 Subject: [PATCH] Format the dispenser parity work Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/boats.rs | 12 +- .../src/game/dispense_fixture.rs | 59 +++++--- crates/horizon-client/src/game/dispenser.rs | 135 ++++++++++++++---- crates/horizon-client/src/game/golems.rs | 4 +- crates/horizon-client/src/game/persist.rs | 11 +- crates/horizon-client/src/game/sculk.rs | 7 +- crates/horizon-client/src/items.rs | 13 +- crates/horizon-world/src/level/hooks.rs | 6 +- crates/horizon-world/src/level/portal.rs | 5 +- 9 files changed, 194 insertions(+), 58 deletions(-) diff --git a/crates/horizon-client/src/game/boats.rs b/crates/horizon-client/src/game/boats.rs index a1d0458bf..fbac6ab14 100644 --- a/crates/horizon-client/src/game/boats.rs +++ b/crates/horizon-client/src/game/boats.rs @@ -175,7 +175,10 @@ impl BoatModels { } } } - Self { models, chest_models } + Self { + models, + chest_models, + } } } impl Game<'_> { @@ -639,9 +642,10 @@ impl Game<'_> { if self.boats[i].chest && (sneaking || self.riding.is_some()) { let b = &self.boats[i]; let key = (i32::MAX - 15, super::minecarts::CART_KEY_Y, b.id as i32); - self.world - .block_entities - .insert(key, horizon_client::containers::BlockEntity::Chest(b.items.clone())); + self.world.block_entities.insert( + key, + horizon_client::containers::BlockEntity::Chest(b.items.clone()), + ); self.container = Some(key); self.screen = super::Screen::Inventory; self.capture(false); diff --git a/crates/horizon-client/src/game/dispense_fixture.rs b/crates/horizon-client/src/game/dispense_fixture.rs index 7ad14cb07..a906ba259 100644 --- a/crates/horizon-client/src/game/dispense_fixture.rs +++ b/crates/horizon-client/src/game/dispense_fixture.rs @@ -65,11 +65,12 @@ enum Target { Stand(u32), } - impl Game<'_> { /// Run every case of `spec` ("CASES,OUTPUT") and write the results. pub(super) fn dispense_fixture(&mut self, spec: &str) -> Result<()> { - let (input, output) = spec.split_once(',').ok_or("HORIZON_DISPENSE_FIXTURE=CASES,OUTPUT")?; + let (input, output) = spec + .split_once(',') + .ok_or("HORIZON_DISPENSE_FIXTURE=CASES,OUTPUT")?; // Saplings and feature placers grow from the live feature registry. self.install_live_features(); let text = std::fs::read_to_string(input)?; @@ -98,8 +99,10 @@ impl Game<'_> { for cz in -2..=2 { let mut chunk = Chunk::empty(cx, cz); for section in &mut chunk.sections { - Arc::make_mut(section).biomes = - horizon_core::paletted::PalettedContainer::new(horizon_client::chunk::BIOME_STRATEGY, plains); + Arc::make_mut(section).biomes = horizon_core::paletted::PalettedContainer::new( + horizon_client::chunk::BIOME_STRATEGY, + plains, + ); } self.world.chunks.insert((cx, cz), Arc::new(chunk)); } @@ -133,7 +136,10 @@ impl Game<'_> { // The oracle level answers one sky and one block light everywhere. let light = case["light"].as_array(); let level = |i: usize, default: i64| { - light.and_then(|l| l.get(i)).and_then(Value::as_i64).unwrap_or(default) as u8 + light + .and_then(|l| l.get(i)) + .and_then(Value::as_i64) + .unwrap_or(default) as u8 }; let packed = (level(0, 15) << 4) | level(1, 0); for chunk in self.world.chunks.values_mut() { @@ -187,7 +193,12 @@ impl Game<'_> { targets.push(self.fixture_target(e)?); } // Leashable.setLeashedTo: a lead from a target to an earlier one. - for (e, t) in case["entities"].as_array().into_iter().flatten().zip(&targets) { + for (e, t) in case["entities"] + .as_array() + .into_iter() + .flatten() + .zip(&targets) + { let (Some(holder), Target::Mob(id)) = (e["leash"].as_u64(), t) else { continue; }; @@ -294,16 +305,13 @@ impl Game<'_> { let flag = |name: &str| e[name].as_bool().unwrap_or(false); let ageable = !matches!( s, - Species::Zombie - | Species::Skeleton - | Species::Bogged - | Species::SnowGolem + Species::Zombie | Species::Skeleton | Species::Bogged | Species::SnowGolem ); if flag("baby") && ageable { mob.extra.age = -24000; } - let tamable = body_in_head(s) - || matches!(s, Species::Cat | Species::Parrot | Species::Ocelot); + let tamable = + body_in_head(s) || matches!(s, Species::Cat | Species::Parrot | Species::Ocelot); if flag("tame") && tamable { mob.extra.tame = true; } @@ -393,7 +401,12 @@ impl Game<'_> { if let Some(r) = ready { line.push_str(if r { " ready" } else { " unready" }); } - if x.chested && matches!(s, Species::Donkey | Species::Mule | Species::Llama | Species::TraderLlama) { + if x.chested + && matches!( + s, + Species::Donkey | Species::Mule | Species::Llama | Species::TraderLlama + ) + { line.push_str(" chest"); } if x.leash.is_some() { @@ -426,9 +439,18 @@ impl Game<'_> { let (p, v) = (m.position, m.velocity); out.push(line(&m.kind.id, [p.x, p.y, p.z], [v.x, v.y, v.z], "")); } - for s in self.armor_stands.iter().filter(|s| !old_stands.contains(&s.id)) { + for s in self + .armor_stands + .iter() + .filter(|s| !old_stands.contains(&s.id)) + { let (p, v) = (s.position, s.velocity); - out.push(line("minecraft:armor_stand", [p.x, p.y, p.z], [v.x, v.y, v.z], "")); + out.push(line( + "minecraft:armor_stand", + [p.x, p.y, p.z], + [v.x, v.y, v.z], + "", + )); } for d in &self.dropped { let (p, v) = (d.position, d.velocity); @@ -459,7 +481,12 @@ impl Game<'_> { out.push(line(kind, [p.x, p.y, p.z], [v.x, v.y, v.z], "")); } for (p, v) in self.rockets.iter().map(|r| r.motion()) { - out.push(line("minecraft:firework_rocket", [p.x, p.y, p.z], [v.x, v.y, v.z], "")); + out.push(line( + "minecraft:firework_rocket", + [p.x, p.y, p.z], + [v.x, v.y, v.z], + "", + )); } for t in &self.tnts { let (p, v) = (t.position, t.velocity); diff --git a/crates/horizon-client/src/game/dispenser.rs b/crates/horizon-client/src/game/dispenser.rs index b943956e0..f6a7e5a58 100644 --- a/crates/horizon-client/src/game/dispenser.rs +++ b/crates/horizon-client/src/game/dispenser.rs @@ -129,7 +129,8 @@ pub(super) fn entity_random() -> LegacyRandom { let mut current = UNIQUIFIER.load(Ordering::Relaxed); let seed = loop { let next = current.wrapping_mul(STEP); - match UNIQUIFIER.compare_exchange_weak(current, next, Ordering::Relaxed, Ordering::Relaxed) { + match UNIQUIFIER.compare_exchange_weak(current, next, Ordering::Relaxed, Ordering::Relaxed) + { Ok(_) => break next, Err(actual) => current = actual, } @@ -603,7 +604,9 @@ impl Game<'_> { "minecraft:honeycomb" => self.dispense_honeycomb(pos, facing, stack)?, "minecraft:potion" => self.dispense_potion(pos, facing, stack)?, _ if item.ends_with("shulker_box") => self.dispense_shulker_box(pos, facing, stack)?, - _ if super::boats::any_boat_wood(&item).is_some() => self.dispense_boat(pos, facing, stack), + _ if super::boats::any_boat_wood(&item).is_some() => { + self.dispense_boat(pos, facing, stack) + } _ if super::minecarts::CartKind::from_id(&item).is_some() => { self.dispense_minecart(pos, facing, stack) } @@ -686,7 +689,9 @@ impl Game<'_> { /// top of the block (`setPos(x + 0.5, y + 1, z + 0.5)`) falls one block /// against the collision shapes overlapping that block alone. fn drop_offset(&self, width: f64, height: f64, p: Pos) -> f64 { - use horizon_world::{block_collision_scan::BlockCollisionScan, collision_context::CollisionContext}; + use horizon_world::{ + block_collision_scan::BlockCollisionScan, collision_context::CollisionContext, + }; let h = width / 2.0; let (x, z) = (f64::from(p.0) + 0.5, f64::from(p.2) + 0.5); let y = f64::from(p.1) + 1.0; @@ -696,7 +701,11 @@ impl Game<'_> { ); let cell = Aabb::new( Vec3::new(f64::from(p.0), f64::from(p.1), f64::from(p.2)), - Vec3::new(f64::from(p.0) + 1.0, f64::from(p.1) + 1.0, f64::from(p.2) + 1.0), + Vec3::new( + f64::from(p.0) + 1.0, + f64::from(p.1) + 1.0, + f64::from(p.2) + 1.0, + ), ); let mut scene = SceneCollisions { world: &self.world, @@ -704,9 +713,17 @@ impl Game<'_> { }; let mut amount = -1.0; // Level.getCollisions(null, aabb): CollisionContext.empty(). - if let Ok(scan) = BlockCollisionScan::new(&mut scene, CollisionContext::empty(false), cell, false, 1_000_000) { + if let Ok(scan) = BlockCollisionScan::new( + &mut scene, + CollisionContext::empty(false), + cell, + false, + 1_000_000, + ) { for hit in scan.flatten() { - amount = hit.shape.collide(horizon_core::geometry::Axis::Y, entity, amount); + amount = hit + .shape + .collide(horizon_core::geometry::Axis::Y, entity, amount); } } 1.0 + amount @@ -762,9 +779,9 @@ impl Game<'_> { // LivingEntity.canEquipWithDispenser: alive, the slot usable, the // item's allowed entities, the slot empty and the dispenser rule. let target = self.targets_at(front).into_iter().find(|t| match *t { - Target::Player => slot.armor_index().is_some_and(|i| { - allows("minecraft:player") && self.armor[i].is_none() - }), + Target::Player => slot + .armor_index() + .is_some_and(|i| allows("minecraft:player") && self.armor[i].is_none()), Target::Stand(i) => slot.stand_index().is_some_and(|s| { allows("minecraft:armor_stand") && self.armor_stands[i].equipment[s].is_none() }), @@ -802,7 +819,11 @@ impl Game<'_> { mob_set_slot(m, slot, one); // setGuaranteedDrop / setPersistenceRequired. m.persistent = true; - let sound = if m.silent { None } else { equip_sound(m, slot, sound) }; + let sound = if m.silent { + None + } else { + equip_sound(m, slot, sound) + }; (Some(m.position), sound) } }; @@ -1010,7 +1031,10 @@ impl Game<'_> { return (shrink(stack), CLICK); } } - (self.default_execute(pos, facing, stack), optional_event("chest")) + ( + self.default_execute(pos, facing, stack), + optional_event("chest"), + ) } /// `BoatDispenseItemBehavior`. fn dispense_boat(&mut self, pos: Pos, facing: Direction, stack: ItemStack) -> Dispensed { @@ -1183,7 +1207,12 @@ impl Game<'_> { if let Some(id) = self.spawn_mob_at(kind, target, true) { self.mob_placed(id)?; } - self.post_block_game_event("minecraft:entity_place", [target.0, target.1, target.2], None, None); + self.post_block_game_event( + "minecraft:entity_place", + [target.0, target.1, target.2], + None, + None, + ); } let bucket = ItemStack::new("minecraft:bucket", 1); Ok(( @@ -1203,7 +1232,12 @@ impl Game<'_> { self.process_level_events()?; match picked { Some(filled) => { - self.post_block_game_event("minecraft:fluid_pickup", [target.x, target.y, target.z], None, None); + self.post_block_game_event( + "minecraft:fluid_pickup", + [target.x, target.y, target.z], + None, + None, + ); let filled = ItemStack::new(filled, 1); Ok(( self.consume_with_remainder(pos, facing, stack, filled), @@ -1253,15 +1287,28 @@ impl Game<'_> { } return Ok((self.hurt_and_break(stack, 1), CLICK)); } - if self.with_level(|b, level, ticks| b.fire_can_be_placed_at(level, ticks, target_pos, facing)) { - let fire = self.with_level(|b, level, ticks| b.fire_state_for(level, ticks, target_pos)); + if self + .with_level(|b, level, ticks| b.fire_can_be_placed_at(level, ticks, target_pos, facing)) + { + let fire = + self.with_level(|b, level, ticks| b.fire_state_for(level, ticks, target_pos)); self.level_set([target.0, target.1, target.2], fire)?; - self.post_block_game_event("minecraft:block_place", [target.0, target.1, target.2], None, None); + self.post_block_game_event( + "minecraft:block_place", + [target.0, target.1, target.2], + None, + None, + ); } else if self.can_light(state, &name) { if let Some(lit) = self.with_props(state, &[("lit", "true")]) { self.level_set([target.0, target.1, target.2], lit)?; } - self.post_block_game_event("minecraft:block_change", [target.0, target.1, target.2], None, None); + self.post_block_game_event( + "minecraft:block_change", + [target.0, target.1, target.2], + None, + None, + ); } else if &*name == "minecraft:tnt" { if self.ui.rules.bool("tnt_explodes") { self.spawn_primed_tnt(target_pos, false); @@ -1282,8 +1329,11 @@ impl Game<'_> { let lit = self.prop(state, "lit"); let waterlogged = self.prop(state, "waterlogged"); let dry_unlit = lit.as_deref() == Some("false") && waterlogged.as_deref() == Some("false"); - ((self.in_block_tag("minecraft:campfires", name) || self.in_block_tag("minecraft:candles", name)) && dry_unlit) - || (self.in_block_tag("minecraft:candle_cakes", name) && lit.as_deref() == Some("false")) + ((self.in_block_tag("minecraft:campfires", name) + || self.in_block_tag("minecraft:candles", name)) + && dry_unlit) + || (self.in_block_tag("minecraft:candle_cakes", name) + && lit.as_deref() == Some("false")) } fn dispense_bone_meal( &mut self, @@ -1336,7 +1386,12 @@ impl Game<'_> { 1.0, 1.0, ); - self.post_block_game_event("minecraft:entity_place", [front.0, front.1, front.2], None, None); + self.post_block_game_event( + "minecraft:entity_place", + [front.0, front.1, front.2], + None, + None, + ); (shrink(stack), CLICK) } @@ -1377,7 +1432,12 @@ impl Game<'_> { if let Some(entity) = BlockEntity::for_block("minecraft:wither_skeleton_skull") { self.world.block_entities.insert(target, entity); } - self.post_block_game_event("minecraft:block_place", [target.0, target.1, target.2], None, None); + self.post_block_game_event( + "minecraft:block_place", + [target.0, target.1, target.2], + None, + None, + ); self.check_wither_spawn([target.0, target.1, target.2])?; return Ok((shrink(stack), CLICK)); } @@ -1436,7 +1496,9 @@ impl Game<'_> { // setBlock; the spot is air again by the time setBlock // would update neighbours, so it skips them. let at = Self::pos_of(target); - self.with_level(|b, level, ticks| b.set_block(level, ticks, at, pumpkin, 2 | 16)); + self.with_level(|b, level, ticks| { + b.set_block(level, ticks, at, pumpkin, 2 | 16) + }); self.process_level_events()?; self.check_golem_spawn(head)?; } else { @@ -1609,7 +1671,11 @@ impl Game<'_> { // BeehiveBlock.dropHoneycomb (harvest/beehive), then // releaseBeesAndResetHoneyLevel and the shear event. let p = [target.0, target.1, target.2]; - for stack in self.sequence_loot("minecraft:harvest/beehive", "minecraft:harvest/beehive", None) { + for stack in self.sequence_loot( + "minecraft:harvest/beehive", + "minecraft:harvest/beehive", + None, + ) { self.pop_resource(p, stack); } if let Some(reset) = self.with_props(state, &[("honey_level", "0")]) { @@ -1714,7 +1780,8 @@ impl Game<'_> { .play("minecraft:entity.sulfur_cube.eject", sound_at, 1.0, 1.0); } Species::Sheep if !m.extra.sheared && !m.is_baby() => { - let color = horizon_client::mobs::render::DYE_NAMES[m.extra.color as usize & 15]; + let color = + horizon_client::mobs::render::DYE_NAMES[m.extra.color as usize & 15]; self.audio .play("minecraft:entity.sheep.shear", sound_at, 1.0, 1.0); let drops = self.sequence_loot( @@ -1799,7 +1866,12 @@ impl Game<'_> { } _ => continue, } - self.post_block_game_event("minecraft:shear", [target.0, target.1, target.2], None, None); + self.post_block_game_event( + "minecraft:shear", + [target.0, target.1, target.2], + None, + None, + ); return Ok(true); } Ok(false) @@ -1816,7 +1888,9 @@ impl Game<'_> { (Holder::Mob(m.id), b.center(), Some(i)) } Target::Player => { - let Some(v) = self.player_view() else { return false }; + let Some(v) = self.player_view() else { + return false; + }; (Holder::Player, v.bounds.center(), None) } Target::Stand(_) => return false, @@ -1826,7 +1900,9 @@ impl Game<'_> { .mobs .iter() .enumerate() - .filter(|(_, m)| !m.removed && m.extra.leash == Some(holder) && overlaps(m.bounds(), area)) + .filter(|(_, m)| { + !m.removed && m.extra.leash == Some(holder) && overlaps(m.bounds(), area) + }) .map(|(j, m)| (m.id, j)) .collect(); leashed.sort_unstable(); @@ -1963,7 +2039,10 @@ impl Game<'_> { let Some(waxed) = waxed.filter(|_| name.contains("copper") || name.contains("lightning_rod")) else { - return Ok((self.default_execute(pos, facing, stack), optional_event("honeycomb"))); + return Ok(( + self.default_execute(pos, facing, stack), + optional_event("honeycomb"), + )); }; set_success("honeycomb", true); self.level_set([target.0, target.1, target.2], waxed)?; diff --git a/crates/horizon-client/src/game/golems.rs b/crates/horizon-client/src/game/golems.rs index d048d3d5c..a67e05af8 100644 --- a/crates/horizon-client/src/game/golems.rs +++ b/crates/horizon-client/src/game/golems.rs @@ -118,7 +118,9 @@ impl Game<'_> { let air = self.world.air; for &p in cells { let pos = horizon_core::position::BlockPos::new(p[0], p[1], p[2]); - self.with_level(|b, level, ticks| b.update_neighbors_at(level, ticks, pos, b.block(air))); + self.with_level(|b, level, ticks| { + b.update_neighbors_at(level, ticks, pos, b.block(air)) + }); } self.process_level_events() } diff --git a/crates/horizon-client/src/game/persist.rs b/crates/horizon-client/src/game/persist.rs index 957ede43a..de2ff8573 100644 --- a/crates/horizon-client/src/game/persist.rs +++ b/crates/horizon-client/src/game/persist.rs @@ -204,9 +204,14 @@ impl Game<'_> { if let Some((position, velocity, yaw)) = entity_nbt::boat_from_nbt(&tag) { self.next_entity += 1; let id = self.next_entity; - let (wood, chest) = super::boats::any_boat_wood(k).unwrap_or(("oak", false)); - let mut b = - super::boats::Boat::new(id, std::sync::Arc::from(wood), position, yaw); + let (wood, chest) = + super::boats::any_boat_wood(k).unwrap_or(("oak", false)); + let mut b = super::boats::Boat::new( + id, + std::sync::Arc::from(wood), + position, + yaw, + ); if chest { b = b.with_chest(); b.items = horizon_client::save::decode_items( diff --git a/crates/horizon-client/src/game/sculk.rs b/crates/horizon-client/src/game/sculk.rs index 65245eaab..61ff84bd9 100644 --- a/crates/horizon-client/src/game/sculk.rs +++ b/crates/horizon-client/src/game/sculk.rs @@ -438,7 +438,12 @@ impl Game<'_> { /// `Level.gameEvent`: tell the listeners within reach. pub(super) fn post_game_event(&mut self, event: &'static str, pos: [f64; 3], ctx: Context) { super::dispense_fixture::record(|| { - format!("G {},{},{} {event}", pos[0].floor() as i32, pos[1].floor() as i32, pos[2].floor() as i32) + format!( + "G {},{},{} {event}", + pos[0].floor() as i32, + pos[1].floor() as i32, + pos[2].floor() as i32 + ) }); if self.remote.is_some() || !self.sculk.tables.built { return; diff --git a/crates/horizon-client/src/items.rs b/crates/horizon-client/src/items.rs index 4912b5408..bfecad8ad 100644 --- a/crates/horizon-client/src/items.rs +++ b/crates/horizon-client/src/items.rs @@ -527,7 +527,11 @@ impl Items { self.loot.contains_key(id) } /// The server random sequence the block's loot table draws from. - pub fn block_loot_sequence(&self, registry: &BlockRegistry, state: BlockStateId) -> Option { + pub fn block_loot_sequence( + &self, + registry: &BlockRegistry, + state: BlockStateId, + ) -> Option { let block = registry.state(state)?; let name = block.name.trim_start_matches("minecraft:"); let standing = name.replacen("_wall_", "_", 1); @@ -913,7 +917,12 @@ impl LootContext<'_> { _ => false, } } - fn choose(&self, entries: &[Value], random: &mut impl RandomSource, produced: &mut Vec) { + fn choose( + &self, + entries: &[Value], + random: &mut impl RandomSource, + produced: &mut Vec, + ) { let mut candidates = Vec::new(); for e in entries { self.expand(e, random, &mut candidates); diff --git a/crates/horizon-world/src/level/hooks.rs b/crates/horizon-world/src/level/hooks.rs index 66114eee4..ee1e3cdd9 100644 --- a/crates/horizon-world/src/level/hooks.rs +++ b/crates/horizon-world/src/level/hooks.rs @@ -459,8 +459,10 @@ impl Sim<'_, L> { if same { return; } - if matches!(self.level.dimension(), super::Dimension::Overworld | super::Dimension::Nether) - && let Some(shape) = self.find_empty_portal_shape(pos, true) + if matches!( + self.level.dimension(), + super::Dimension::Overworld | super::Dimension::Nether + ) && let Some(shape) = self.find_empty_portal_shape(pos, true) { self.create_portal_blocks(&shape); return; diff --git a/crates/horizon-world/src/level/portal.rs b/crates/horizon-world/src/level/portal.rs index 403cd49c6..b59dd477c 100644 --- a/crates/horizon-world/src/level/portal.rs +++ b/crates/horizon-world/src/level/portal.rs @@ -160,7 +160,10 @@ impl Sim<'_, L> { return true; } // isPortal - if !matches!(self.level.dimension(), super::Dimension::Overworld | super::Dimension::Nether) { + if !matches!( + self.level.dimension(), + super::Dimension::Overworld | super::Dimension::Nether + ) { return false; } for face in Direction::ALL {