diff --git a/crates/horizon-client/src/containers.rs b/crates/horizon-client/src/containers.rs index 9cdac1463..6a135799c 100644 --- a/crates/horizon-client/src/containers.rs +++ b/crates/horizon-client/src/containers.rs @@ -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>), @@ -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", }, diff --git a/crates/horizon-client/src/game/machines.rs b/crates/horizon-client/src/game/machines.rs index 6947041f2..a736be2db 100644 --- a/crates/horizon-client/src/game/machines.rs +++ b/crates/horizon-client/src/game/machines.rs @@ -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 = 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();