Tidy clippy findings in the station modules
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -152,7 +152,10 @@ pub fn potion_color(id: Option<&str>) -> u32 {
|
||||
b += w * (e.color & 255);
|
||||
total += w;
|
||||
}
|
||||
if total == 0 { BASE_POTION_COLOR } else { (r / total) << 16 | (g / total) << 8 | b / total }
|
||||
match (r.checked_div(total), g.checked_div(total), b.checked_div(total)) {
|
||||
(Some(r), Some(g), Some(b)) => (r << 16) | (g << 8) | b,
|
||||
_ => BASE_POTION_COLOR,
|
||||
}
|
||||
}
|
||||
/// `MobEffectUtil.formatDuration` at 20 TPS: m:ss or h:mm:ss.
|
||||
pub fn format_duration(ticks: i32) -> String {
|
||||
|
||||
@@ -523,7 +523,9 @@ pub fn apply_value_effect(effect: &Value, level: u32, random: &mut LegacyRandom,
|
||||
"minecraft:remove_binomial" => {
|
||||
let p = level_value(&effect["chance"], level);
|
||||
let n = value;
|
||||
let removed = if !(n <= 128.0) && !(n * p < 20.0) && !(n * (1.0 - p) < 20.0) {
|
||||
// Normal approximation for large counts (written as vanilla's negated tests).
|
||||
let large = n > 128.0 && n * p >= 20.0 && n * (1.0 - p) >= 20.0;
|
||||
let removed = if large {
|
||||
let miu = (f64::from(n) * f64::from(p)).floor();
|
||||
let sigma = (f64::from(n) * f64::from(p) * f64::from(1.0 - p)).sqrt();
|
||||
((miu + random.next_gaussian() * sigma).round() as i32).clamp(0, n as i32)
|
||||
|
||||
@@ -103,7 +103,7 @@ impl Game<'_> {
|
||||
let remaining = 32u32.saturating_sub(ticks);
|
||||
let eye = self.eye_position().unwrap_or_default();
|
||||
// Consumable.emitParticlesAndSounds: the drink sound every 4 ticks near the end.
|
||||
if remaining <= 25 && remaining % 4 == 0 {
|
||||
if remaining <= 25 && remaining.is_multiple_of(4) {
|
||||
let pitch = self.world.random.next_float() * 0.1 + 0.9;
|
||||
self.audio.play("minecraft:entity.generic.drink", Some(eye), 0.5, pitch);
|
||||
}
|
||||
@@ -269,7 +269,7 @@ impl Game<'_> {
|
||||
self.apply_effect_action(a);
|
||||
}
|
||||
} else {
|
||||
let d = (intensity * f64::from(*duration) * f64::from(scale) + 0.5) as i32;
|
||||
let d = (intensity * f64::from(*duration) * scale + 0.5) as i32;
|
||||
if d > 20
|
||||
&& let Some(e) = brewing::effect(id)
|
||||
{
|
||||
|
||||
@@ -890,15 +890,14 @@ impl Game<'_> {
|
||||
let count = names.next_int_bound(2).unwrap_or(0) + 3;
|
||||
let words: Vec<&str> = (0..count).map(|_| WORDS[names.next_int_bound(WORDS.len() as i32).unwrap_or(0) as usize]).collect();
|
||||
let message = words.join(" ");
|
||||
let col: i32;
|
||||
let disabled = (gold < i as i32 + 1 || level < cost) && !self.creative;
|
||||
if disabled {
|
||||
let col: i32 = if disabled {
|
||||
batch.sprite_scaled(atlas, "gui/sprites/container/enchanting_table/enchantment_slot_disabled", ox + bx, oy + by, bw, bh, u32::MAX);
|
||||
batch.sprite(atlas, &format!("gui/sprites/container/enchanting_table/level_{}_disabled", i + 1), ox + bx + 1.0, oy + by + 1.0);
|
||||
let c = ((-9937334i32) & 16711422) >> 1;
|
||||
let msg_color = argb(c | 0xFF00_0000u32 as i32);
|
||||
self.galactic_deferred(batch, &message, ox + bx + 20.0, oy + by + 2.0, text_width, msg_color);
|
||||
col = -12550384;
|
||||
-12550384
|
||||
} else {
|
||||
let hover = inside(local, bx, by, bw, bh);
|
||||
let sprite = if hover { "enchantment_slot_highlighted" } else { "enchantment_slot" };
|
||||
@@ -906,8 +905,8 @@ impl Game<'_> {
|
||||
batch.sprite(atlas, &format!("gui/sprites/container/enchanting_table/level_{}", i + 1), ox + bx + 1.0, oy + by + 1.0);
|
||||
let msg_color = if hover { -128 } else { -9937334 };
|
||||
self.galactic_deferred(batch, &message, ox + bx + 20.0, oy + by + 2.0, text_width, argb(msg_color));
|
||||
col = -8323296;
|
||||
}
|
||||
-8323296
|
||||
};
|
||||
let atlas = &self.res.atlas;
|
||||
let cw = HudBatch::text_width(atlas, &cost_text);
|
||||
batch.text(atlas, &cost_text, ox + bx + 20.0 + 86.0 - cw, oy + by + 9.0, argb(col), true);
|
||||
@@ -942,7 +941,7 @@ impl Game<'_> {
|
||||
batch.sprite(atlas, "gui/sprites/container/anvil/error", ox + 99.0, oy + 45.0);
|
||||
}
|
||||
if s.inputs[0].is_some() {
|
||||
let blink = if (self.ticks / 6) % 2 == 0 { "_" } else { "" };
|
||||
let blink = if (self.ticks / 6).is_multiple_of(2) { "_" } else { "" };
|
||||
batch.text(atlas, &format!("{}{blink}", s.name), ox + 62.0, oy + 24.0, u32::MAX, true);
|
||||
}
|
||||
let cost = s.anvil.cost;
|
||||
|
||||
@@ -286,10 +286,10 @@ pub fn offer_from<R: RandomSource>(ctx: &TradeContext<'_>, t: &Value, random: &m
|
||||
result = stack;
|
||||
additional += extra;
|
||||
}
|
||||
if let Some(Value::String(tag)) = t.get("double_trade_price_enchantments") {
|
||||
if result.stored_enchantments().iter().any(|(e, _)| ctx.enchantments.in_tag(tag, e)) {
|
||||
additional *= 2;
|
||||
}
|
||||
if let Some(Value::String(tag)) = t.get("double_trade_price_enchantments")
|
||||
&& result.stored_enchantments().iter().any(|(e, _)| ctx.enchantments.in_tag(tag, e))
|
||||
{
|
||||
additional *= 2;
|
||||
}
|
||||
let a = cost(ctx.items, &t["wants"], additional);
|
||||
if a.stack.count < 1 {
|
||||
|
||||
@@ -507,7 +507,7 @@ mod tests {
|
||||
let a = enchant_offers(&e, &items, 1234, 15, Some(&s));
|
||||
let b = enchant_offers(&e, &items, 1234, 15, Some(&s));
|
||||
assert_eq!(a, b);
|
||||
assert!(a.costs[2] >= 30 && a.costs[2] <= 30, "{a:?}");
|
||||
assert_eq!(a.costs[2], 30, "{a:?}");
|
||||
assert!(a.costs[0] >= 1 && a.costs[0] <= a.costs[2]);
|
||||
// The clue is the first offer's random pick from the same list.
|
||||
for slot in 0..3 {
|
||||
|
||||
Reference in New Issue
Block a user