Fire bee_nest_destroyed with the bees left inside

Vanilla's BeehiveBlock.playerDestroy fires BEE_NEST_DESTROYED after emptying the hive, with the tool and the bees still inside; a silk touch break keeps them in.
This commit is contained in:
Kacpherek
2026-10-27 22:07:25 +01:00
parent 3c72bf2d79
commit 079963f27e
2 changed files with 40 additions and 5 deletions
+8 -5
View File
@@ -4016,11 +4016,14 @@ impl Game<'_> {
self.pop_resource(pos, d);
}
}
// BeehiveBlock.playerDestroy: silk touch keeps the bees in.
if let Some((hive, (honey, facing))) = hive
&& !silk
{
self.hive_broken_by_player(pos, hive, honey, facing);
// BeehiveBlock.playerDestroy: silk touch keeps the bees in, so
// the trigger counts them; otherwise they are out already.
if let Some((hive, (honey, facing))) = hive {
let bees = if silk { hive.bees.len() as i64 } else { 0 };
if !silk {
self.hive_broken_by_player(pos, hive, honey, facing);
}
self.trigger_bee_nest_destroyed(broken, held.as_ref(), bees);
}
// InfestedBlock.spawnAfterBreak: its silverfish comes out unless the
// tool has silk touch (#prevents_infested_spawns) or blocks don't drop.
@@ -1079,6 +1079,38 @@ impl Game<'_> {
&& c["count"].as_u64().is_none_or(|n| stabbed as u64 >= n)
});
}
/// `BeeNestDestroyedTrigger`: the nest's block state, the tool that broke
/// it and the bees left inside.
pub(super) fn trigger_bee_nest_destroyed(
&mut self,
state: horizon_world::registry::BlockStateId,
tool: Option<&ItemStack>,
bees: i64,
) {
let Some(definition) = self.pack.assets.registry.state(state).cloned() else {
return;
};
let me = self.player_entity();
let tool = tool.map(item_view).unwrap_or_default();
self.trigger("minecraft:bee_nest_destroyed", move |c, w| {
let pctx = adv::Entities {
this: Some(&me),
origin: me.position,
tool: None,
block_pos: None,
};
let state_ok = c["state"]
.as_object()
.into_iter()
.flatten()
.all(|(k, v)| definition.properties.get(k).map(String::as_str) == v.as_str());
adv::id_matches(&c["blocks"], "block", &definition.name, w)
&& state_ok
&& adv::item(&c["item"], &tool, w)
&& adv::range_i(&c["num_bees_inside"], bees)
&& adv::conditions(&c["player"], &pctx, w)
});
}
/// A trigger with only the player condition (slept_in_bed, started_riding).
pub(super) fn trigger_player(&mut self, name: &str) {
let me = self.player_entity();