Skip to content

Commit b4dc58e

Browse files
committed
Fix computer running sound not stopping when stopped before initial delay expired.
1 parent a1217ba commit b4dc58e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/main/java/li/cil/oc2/client/audio/LoopingBlockEntitySound.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public final class LoopingBlockEntitySound extends AbstractTickableSoundInstance
1818
///////////////////////////////////////////////////////////////////
1919

2020
private final BlockEntity blockEntity;
21+
private boolean isCanceled;
2122

2223
///////////////////////////////////////////////////////////////////
2324

@@ -36,6 +37,10 @@ public LoopingBlockEntitySound(final BlockEntity blockEntity, final SoundEvent s
3637

3738
///////////////////////////////////////////////////////////////////
3839

40+
public void cancel() {
41+
isCanceled = true;
42+
}
43+
3944
@Override
4045
public void tick() {
4146
volume = Mth.clamp(volume + FADE_IN_PER_TICK, 0, 1);
@@ -44,4 +49,9 @@ public void tick() {
4449
stop();
4550
}
4651
}
52+
53+
@Override
54+
public boolean canPlaySound() {
55+
return !isCanceled;
56+
}
4757
}

src/main/java/li/cil/oc2/client/audio/LoopingSoundManager.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.util.WeakHashMap;
99

1010
public final class LoopingSoundManager {
11-
private static final WeakHashMap<BlockEntity, TickableSoundInstance> BLOCK_ENTITY_SOUNDS = new WeakHashMap<>();
11+
private static final WeakHashMap<BlockEntity, LoopingBlockEntitySound> BLOCK_ENTITY_SOUNDS = new WeakHashMap<>();
1212

1313
///////////////////////////////////////////////////////////////////
1414

@@ -21,14 +21,15 @@ public static void play(final BlockEntity blockEntity, final SoundEvent sound, f
2121
}
2222

2323
public static void stop(final BlockEntity blockEntity) {
24-
final TickableSoundInstance instance = BLOCK_ENTITY_SOUNDS.remove(blockEntity);
24+
final LoopingBlockEntitySound instance = BLOCK_ENTITY_SOUNDS.remove(blockEntity);
2525
if (instance != null) {
26+
instance.cancel();
2627
Minecraft.getInstance().getSoundManager().stop(instance);
2728
}
2829
}
2930

3031
public static boolean isPlaying(final BlockEntity blockEntity) {
31-
final TickableSoundInstance instance = BLOCK_ENTITY_SOUNDS.get(blockEntity);
32+
final LoopingBlockEntitySound instance = BLOCK_ENTITY_SOUNDS.get(blockEntity);
3233
return instance != null && !instance.isStopped();
3334
}
3435
}

0 commit comments

Comments
 (0)