fix sound issues

This commit is contained in:
LabyStudio
2022-02-13 08:10:28 +01:00
parent c955fdc7f9
commit b7b3439f0d
2 changed files with 25 additions and 18 deletions
+21 -17
View File
@@ -45,7 +45,7 @@ window.Player = class {
this.timeFovChanged = 0; this.timeFovChanged = 0;
this.distanceWalked = 0; this.distanceWalked = 0;
this.nextStepDistance = 0; this.nextStepDistance = 1;
} }
respawn() { respawn() {
@@ -248,6 +248,8 @@ window.Player = class {
let prevX = this.x; let prevX = this.x;
let prevZ = this.z; let prevZ = this.z;
let isSlow = this.onGround && this.sneaking;
let value = 0.16277136 / (prevSlipperiness * prevSlipperiness * prevSlipperiness); let value = 0.16277136 / (prevSlipperiness * prevSlipperiness * prevSlipperiness);
let friction; let friction;
@@ -275,25 +277,27 @@ window.Player = class {
this.motionY *= 0.98; this.motionY *= 0.98;
this.motionZ *= slipperiness; this.motionZ *= slipperiness;
let blockX = MathHelper.floor_double(this.x);
let blockY = MathHelper.floor_double(this.y - 0.2);
let blockZ = MathHelper.floor_double(this.z);
let typeId = this.world.getBlockAt(blockX, blockY, blockZ);
let distanceX = this.x - prevX;
let distanceZ = this.z - prevZ;
// Step sound // Step sound
this.distanceWalked += Math.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.6; if (!isSlow) {
if (this.distanceWalked > this.nextStepDistance && typeId !== 0) { let blockX = MathHelper.floor_double(this.x);
this.nextStepDistance++; let blockY = MathHelper.floor_double(this.y - 0.2);
let blockZ = MathHelper.floor_double(this.z);
let typeId = this.world.getBlockAt(blockX, blockY, blockZ);
let block = Block.getById(typeId); let distanceX = this.x - prevX;
let sound = block.getSound(); let distanceZ = this.z - prevZ;
// Play sound this.distanceWalked += Math.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.6;
if (!block.isLiquid()) { if (this.distanceWalked > this.nextStepDistance && typeId !== 0) {
this.minecraft.soundManager.playSound(sound.getStepSound(), this.x, this.y, this.z, sound.getPitch()); this.nextStepDistance = this.distanceWalked + 1;
let block = Block.getById(typeId);
let sound = block.getSound();
// Play sound
if (!block.isLiquid()) {
this.minecraft.soundManager.playSound(sound.getStepSound(), this.x, this.y, this.z, sound.getPitch());
}
} }
} }
} }
@@ -38,7 +38,9 @@ window.SoundManager = class {
} }
loadSound(path) { loadSound(path) {
let scope = this; if (!this.isCreated()) {
return;
}
// Create sound // Create sound
let sound = new THREE.PositionalAudio(this.audioListener); let sound = new THREE.PositionalAudio(this.audioListener);
@@ -47,6 +49,7 @@ window.SoundManager = class {
sound.setFilter(sound.context.createBiquadFilter()); sound.setFilter(sound.context.createBiquadFilter());
// Load sound // Load sound
let scope = this;
this.audioLoader.load(path, function (buffer) { this.audioLoader.load(path, function (buffer) {
sound.setBuffer(buffer); sound.setBuffer(buffer);
scope.scene.add(sound); scope.scene.add(sound);