From a7482c52f1f8418c67517fe1c5f84cf301836a80 Mon Sep 17 00:00:00 2001 From: LabyStudio Date: Sun, 13 Feb 2022 08:19:49 +0100 Subject: [PATCH] improve step sound --- src/js/net/minecraft/client/Minecraft.js | 24 ++++++++++++++++--- src/js/net/minecraft/client/entity/Player.js | 2 +- .../minecraft/client/sound/SoundManager.js | 5 ++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/js/net/minecraft/client/Minecraft.js b/src/js/net/minecraft/client/Minecraft.js index 87070a8..f1fea17 100644 --- a/src/js/net/minecraft/client/Minecraft.js +++ b/src/js/net/minecraft/client/Minecraft.js @@ -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 + ); } } } diff --git a/src/js/net/minecraft/client/entity/Player.js b/src/js/net/minecraft/client/entity/Player.js index 836f0d9..54c17e0 100644 --- a/src/js/net/minecraft/client/entity/Player.js +++ b/src/js/net/minecraft/client/entity/Player.js @@ -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()); } } } diff --git a/src/js/net/minecraft/client/sound/SoundManager.js b/src/js/net/minecraft/client/sound/SoundManager.js index 219d074..46239de 100644 --- a/src/js/net/minecraft/client/sound/SoundManager.js +++ b/src/js/net/minecraft/client/sound/SoundManager.js @@ -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