Fire the brewed_potion trigger when a potion is taken from a brewing stand
This commit is contained in:
@@ -6176,6 +6176,7 @@ impl Game<'_> {
|
||||
self.player_menu_sound(sound);
|
||||
}
|
||||
let crafted = std::mem::take(&mut menu.crafted);
|
||||
let brewed = std::mem::take(&mut menu.brewed);
|
||||
let equipped = std::mem::take(&mut menu.equipped);
|
||||
for (i, stack) in after.into_iter().enumerate() {
|
||||
if let Some(g) = game_of[i] {
|
||||
@@ -6191,6 +6192,9 @@ impl Game<'_> {
|
||||
self.player_drop(stack);
|
||||
}
|
||||
self.award_crafted(&crafted);
|
||||
for stack in &brewed {
|
||||
self.trigger_brewed_potion(stack);
|
||||
}
|
||||
if furnace_before > furnace_after
|
||||
&& self.remote.is_none()
|
||||
&& let (Some(pos), Some(p)) = (self.container, self.player.as_ref())
|
||||
|
||||
@@ -708,6 +708,25 @@ impl Game<'_> {
|
||||
let it = item_view(stack);
|
||||
self.trigger(name, |c, w| adv::item_entity(c, &me, target, &it, w));
|
||||
}
|
||||
/// `BrewedPotionTrigger`: the potion contents of a stack taken from a
|
||||
/// brewing stand.
|
||||
pub(super) fn trigger_brewed_potion(&mut self, stack: &ItemStack) {
|
||||
let me = self.player_entity();
|
||||
let potion = stack.potion().map(str::to_owned);
|
||||
self.trigger("minecraft:brewed_potion", move |c, w| {
|
||||
let pctx = adv::Entities {
|
||||
this: Some(&me),
|
||||
origin: me.position,
|
||||
tool: None,
|
||||
block_pos: None,
|
||||
};
|
||||
adv::conditions(&c["player"], &pctx, w)
|
||||
&& (c["potion"].is_null()
|
||||
|| potion
|
||||
.as_deref()
|
||||
.is_some_and(|p| adv::id_matches(&c["potion"], "potion", p, w)))
|
||||
});
|
||||
}
|
||||
/// `EnterBlockTrigger`: the block, its state properties and the player.
|
||||
pub(super) fn trigger_enter_block(&mut self, state: horizon_world::registry::BlockStateId) {
|
||||
let Some(definition) = self.pack.assets.registry.state(state).cloned() else {
|
||||
|
||||
@@ -127,9 +127,18 @@ impl Game<'_> {
|
||||
}
|
||||
let dropped = std::mem::take(&mut menu.dropped);
|
||||
let equipped = std::mem::take(&mut menu.equipped);
|
||||
let brewed = std::mem::take(&mut menu.brewed);
|
||||
menu.drops.clear();
|
||||
menu.crafted.clear();
|
||||
store_player(menu, &mut host.hub.guests[gi]);
|
||||
if !brewed.is_empty() {
|
||||
let conn = host.hub.guests[gi].conn;
|
||||
self.as_guest(host, conn, |g| {
|
||||
for stack in &brewed {
|
||||
g.trigger_brewed_potion(stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
if !equipped.is_empty() {
|
||||
let conn = host.hub.guests[gi].conn;
|
||||
self.as_guest(host, conn, |g| {
|
||||
|
||||
@@ -288,6 +288,9 @@ pub struct Menu {
|
||||
pub player_sounds: Vec<&'static str>,
|
||||
/// Recipes whose result was taken (`awardUsedRecipes`), for the caller.
|
||||
pub crafted: Vec<String>,
|
||||
/// Potions taken from a brewing stand's bottle slots
|
||||
/// (`PotionSlot.onTake`), for the caller.
|
||||
pub brewed: Vec<ItemStack>,
|
||||
/// `LivingEntity.onEquipItem` calls that change the item: the
|
||||
/// `EquipmentSlot` name and the new stack, in order, for the caller.
|
||||
pub equipped: Vec<(&'static str, Option<ItemStack>)>,
|
||||
@@ -683,6 +686,7 @@ impl Menu {
|
||||
sounds: Vec::new(),
|
||||
player_sounds: Vec::new(),
|
||||
crafted: Vec::new(),
|
||||
brewed: Vec::new(),
|
||||
equipped: Vec::new(),
|
||||
merchant: None,
|
||||
stone: Stonecutter::default(),
|
||||
@@ -1504,7 +1508,17 @@ impl Menu {
|
||||
}
|
||||
|
||||
/// `ResultSlot.onTake` and the other `Slot.onTake` overrides.
|
||||
fn on_take(&mut self, env: &Env, s: usize) {
|
||||
fn on_take(&mut self, env: &Env, s: usize, taken: &ItemStack) {
|
||||
if self.slots[s].role == Role::Potion {
|
||||
// BrewingStandMenu.PotionSlot.onTake: a stack with potion contents.
|
||||
if matches!(
|
||||
&*taken.item,
|
||||
"minecraft:potion" | "minecraft:splash_potion" | "minecraft:lingering_potion"
|
||||
) {
|
||||
self.brewed.push(taken.clone());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if self.slots[s].role == Role::MerchantResult {
|
||||
self.merchant_take(env);
|
||||
return;
|
||||
@@ -1671,7 +1685,7 @@ impl Menu {
|
||||
max_amount: u32,
|
||||
) -> Option<ItemStack> {
|
||||
let mut result = self.try_remove(env, s, amount, max_amount)?;
|
||||
self.on_take(env, s);
|
||||
self.on_take(env, s, &result);
|
||||
if self.slots[s].role == Role::CartoResult {
|
||||
Self::map_crafted(env, &mut result);
|
||||
}
|
||||
@@ -2346,7 +2360,7 @@ impl Menu {
|
||||
return None;
|
||||
}
|
||||
if after_take || matches!(self.kind, Kind::Inventory | Kind::Crafting) {
|
||||
self.on_take(env, index);
|
||||
self.on_take(env, index, &clicked);
|
||||
}
|
||||
// What the result slot's move left over is dropped.
|
||||
if (index == 0 && matches!(self.kind, Kind::Inventory | Kind::Crafting))
|
||||
@@ -2594,7 +2608,7 @@ impl Menu {
|
||||
};
|
||||
if let Some(mut taken) = self.try_remove(env, s, amount, u32::MAX) {
|
||||
self.carried = Some(taken.clone());
|
||||
self.on_take(env, s);
|
||||
self.on_take(env, s, &taken);
|
||||
if self.slots[s].role == Role::CartoResult {
|
||||
// onTake's onCraftedBy edits the carried stack.
|
||||
Self::map_crafted(env, &mut taken);
|
||||
@@ -2628,7 +2642,7 @@ impl Menu {
|
||||
if let Some(c) = self.carried.as_mut() {
|
||||
c.count += taken.count;
|
||||
}
|
||||
self.on_take(env, s);
|
||||
self.on_take(env, s, &taken);
|
||||
if self.slots[s].role == Role::CartoResult {
|
||||
// onCraftedBy edits the taken stack, not the carried one.
|
||||
Self::map_crafted(env, &mut taken);
|
||||
@@ -2656,7 +2670,7 @@ impl Menu {
|
||||
if self.may_pickup(env, target) {
|
||||
self.containers[PLAYER][inv_slot] = Some(taken.clone());
|
||||
self.set_by_player(env, target, None);
|
||||
self.on_take(env, target);
|
||||
self.on_take(env, target, &taken);
|
||||
if self.slots[target].role == Role::CartoResult
|
||||
&& let Some(stack) = self.containers[PLAYER][inv_slot].as_mut()
|
||||
{
|
||||
@@ -2684,14 +2698,14 @@ impl Menu {
|
||||
let part = split(&mut source, max);
|
||||
self.containers[PLAYER][inv_slot] = Some(source);
|
||||
self.set_by_player(env, target, Some(part));
|
||||
self.on_take(env, target);
|
||||
self.on_take(env, target, &taken);
|
||||
if !self.inventory_add(env, &mut taken) {
|
||||
self.drop_stack(&taken);
|
||||
}
|
||||
} else {
|
||||
self.containers[PLAYER][inv_slot] = Some(taken);
|
||||
self.containers[PLAYER][inv_slot] = Some(taken.clone());
|
||||
self.set_by_player(env, target, Some(source));
|
||||
self.on_take(env, target);
|
||||
self.on_take(env, target, &taken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user