Give the fire charge's use sound its own pitch
Placing fire with a fire charge played item.firecharge.use at the flint and steel's pitch (nextFloat * 0.4 + 0.8, one draw). FireChargeItem.playSound uses (nextFloat - nextFloat) * 0.2 + 1.0, two draws from the level random. The pitch is now horizon_client::items::fire_starter_pitch, checked against the real FireChargeItem.playSound by tools/test_fire_starter_sound_parity.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#![forbid(unsafe_code)]
|
||||
//! Runs tools/test_fire_starter_sound_parity.py's level random seeds through
|
||||
//! the fire charge's use sound (`horizon_client::items::fire_starter_pitch`).
|
||||
use horizon_client::{
|
||||
Result,
|
||||
items::{fire_starter_pitch, fire_starter_sound},
|
||||
};
|
||||
use horizon_core::random::{LegacyRandom, RandomSource};
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{BufRead, BufReader, BufWriter, Write},
|
||||
};
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
let input = BufReader::new(File::open(&args[1])?);
|
||||
let mut out = BufWriter::new(File::create(&args[2])?);
|
||||
for line in input.lines() {
|
||||
let mut random = LegacyRandom::new(line?.trim().parse()?);
|
||||
let pitch = fire_starter_pitch(true, &mut random);
|
||||
writeln!(
|
||||
out,
|
||||
"{} {} {} {}",
|
||||
fire_starter_sound(true),
|
||||
1.0f32.to_bits() as i32,
|
||||
pitch.to_bits() as i32,
|
||||
random.next_long()
|
||||
)?;
|
||||
}
|
||||
out.flush()?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -6267,17 +6267,12 @@ impl Game<'_> {
|
||||
if !self.try_light_portal(target)? {
|
||||
self.set_state_named(target, "minecraft:fire", &[])?;
|
||||
}
|
||||
let sound = if item == "fire_charge" {
|
||||
"minecraft:item.firecharge.use"
|
||||
} else {
|
||||
"minecraft:item.flintandsteel.use"
|
||||
};
|
||||
self.audio.play(
|
||||
sound,
|
||||
Some(at(target)),
|
||||
1.0,
|
||||
self.world.random.next_float() * 0.4 + 0.8,
|
||||
let sound = horizon_client::items::fire_starter_sound(item == "fire_charge");
|
||||
let pitch = horizon_client::items::fire_starter_pitch(
|
||||
item == "fire_charge",
|
||||
&mut self.world.random,
|
||||
);
|
||||
self.audio.play(sound, Some(at(target)), 1.0, pitch);
|
||||
if item == "fire_charge" {
|
||||
self.consume_held();
|
||||
} else {
|
||||
|
||||
@@ -12,6 +12,27 @@ use std::{
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
/// A fire starter's use sound: `SoundEvents.FIRECHARGE_USE` or
|
||||
/// `FLINTANDSTEEL_USE`.
|
||||
pub fn fire_starter_sound(fire_charge: bool) -> &'static str {
|
||||
if fire_charge {
|
||||
"minecraft:item.firecharge.use"
|
||||
} else {
|
||||
"minecraft:item.flintandsteel.use"
|
||||
}
|
||||
}
|
||||
|
||||
/// The pitch of a fire starter's use sound, from the level's random:
|
||||
/// `FlintAndSteelItem.useOn`'s `nextFloat() * 0.4 + 0.8`, or
|
||||
/// `FireChargeItem.playSound`'s `(nextFloat() - nextFloat()) * 0.2 + 1.0`.
|
||||
pub fn fire_starter_pitch(fire_charge: bool, random: &mut impl RandomSource) -> f32 {
|
||||
if fire_charge {
|
||||
(random.next_float() - random.next_float()) * 0.2 + 1.0
|
||||
} else {
|
||||
random.next_float() * 0.4 + 0.8
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ToolRule {
|
||||
pub blocks: Vec<String>,
|
||||
|
||||
Reference in New Issue
Block a user