From 8c0ed0e591d7abe2d5a971ad8e6929c37283666b Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 19:33:24 +0100 Subject: [PATCH] Let a comparator read an item frame through a block A comparator behind a solid block now reads the item frame on its far side (rotation + 1, or 0 when empty), and updates when the frame's item or rotation changes. --- crates/horizon-client/src/game.rs | 17 +++++++++++++++++ crates/horizon-client/src/game/frames.rs | 14 ++++++++++++++ crates/horizon-world/src/level/mod.rs | 6 ++++++ crates/horizon-world/src/level/redstone.rs | 10 ++++++++-- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 58b89a140..083c9c85e 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -545,6 +545,8 @@ struct GameLevel<'w> { player_collision: Option, /// Minecart boxes (detector rails). cart_boxes: Vec<([f64; 3], [f64; 3])>, + /// The item frames a comparator reads through a conductor. + item_frames: &'w [horizon_client::entities::ItemFrame], /// The other entities that keep blocks from being placed into them. blockers: Blockers<'w>, biomes: &'w Biomes, @@ -706,6 +708,20 @@ impl LevelAccess for GameLevel<'_> { } machines::container_signal(self.world, self.behaviours, self.items, self.registry, pos) } + fn item_frame_analog_output(&self, pos: BlockPos, facing: Direction) -> Option { + let mut frames = self + .item_frames + .iter() + .filter(|f| f.pos == [pos.x, pos.y, pos.z] && f.facing == facing as u8); + let frame = frames.next().filter(|_| frames.next().is_none())?; + // ItemFrame.getAnalogOutput. + Some( + frame + .item + .as_ref() + .map_or(0, |_| i32::from(frame.rotation % 8) + 1), + ) + } fn block_entity_signal( &self, pos: BlockPos, @@ -2541,6 +2557,7 @@ impl Game<'_> { }; let mut level = GameLevel { cart_boxes, + item_frames: &self.item_frames, blockers, world: &mut self.world, facts: self.res.facts(), diff --git a/crates/horizon-client/src/game/frames.rs b/crates/horizon-client/src/game/frames.rs index d08c5f283..9e18b2cb3 100644 --- a/crates/horizon-client/src/game/frames.rs +++ b/crates/horizon-client/src/game/frames.rs @@ -7,6 +7,7 @@ use horizon_assets::{bake::bake_model, model::CuboidModel, resolve::ModelLibrary use horizon_client::{entities::ItemFrame, items::ItemStack, mesher::Vertex}; use horizon_core::{ geometry::{Aabb, Vec3}, + position::BlockPos, random::RandomSource, }; use std::sync::Arc; @@ -223,6 +224,7 @@ impl Game<'_> { } let p = self.item_frames[i].pos; self.world.modified.insert((p[0] >> 4, p[2] >> 4)); + self.frame_output_changed(p); self.swing_arm(); true } @@ -255,8 +257,17 @@ impl Game<'_> { } self.drop_frame_items(&f, with_frame, true); self.world.modified.insert((f.pos[0] >> 4, f.pos[2] >> 4)); + if f.item.is_some() { + self.frame_output_changed(f.pos); + } true } + /// `ItemFrame.setItem` / `setRotation`: `updateNeighbourForOutputSignal`, so + /// the comparators reading the frame take its new signal. + fn frame_output_changed(&mut self, pos: [i32; 3]) { + let at = BlockPos::new(pos[0], pos[1], pos[2]); + self.with_level(|b, level, ticks| b.update_neighbour_for_output_signal(level, ticks, at)); + } /// `ItemFrame.dropItem`: the frame (when breaking) and the held item. fn drop_frame_items(&mut self, f: &ItemFrame, with_frame: bool, by_player: bool) { if !self.ui.rules.bool("entity_drops") || (by_player && self.creative) { @@ -300,6 +311,9 @@ impl Game<'_> { self.audio .play(&sound(&f, "break"), Some(center(&f)), 1.0, 1.0); self.drop_frame_items(&f, true, false); + if f.item.is_some() { + self.frame_output_changed(f.pos); + } continue; } } diff --git a/crates/horizon-world/src/level/mod.rs b/crates/horizon-world/src/level/mod.rs index c81bdf369..f06771a06 100644 --- a/crates/horizon-world/src/level/mod.rs +++ b/crates/horizon-world/src/level/mod.rs @@ -372,6 +372,12 @@ pub trait LevelAccess { ) -> i32 { 0 } + /// `ItemFrame.getAnalogOutput` of the one item frame in the block at + /// `pos` that faces `facing` (`ComparatorBlock.getItemFrame`), or None when + /// there is not exactly one. + fn item_frame_analog_output(&self, _pos: BlockPos, _facing: Direction) -> Option { + None + } /// `ContainerOpenersCounter.recheckOpenCount` for the chest or ender chest /// block entity at `pos`: recounts its openers and returns the previous /// and new counts (the caller plays open/close effects when they change), diff --git a/crates/horizon-world/src/level/redstone.rs b/crates/horizon-world/src/level/redstone.rs index 92f9059e5..bebf5d826 100644 --- a/crates/horizon-world/src/level/redstone.rs +++ b/crates/horizon-world/src/level/redstone.rs @@ -490,8 +490,14 @@ impl Sim<'_, L> { } else if result < 15 && self.is_redstone_conductor(target_state, target) { let further = rel(target, facing); let further_state = self.state(further); - if b.has_flag(further_state, state_flags::ANALOG_OUTPUT) { - result = self.analog_output(further_state, further, facing.opposite()); + let block = b + .has_flag(further_state, state_flags::ANALOG_OUTPUT) + .then(|| self.analog_output(further_state, further, facing.opposite())); + // ComparatorBlock.getInputSignal: an item frame behind the + // conductor counts too, the larger signal winning. + let frame = self.level.item_frame_analog_output(further, facing); + if let Some(signal) = frame.into_iter().chain(block).max() { + result = signal; } } }