improve step sound

This commit is contained in:
LabyStudio
2022-02-13 08:19:49 +01:00
parent b7b3439f0d
commit a7482c52f1
3 changed files with 25 additions and 6 deletions
+21 -3
View File
@@ -211,7 +211,14 @@ window.Minecraft = class {
let soundName = block.getSound().getBreakSound();
// Play sound
this.soundManager.playSound(soundName, hitResult.x + 0.5, hitResult.y + 0.5, hitResult.z + 0.5, 1.0);
this.soundManager.playSound(
soundName,
hitResult.x + 0.5,
hitResult.y + 0.5,
hitResult.z + 0.5,
1.0,
1.0
);
// Destroy block
this.world.setBlockAt(hitResult.x, hitResult.y, hitResult.z, 0);
@@ -241,7 +248,11 @@ window.Minecraft = class {
// Don't place blocks if the player is standing there
if (!placedBoundingBox.intersects(this.player.boundingBox)) {
let typeId = this.inventory.getItemInSelectedSlot();
if (typeId !== 0) {
// Get previous block
let prevTypeId = this.world.getBlockAt(x, y, z);
if (typeId !== 0 && prevTypeId !== typeId) {
// Place block
this.world.setBlockAt(x, y, z, typeId);
@@ -252,7 +263,14 @@ window.Minecraft = class {
// Play sound
let sound = block.getSound();
let soundName = sound.getStepSound();
this.soundManager.playSound(soundName, hitResult.x + 0.5, hitResult.y + 0.5, hitResult.z + 0.5, sound.getPitch() * 0.8);
this.soundManager.playSound(
soundName,
hitResult.x + 0.5,
hitResult.y + 0.5,
hitResult.z + 0.5,
1.0,
sound.getPitch() * 0.8
);
}
}
}
+1 -1
View File
@@ -296,7 +296,7 @@ window.Player = class {
// Play sound
if (!block.isLiquid()) {
this.minecraft.soundManager.playSound(sound.getStepSound(), this.x, this.y, this.z, sound.getPitch());
this.minecraft.soundManager.playSound(sound.getStepSound(), this.x, this.y, this.z, 0.15, sound.getPitch());
}
}
}
@@ -58,7 +58,7 @@ window.SoundManager = class {
return sound;
}
playSound(name, x, y, z, pitch) {
playSound(name, x, y, z, volume, pitch) {
let pool = this.soundPool[name];
if (typeof pool === "undefined") {
@@ -76,7 +76,8 @@ window.SoundManager = class {
// Update position
sound.position.set(x, y, z);
// Update pitch
// Update volume and pitch
sound.setVolume(volume);
sound.filters[0].frequency.setValueAtTime(12000 * pitch, sound.context.currentTime);
// Play sound