Cats sit on a chest only while nobody has it open, and on a bed's foot only

This commit is contained in:
Kacpherek
2026-10-26 19:43:27 +01:00
parent 7f8a6680a8
commit 752138e866
4 changed files with 11 additions and 2 deletions
@@ -1069,6 +1069,8 @@ pub fn main() -> horizon_client::Result<()> {
for (i, m) in mobs.iter().enumerate() {
print(&mut out, 0, i, m, s.creative, world.game_time);
}
// No player has a chest open in the scenarios.
let lid_openers = std::collections::HashMap::new();
// The MobWorld every step sees, over a snapshot of the mobs.
macro_rules! mob_world {
($snapshot:expr) => {
@@ -1103,6 +1105,7 @@ pub fn main() -> horizon_client::Result<()> {
// FlatLevelSource.getSeaLevel.
sea_level: -63,
items: Some(&items),
lid_openers: &lid_openers,
}
};
}
@@ -422,6 +422,7 @@ impl Game<'_> {
sea_level: if self.dim == Dim::Nether { 32 } else { 63 },
teams: std::sync::Arc::new(self.mob_teams()),
items: Some(self.res.items()),
lid_openers: &self.lid_openers,
difficulty: self.local_difficulty(
self.player
.as_ref()
+2
View File
@@ -1529,6 +1529,8 @@ pub struct MobWorld<'a> {
pub teams: std::sync::Arc<Teams<'a>>,
/// Item data (max stack sizes), when the host has it.
pub items: Option<&'a crate::items::Items>,
/// `ChestBlockEntity.getOpenCount`: the players with each chest open.
pub lid_openers: &'a HashMap<(i32, i32, i32), i32>,
}
/// `Entity.getTeam` of the player and of the mobs on a team.
#[derive(Clone, Debug, Default)]
+5 -2
View File
@@ -835,7 +835,7 @@ impl Goal for CatLieOnBlock {
m.extra.flag = self.0.reached;
}
}
/// `CatSitOnBlockGoal`: chests, lit furnaces and beds.
/// `CatSitOnBlockGoal`: unopened chests, lit furnaces and the foot of beds.
#[derive(Clone, Debug)]
struct CatSitOnBlock(super::goals::MoveToBlock);
fn can_sit_on(w: &MobWorld, p: [i32; 3]) -> bool {
@@ -846,7 +846,10 @@ fn can_sit_on(w: &MobWorld, p: [i32; 3]) -> bool {
match f.name.as_ref() {
// The lit state is the only light source a furnace has.
"minecraft:furnace" => f.emission > 0,
_ => true,
// `ChestBlockEntity.getOpenCount(level, pos) < 1`.
"minecraft:chest" => !w.lid_openers.contains_key(&(p[0], p[1], p[2])),
// A bed's foot only (`BedBlock.PART != HEAD`).
_ => w.prop(p[0], p[1], p[2], "part") != Some("head"),
}
}
impl Goal for CatSitOnBlock {