Loot: suspicious stew keeps the effect set_stew_effect rolled

The function drew an effect and a duration but dropped them. The stack
now carries the effect and it is stored in suspicious_stew_effects.
This commit is contained in:
Kacpherek
2026-10-26 14:31:03 +01:00
parent b78daab11c
commit 8bfa7a5b7b
5 changed files with 30 additions and 1 deletions
@@ -23,6 +23,7 @@ fn stack(spec: &str) -> LootStack {
map: false,
exploration: None,
ominous_amplifier: None,
stew_effects: Vec::new(),
};
for e in parts {
let (name, level) = e.rsplit_once(':').unwrap_or((e, "1"));
@@ -3297,6 +3297,7 @@ fn to_loot(stack: &ItemStack) -> horizon_world::loot::LootStack {
map: false,
exploration: None,
ominous_amplifier: None,
stew_effects: Vec::new(),
}
}
/// A generated loot stack as a Horizon item stack.
+1
View File
@@ -304,6 +304,7 @@ fn loot_stack(item: &str, count: i32) -> LootStack {
map: false,
exploration: None,
ominous_amplifier: None,
stew_effects: Vec::new(),
}
}
/// `Mob.dropChances.byEquipment(slot)`: the recorded chance, or the one the
@@ -63,6 +63,12 @@ pub fn loot_item_with_components(s: &horizon_world::loot::LootStack) -> ItemStac
if let Some(level) = s.ominous_amplifier.filter(|l| *l > 0) {
item.data_mut().ominous_amplifier = Some(level.clamp(0, 4) as u8);
}
// set_stew_effect's `suspicious_stew_effects`.
for (effect, duration) in &s.stew_effects {
item.data_mut()
.stew_effects
.push((Arc::from(effect.as_str()), *duration));
}
item
}
@@ -243,6 +249,7 @@ mod tests {
map: false,
exploration: None,
ominous_amplifier: None,
stew_effects: Vec::new(),
};
// An End city chest's enchant_with_levels roll.
let boots = loot_item_with_components(&stack(
@@ -286,6 +293,7 @@ mod tests {
"zoom": 1
})))),
ominous_amplifier: None,
stew_effects: Vec::new(),
};
let mut item = loot_item(&stack);
assert!(has_pending_map(&item));
+19 -1
View File
@@ -31,6 +31,9 @@ pub struct LootStack {
pub exploration: Option<Box<ExplorationMap>>,
/// Set by set_ominous_bottle_amplifier.
pub ominous_amplifier: Option<i32>,
/// Added by set_stew_effect (the `suspicious_stew_effects` component):
/// (effect id, duration in ticks).
pub stew_effects: Vec<(String, i32)>,
}
/// `ExplorationMapFunction`'s settings.
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -74,6 +77,7 @@ impl LootStack {
map: false,
exploration: None,
ominous_amplifier: None,
stew_effects: Vec::new(),
}
}
pub fn is_empty(&self) -> bool {
@@ -678,6 +682,13 @@ impl LootData {
}
}
/// `MobEffect.isInstantaneous`.
fn is_instantaneous(effect: &str) -> bool {
matches!(
effect,
"minecraft:saturation" | "minecraft:instant_health" | "minecraft:instant_damage"
)
}
/// The level of one enchantment on a stack (its `enchantments` component).
fn item_level(stack: &LootStack, enchantment: &str) -> i32 {
stack
@@ -1134,7 +1145,14 @@ impl<R: RandomSource> Context<'_, R> {
.random
.next_int_bound(effects.len() as i32)
.unwrap_or(0) as usize;
self.int(&effects[pick]["duration"]);
let effect = effects[pick]["type"].as_str().unwrap_or("");
let mut duration = self.int(&effects[pick]["duration"]);
// Seconds, unless the effect is instantaneous.
if !is_instantaneous(effect) {
duration *= 20;
}
// SuspiciousStewEffects.withEffectAdded
stack.stew_effects.push((effect.to_owned(), duration));
}
}
"minecraft:set_ominous_bottle_amplifier" => {