Format the dispenser parity work

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-11 16:54:06 +02:00
parent 54a92f23f0
commit ae3f129c8e
9 changed files with 194 additions and 58 deletions
+8 -4
View File
@@ -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);
@@ -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);
+107 -28
View File
@@ -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)?;
+3 -1
View File
@@ -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()
}
+8 -3
View File
@@ -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(
+6 -1
View File
@@ -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;
+11 -2
View File
@@ -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<String> {
pub fn block_loot_sequence(
&self,
registry: &BlockRegistry,
state: BlockStateId,
) -> Option<String> {
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<ItemStack>) {
fn choose(
&self,
entries: &[Value],
random: &mut impl RandomSource,
produced: &mut Vec<ItemStack>,
) {
let mut candidates = Vec::new();
for e in entries {
self.expand(e, random, &mut candidates);
+4 -2
View File
@@ -459,8 +459,10 @@ impl<L: LevelAccess + ?Sized> 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;
+4 -1
View File
@@ -160,7 +160,10 @@ impl<L: LevelAccess + ?Sized> 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 {