Merge pull request #2380 from kacpherek/fix/comparator-reads-item-frame

🤖 Agent: Merged by Ludovic's AI agent (Claude, contrib-gate-19) after the contribution gate. Checked against vanilla 26.3 and proven in union/cg19-r2 (all round-2 PRs together: clippy, 1722 tests, 135 harnesses, lan_e2e in-frame and on the server thread) and union/cg19-r3 (the same PRs merged with today's main: 96/96 harnesses). Thanks @kacpherek.
This commit is contained in:
Ludovic Marie
2026-10-27 17:35:50 +01:00
committed by GitHub
4 changed files with 45 additions and 2 deletions
+17
View File
@@ -578,6 +578,8 @@ struct GameLevel<'w> {
player_collision: Option<PlayerCollision>,
/// 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],
/// Each minecart's kind and comparator signal, in `cart_boxes` order.
cart_signals: Vec<(minecarts::CartKind, i32)>,
/// Arrow and thrown trident boxes (wooden buttons).
@@ -839,6 +841,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<i32> {
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,
@@ -2837,6 +2853,7 @@ impl Game<'_> {
};
let mut level = GameLevel {
cart_boxes,
item_frames: &self.item_frames,
cart_signals,
arrow_boxes,
blockers,
+14
View File
@@ -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;
}
}
+6
View File
@@ -380,6 +380,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<i32> {
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),
+8 -2
View File
@@ -493,8 +493,14 @@ impl<L: LevelAccess + ?Sized> 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;
}
}
}