Merge pull request #738 from ludovic111/perf/hopper-scan-five-slots

🤖 Agent: merged by Ludovic's AI agent: perf-server-5. Before/after in the PR body; agent parity 87/87 stacked; orchestrator combined check with the perf-ticks-5 stack on current main: clippy clean, client+protocol tests pass (one flaky world-delete test, #749), dedicated_server/lan/chunk_stage/block_entity_storage PASS.
This commit is contained in:
Ludovic Marie
2026-10-17 22:47:27 +02:00
committed by GitHub
2 changed files with 12 additions and 7 deletions
+5 -2
View File
@@ -45,6 +45,9 @@ pub struct Furnace {
pub cooking_total: i32,
pub speed: f32,
}
/// A hopper's slots: the only plain container with five.
pub const HOPPER_SLOTS: usize = 5;
#[derive(Clone, Debug)]
pub enum BlockEntity {
Chest(Vec<Option<ItemStack>>),
@@ -242,7 +245,7 @@ impl BlockEntity {
let size = match name {
"minecraft:chest" | "minecraft:trapped_chest" | "minecraft:barrel" => 27,
n if n.ends_with("copper_chest") => 27,
"minecraft:hopper" => 5,
"minecraft:hopper" => HOPPER_SLOTS,
"minecraft:dispenser" | "minecraft:dropper" => 9,
n if n.ends_with("shulker_box") => 27,
_ => return None,
@@ -270,7 +273,7 @@ impl BlockEntity {
pub fn id(&self) -> &'static str {
match self {
Self::Chest(items) => match items.len() {
5 => "minecraft:hopper",
HOPPER_SLOTS => "minecraft:hopper",
9 => "minecraft:dispenser",
_ => "minecraft:chest",
},
+7 -5
View File
@@ -7,7 +7,7 @@ use super::Game;
mod crafter;
use horizon_client::{
Result,
containers::BlockEntity,
containers::{BlockEntity, HOPPER_SLOTS},
items::{ItemStack, Items},
world::World,
};
@@ -506,14 +506,16 @@ impl Game<'_> {
.default_state("minecraft:hopper")
.map(|s| self.res.facts.get(s).name.clone());
let Some(hopper) = hopper else { return Ok(()) };
// A hopper's block entity is a plain container (`Chest`): only those
// need their block looked up (the ticker runs for a HopperBlockEntity
// whose block is still a hopper, `BlockEntityType.isValid`).
// A hopper's block entity is the plain container with five slots
// (`BlockEntity::for_block`; `BlockEntity::id` names it the hopper):
// only those need their block looked up (the ticker runs for a
// HopperBlockEntity whose block is still a hopper,
// `BlockEntityType.isValid`).
let mut positions: Vec<Pos> = self
.world
.block_entities
.iter()
.filter(|(_, e)| matches!(e, BlockEntity::Chest(_)))
.filter(|(_, e)| matches!(e, BlockEntity::Chest(items) if items.len() == HOPPER_SLOTS))
.map(|(p, _)| *p)
.filter(|p| self.res.facts.get(self.world.block(p.0, p.1, p.2)).name == hopper)
.collect();