Hoppers: look up the block only under five-slot containers

tick_hoppers read the block under every plain container block entity
each tick (chests, barrels, shulker boxes, dispensers, droppers) to find
the hoppers. A hopper's block entity is the only five-slot one
(BlockEntity::for_block, and BlockEntity::id already names it the
hopper), so only those are looked up now; a position still needs a
hopper block to tick.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-17 18:35:42 +02:00
parent 7bbbf6e97f
commit 2f82becb9c
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();